Skip to content

Commit

Permalink
feat: show foreign key in openapi specs
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
  • Loading branch information
aaqilniz committed Nov 14, 2023
1 parent aa157d5 commit bdee472
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -1130,7 +1130,10 @@ describe('build-schema', () => {
properties: {
id: {type: 'number'},
categoryId: {type: 'number'},
category: {$ref: '#/definitions/CategoryWithRelations'},
category: {
$ref: '#/definitions/CategoryWithRelations',
},
foreignKey: 'categoryId' as JsonSchema,
},
additionalProperties: false,
},
Expand All @@ -1139,7 +1142,9 @@ describe('build-schema', () => {
id: {type: 'number'},
products: {
type: 'array',
items: {$ref: '#/definitions/ProductWithRelations'},
items: {
$ref: '#/definitions/ProductWithRelations',
},
},
},
additionalProperties: false,
Expand Down Expand Up @@ -1182,6 +1187,7 @@ describe('build-schema', () => {
category: {
$ref: '#/definitions/CategoryWithoutPropWithRelations',
},
foreignKey: 'categoryId' as JsonSchema,
},
additionalProperties: false,
},
Expand Down
5 changes: 5 additions & 0 deletions packages/repository-json-schema/src/build-schema.ts
Expand Up @@ -577,6 +577,11 @@ export function modelToJsonSchema<T extends object>(

result.properties[relMeta.name] =
result.properties[relMeta.name] || propDef;
if ((relMeta as {keyFrom: string}).keyFrom) {
result.properties.foreignKey = (relMeta as {keyFrom: string})
.keyFrom as JsonSchema;
}

includeReferencedSchema(targetSchema.title!, targetSchema);
}
}
Expand Down

0 comments on commit bdee472

Please sign in to comment.