Skip to content

Commit

Permalink
feat: add shouldBeGenerated to metaData
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchdesign committed May 22, 2024
1 parent f76c10d commit e65da94
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Beside generating the expected schema files under `outputPath`, `openapiToTsJson
// Original dereferenced JSON schema
isRef: boolean;
// True if schemas is used as a `$ref`
shouldBeGenerated: boolean;
// True is the schema has to be generated

absoluteDirName: string;
// Absolute path pointing to schema folder (posix or win32). Eg: `"Users/username/output/path/components/schemas"`
Expand Down
2 changes: 2 additions & 0 deletions src/openapiToTsJsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export async function openapiToTsJsonSchema(
jsonSchema,
outputPath,
isRef: true,
shouldBeGenerated: true,
});
}
}
Expand All @@ -177,6 +178,7 @@ export async function openapiToTsJsonSchema(
jsonSchema: jsonSchemaDefinitions[schemaName],
outputPath,
isRef: inlinedRefs.has(id),
shouldBeGenerated: true,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type Options = {
* @property `id` - Internal unique schema identifier. Eg `"/components/schemas/MySchema"`
* @property `$id` - JSON schema Compound Schema Document `$id`. Eg `"/components/schemas/MySchema"`
* @property `isRef` - True if schemas is used as `$ref`
* @property `shouldBeGenerated` - True is the schema has to be generated
* @property `uniqueName` - Unique JavaScript identifier used as import name. Eg: `"componentsSchemasMySchema"`
* @property `openApiDefinition` - Original dereferenced openAPI definition
* @property `originalSchema` - Original dereferenced JSON schema
Expand All @@ -71,6 +72,7 @@ export type SchemaMetaData = {
id: string;
$id: string;
isRef: boolean;
shouldBeGenerated: boolean;
uniqueName: string;
openApiDefinition?: OpenApiObject;
originalSchema: JSONSchema;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/addSchemaToMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function addSchemaToMetaData({
openApiDefinition,
jsonSchema,
isRef,
shouldBeGenerated,
// Options
outputPath,
}: {
Expand All @@ -33,6 +34,7 @@ export function addSchemaToMetaData({
openApiDefinition: OpenApiObject;
jsonSchema: JSONSchema;
isRef: boolean;
shouldBeGenerated: boolean;
outputPath: string;
}): void {
// Do not override existing meta info of inlined schemas
Expand All @@ -52,6 +54,7 @@ export function addSchemaToMetaData({
$id,
uniqueName: namify(id),
isRef,
shouldBeGenerated,
openApiDefinition,
originalSchema: jsonSchema,

Expand Down
2 changes: 2 additions & 0 deletions test/metaData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Returned "metaData"', async () => {
type: ['string', 'null'],
},
isRef: true,
shouldBeGenerated: true,

absoluteDirName: `${outputPath}/components/schemas`.replaceAll(
'/',
Expand Down Expand Up @@ -97,6 +98,7 @@ describe('Returned "metaData"', async () => {
type: 'object',
},
isRef: false,
shouldBeGenerated: true,

absoluteDirName: `${outputPath}/components/schemas`.replaceAll(
'/',
Expand Down
2 changes: 2 additions & 0 deletions test/unit-tests/addSchemaToMetaData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('addSchemaToMetaData', () => {
jsonSchema,
outputPath,
isRef: true,
shouldBeGenerated: true,
});

const actual = schemaMetaDataMap.get(id);
Expand All @@ -38,6 +39,7 @@ describe('addSchemaToMetaData', () => {
$id: '$/components/schemas/Foo',
uniqueName: 'componentsSchemasFoo',
isRef: true,
shouldBeGenerated: true,
openApiDefinition,
originalSchema: jsonSchema,

Expand Down

0 comments on commit e65da94

Please sign in to comment.