diff --git a/packages/plugins/openapi/src/rest-generator.ts b/packages/plugins/openapi/src/rest-generator.ts index 4e7c8bcb..86ed9736 100644 --- a/packages/plugins/openapi/src/rest-generator.ts +++ b/packages/plugins/openapi/src/rest-generator.ts @@ -868,6 +868,10 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { const required: string[] = []; for (const field of fields) { + if (isForeignKeyField(field) && mode !== 'read') { + // foreign keys are not exposed as attributes + continue; + } if (isRelationshipField(field)) { let relType: string; if (mode === 'create' || mode === 'update') { diff --git a/packages/plugins/openapi/tests/baseline/rest-3.0.0.baseline.yaml b/packages/plugins/openapi/tests/baseline/rest-3.0.0.baseline.yaml index adb9ded1..0ea25801 100644 --- a/packages/plugins/openapi/tests/baseline/rest-3.0.0.baseline.yaml +++ b/packages/plugins/openapi/tests/baseline/rest-3.0.0.baseline.yaml @@ -2791,14 +2791,10 @@ components: type: string attributes: type: object - required: - - userId properties: image: type: string nullable: true - userId: - type: string relationships: type: object properties: @@ -2830,8 +2826,6 @@ components: image: type: string nullable: true - userId: - type: string relationships: type: object properties: @@ -2974,9 +2968,6 @@ components: format: date-time title: type: string - authorId: - type: string - nullable: true published: type: boolean viewCount: @@ -3022,9 +3013,6 @@ components: format: date-time title: type: string - authorId: - type: string - nullable: true published: type: boolean viewCount: diff --git a/packages/plugins/openapi/tests/baseline/rest-3.1.0.baseline.yaml b/packages/plugins/openapi/tests/baseline/rest-3.1.0.baseline.yaml index f69536b3..9bd34467 100644 --- a/packages/plugins/openapi/tests/baseline/rest-3.1.0.baseline.yaml +++ b/packages/plugins/openapi/tests/baseline/rest-3.1.0.baseline.yaml @@ -2797,15 +2797,11 @@ components: type: string attributes: type: object - required: - - userId properties: image: oneOf: - type: 'null' - type: string - userId: - type: string relationships: type: object properties: @@ -2838,8 +2834,6 @@ components: oneOf: - type: 'null' - type: string - userId: - type: string relationships: type: object properties: @@ -2984,10 +2978,6 @@ components: format: date-time title: type: string - authorId: - oneOf: - - type: 'null' - - type: string published: type: boolean viewCount: @@ -3034,10 +3024,6 @@ components: format: date-time title: type: string - authorId: - oneOf: - - type: 'null' - - type: string published: type: boolean viewCount: