diff --git a/packages/plugins/openapi/src/rest-generator.ts b/packages/plugins/openapi/src/rest-generator.ts index 4e7c8bcb..c0447763 100644 --- a/packages/plugins/openapi/src/rest-generator.ts +++ b/packages/plugins/openapi/src/rest-generator.ts @@ -860,7 +860,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { // For compound ids each component is also exposed as a separate fields for read operations, // but not required for write operations const fields = - idFields.length > 1 && mode === 'read' ? model.fields : model.fields.filter((f) => !isIdField(f)); + idFields.length > 1 && mode !== 'update' ? model.fields : model.fields.filter((f) => !isIdField(f)); const attributes: Record = {}; const relationships: Record = {}; @@ -907,7 +907,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { if (mode === 'create') { // 'id' is required if there's no default value const idFields = model.fields.filter((f) => isIdField(f)); - if (idFields.length && idFields.every((f) => !hasAttribute(f, '@default'))) { + if (idFields.length === 1 && idFields.every((f) => !hasAttribute(f, '@default'))) { properties = { id: { type: 'string' }, ...properties }; toplevelRequired.unshift('id'); } 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..f0b46fc9 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 @@ -3135,14 +3135,11 @@ components: type: object description: The "PostLike" model required: - - id - type - attributes properties: type: type: string - attributes: - type: object relationships: type: object properties: 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..79e0c020 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 @@ -3149,7 +3149,6 @@ components: type: object description: The "PostLike" model required: - - id - type - attributes properties: