Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(openapi): bugfix for compound id create and update #1855

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/plugins/openapi/src/rest-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
ymc9 marked this conversation as resolved.
Show resolved Hide resolved

const attributes: Record<string, OAPI.SchemaObject> = {};
const relationships: Record<string, OAPI.ReferenceObject | OAPI.SchemaObject> = {};
Expand Down Expand Up @@ -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'))) {
thomassnielsen marked this conversation as resolved.
Show resolved Hide resolved
ymc9 marked this conversation as resolved.
Show resolved Hide resolved
properties = { id: { type: 'string' }, ...properties };
toplevelRequired.unshift('id');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3149,7 +3149,6 @@ components:
type: object
description: The "PostLike" model
required:
- id
- type
- attributes
properties:
Expand Down
1 change: 0 additions & 1 deletion packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@ describe('REST server tests', () => {
requestBody: {
data: {
type: 'postLike',
id: `1${idDivider}user1`,
attributes: { userId: 'user1', postId: 1, superLike: false },
},
},
Expand Down
Loading