diff --git a/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts b/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts index f46e2a6b670f..af512eb78d83 100644 --- a/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts +++ b/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts @@ -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, }, @@ -1139,7 +1142,9 @@ describe('build-schema', () => { id: {type: 'number'}, products: { type: 'array', - items: {$ref: '#/definitions/ProductWithRelations'}, + items: { + $ref: '#/definitions/ProductWithRelations', + }, }, }, additionalProperties: false, @@ -1182,6 +1187,7 @@ describe('build-schema', () => { category: { $ref: '#/definitions/CategoryWithoutPropWithRelations', }, + foreignKey: 'categoryId' as JsonSchema, }, additionalProperties: false, }, diff --git a/packages/repository-json-schema/src/build-schema.ts b/packages/repository-json-schema/src/build-schema.ts index f5d6fee5a98b..e945000973e8 100644 --- a/packages/repository-json-schema/src/build-schema.ts +++ b/packages/repository-json-schema/src/build-schema.ts @@ -577,6 +577,11 @@ export function modelToJsonSchema( 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); } }