Skip to content

Commit 3978a30

Browse files
committed
- Added methods to get composition
1 parent 18bf2f7 commit 3978a30

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Model } from './Model';
2+
3+
export interface ModelComposition {
4+
type: 'one-of' | 'any-of' | 'all-of';
5+
imports: string[];
6+
enums: Model[];
7+
properties: Model[];
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ModelComposition } from '../../../client/interfaces/ModelComposition';
2+
import type { OpenApi } from '../interfaces/OpenApi';
3+
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
4+
import type { getModel } from './getModel';
5+
6+
// Fix for circular dependency
7+
export type GetModelFn = typeof getModel;
8+
9+
export function getModelComposition(openApi: OpenApi, definitions: OpenApiSchema[], type: 'one-of' | 'any-of' | 'all-of', getModel: GetModelFn): ModelComposition {
10+
const composition: ModelComposition = {
11+
type,
12+
imports: [],
13+
enums: [],
14+
properties: [],
15+
};
16+
17+
const modes = definitions.map(definition => getModel(openApi, definition));
18+
modes.forEach(model => {
19+
composition.imports.push(...model.imports);
20+
composition.enums.push(...model.enums);
21+
composition.properties.push(model);
22+
});
23+
24+
return composition;
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ModelComposition } from '../../../client/interfaces/ModelComposition';
2+
import type { OpenApi } from '../interfaces/OpenApi';
3+
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
4+
import type { getModel } from './getModel';
5+
6+
// Fix for circular dependency
7+
export type GetModelFn = typeof getModel;
8+
9+
export function getModelComposition(openApi: OpenApi, definitions: OpenApiSchema[], type: 'one-of' | 'any-of' | 'all-of', getModel: GetModelFn): ModelComposition {
10+
const composition: ModelComposition = {
11+
type,
12+
imports: [],
13+
enums: [],
14+
properties: [],
15+
};
16+
17+
const modes = definitions.map(definition => getModel(openApi, definition));
18+
modes.forEach(model => {
19+
composition.imports.push(...model.imports);
20+
composition.enums.push(...model.enums);
21+
composition.properties.push(model);
22+
});
23+
24+
return composition;
25+
}

0 commit comments

Comments
 (0)