Skip to content

Commit bdee472

Browse files
committed
feat: show foreign key in openapi specs
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
1 parent aa157d5 commit bdee472

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,10 @@ describe('build-schema', () => {
11301130
properties: {
11311131
id: {type: 'number'},
11321132
categoryId: {type: 'number'},
1133-
category: {$ref: '#/definitions/CategoryWithRelations'},
1133+
category: {
1134+
$ref: '#/definitions/CategoryWithRelations',
1135+
},
1136+
foreignKey: 'categoryId' as JsonSchema,
11341137
},
11351138
additionalProperties: false,
11361139
},
@@ -1139,7 +1142,9 @@ describe('build-schema', () => {
11391142
id: {type: 'number'},
11401143
products: {
11411144
type: 'array',
1142-
items: {$ref: '#/definitions/ProductWithRelations'},
1145+
items: {
1146+
$ref: '#/definitions/ProductWithRelations',
1147+
},
11431148
},
11441149
},
11451150
additionalProperties: false,
@@ -1182,6 +1187,7 @@ describe('build-schema', () => {
11821187
category: {
11831188
$ref: '#/definitions/CategoryWithoutPropWithRelations',
11841189
},
1190+
foreignKey: 'categoryId' as JsonSchema,
11851191
},
11861192
additionalProperties: false,
11871193
},

packages/repository-json-schema/src/build-schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,11 @@ export function modelToJsonSchema<T extends object>(
577577

578578
result.properties[relMeta.name] =
579579
result.properties[relMeta.name] || propDef;
580+
if ((relMeta as {keyFrom: string}).keyFrom) {
581+
result.properties.foreignKey = (relMeta as {keyFrom: string})
582+
.keyFrom as JsonSchema;
583+
}
584+
580585
includeReferencedSchema(targetSchema.title!, targetSchema);
581586
}
582587
}

0 commit comments

Comments
 (0)