From b4ac69b4f6e57c07053e497047973d3e336f2e8d Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Fri, 4 Oct 2024 10:54:04 +0200 Subject: [PATCH 1/7] Add sample compound id model --- packages/plugins/openapi/tests/openapi-restful.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/plugins/openapi/tests/openapi-restful.test.ts b/packages/plugins/openapi/tests/openapi-restful.test.ts index 9997dd540..22d7a16f9 100644 --- a/packages/plugins/openapi/tests/openapi-restful.test.ts +++ b/packages/plugins/openapi/tests/openapi-restful.test.ts @@ -35,6 +35,7 @@ model User { role role @default(USER) posts post_Item[] profile Profile? + likes PostLike[] } model Profile { @@ -55,12 +56,21 @@ model post_Item { published Boolean @default(false) viewCount Int @default(0) notes String? + likes PostLike[] @@openapi.meta({ tagDescription: 'Post-related operations' }) } +model PostLike { + post post_Item @relation(fields: [postId], references: [id]) + postId String + user User @relation(fields: [userId], references: [id]) + userId String + @@id([postId, userId]) +} + model Foo { id String @id @@openapi.ignore From fbb5706b7b21be7eb5186d8e6454455f469c7cf0 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Fri, 4 Oct 2024 11:14:04 +0200 Subject: [PATCH 2/7] Support compound ids --- packages/plugins/openapi/src/rest-generator.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/plugins/openapi/src/rest-generator.ts b/packages/plugins/openapi/src/rest-generator.ts index 90383f8f9..9e2bdc337 100644 --- a/packages/plugins/openapi/src/rest-generator.ts +++ b/packages/plugins/openapi/src/rest-generator.ts @@ -409,6 +409,8 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { private generateFilterParameters(model: DataModel) { const result: OAPI.ParameterObject[] = []; + const hasMultipleIds = model.fields.filter((f) => isIdField(f)).length > 1; + for (const field of model.fields) { if (isForeignKeyField(field)) { // no filtering with foreign keys because one can filter @@ -416,7 +418,8 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { continue; } - if (isIdField(field)) { + // For multiple ids, make each id field filterable like a regular field + if (isIdField(field) && !hasMultipleIds) { // id filter result.push(this.makeFilterParameter(field, 'id', 'Id filter')); continue; @@ -843,7 +846,9 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { } private generateModelEntity(model: DataModel, mode: 'read' | 'create' | 'update'): OAPI.SchemaObject { - const fields = model.fields.filter((f) => !isIdField(f)); + const idFields = model.fields.filter((f) => isIdField(f)); + // For compound ids, each component is also exposed as a separate field + const fields = idFields.length > 1 ? model.fields : model.fields.filter((f) => !isIdField(f)); const attributes: Record = {}; const relationships: Record = {}; @@ -886,8 +891,8 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase { if (mode === 'create') { // 'id' is required if there's no default value - const idField = model.fields.find((f) => isIdField(f)); - if (idField && !hasAttribute(idField, '@default')) { + const idFields = model.fields.filter((f) => isIdField(f)); + if (idFields.length && idFields.every((f) => !hasAttribute(f, '@default'))) { properties = { id: { type: 'string' }, ...properties }; toplevelRequired.unshift('id'); } From 7159e66a8579e5d981cd84f2e7537a38e31fbd42 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Mon, 7 Oct 2024 09:59:18 +0200 Subject: [PATCH 3/7] Update baseline yaml files --- .../tests/baseline/rest-3.0.0.baseline.yaml | 42 +++++++++++++++++++ .../tests/baseline/rest-3.1.0.baseline.yaml | 42 +++++++++++++++++++ 2 files changed, 84 insertions(+) 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 263624c66..33bfc7f5b 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 @@ -9,6 +9,8 @@ tags: description: Profile operations - name: post_Item description: Post-related operations + - name: postLike + description: PostLike operations paths: /user: get: @@ -193,6 +195,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -543,6 +555,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -745,6 +767,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -1593,6 +1625,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation 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 e0c7cce3d..760ce93f9 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 @@ -9,6 +9,8 @@ tags: description: Profile operations - name: post_Item description: Post-related operations + - name: postLike + description: PostLike operations paths: /user: get: @@ -193,6 +195,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -543,6 +555,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -745,6 +767,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation @@ -1593,6 +1625,16 @@ paths: explode: false schema: type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string responses: '200': description: Successful operation From 55d3c7a37f1d2ab633e12b4ccb5a4503d6fc5a76 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Mon, 7 Oct 2024 12:26:14 +0200 Subject: [PATCH 4/7] Add tests --- .../openapi/tests/openapi-restful.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/plugins/openapi/tests/openapi-restful.test.ts b/packages/plugins/openapi/tests/openapi-restful.test.ts index 22d7a16f9..d9e6be6e1 100644 --- a/packages/plugins/openapi/tests/openapi-restful.test.ts +++ b/packages/plugins/openapi/tests/openapi-restful.test.ts @@ -108,9 +108,15 @@ model Bar { expect(api.paths?.['/user/{id}/relationships/posts']?.['get']).toBeTruthy(); expect(api.paths?.['/user/{id}/relationships/posts']?.['post']).toBeTruthy(); expect(api.paths?.['/user/{id}/relationships/posts']?.['patch']).toBeTruthy(); + expect(api.paths?.['/user/{id}/relationships/likes']?.['get']).toBeTruthy(); + expect(api.paths?.['/user/{id}/relationships/likes']?.['post']).toBeTruthy(); + expect(api.paths?.['/user/{id}/relationships/likes']?.['patch']).toBeTruthy(); expect(api.paths?.['/post_Item/{id}/relationships/author']?.['get']).toBeTruthy(); expect(api.paths?.['/post_Item/{id}/relationships/author']?.['post']).toBeUndefined(); expect(api.paths?.['/post_Item/{id}/relationships/author']?.['patch']).toBeTruthy(); + expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['get']).toBeTruthy(); + expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['post']).toBeTruthy(); + expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['patch']).toBeTruthy(); expect(api.paths?.['/foo']).toBeUndefined(); expect(api.paths?.['/bar']).toBeUndefined(); @@ -333,6 +339,37 @@ model Foo { expect(parsed).toMatchObject(baseline); } }); + + it('exposes individual fields from a compound id as attributes', async () => { + const { model, dmmf, modelFile } = await loadZModelAndDmmf(` +plugin openapi { + provider = '${normalizePath(path.resolve(__dirname, '../dist'))}' +} + +model User { + email String + role String + company String + @@id([role, company]) +} + `); + + const { name: output } = tmp.fileSync({ postfix: '.yaml' }); + + const options = buildOptions(model, modelFile, output, '3.1.0'); + await generate(model, options, dmmf); + + await OpenAPIParser.validate(output); + + const parsed = YAML.parse(fs.readFileSync(output, 'utf-8')); + expect(parsed.openapi).toBe('3.1.0'); + + expect(Object.keys(parsed.components.schemas.User.properties.attributes.properties)).toEqual( + expect.arrayContaining(['role', 'company']) + ); + + console.log(JSON.stringify(parsed)); + }); }); function buildOptions(model: Model, modelFile: string, output: string, specVersion = '3.0.0') { From d0771a602e532b7bc35f3e17b5589518b0a121f4 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Tue, 8 Oct 2024 10:08:15 +0200 Subject: [PATCH 5/7] Remove console log --- packages/plugins/openapi/tests/openapi-restful.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/plugins/openapi/tests/openapi-restful.test.ts b/packages/plugins/openapi/tests/openapi-restful.test.ts index d9e6be6e1..8fd0880ff 100644 --- a/packages/plugins/openapi/tests/openapi-restful.test.ts +++ b/packages/plugins/openapi/tests/openapi-restful.test.ts @@ -367,8 +367,6 @@ model User { expect(Object.keys(parsed.components.schemas.User.properties.attributes.properties)).toEqual( expect.arrayContaining(['role', 'company']) ); - - console.log(JSON.stringify(parsed)); }); }); From af30bc9c17ffdd8b3f6b8818866ae955b6965276 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Tue, 8 Oct 2024 10:34:12 +0200 Subject: [PATCH 6/7] Add postlike path to baseline --- .../tests/baseline/rest-3.0.0.baseline.yaml | 313 ++++++++++++++++++ 1 file changed, 313 insertions(+) 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 33bfc7f5b..0a1a17918 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 @@ -1918,6 +1918,319 @@ paths: application/vnd.api+json: schema: $ref: '#/components/schemas/_errorResponse' + /postLike: + get: + operationId: list-PostLike + description: List "PostLike" resources + tags: + - postLike + parameters: + - $ref: '#/components/parameters/include' + - $ref: '#/components/parameters/sort' + - $ref: '#/components/parameters/page-offset' + - $ref: '#/components/parameters/page-limit' + - name: filter[id] + required: false + description: Id filter + in: query + style: form + explode: false + schema: + type: string + - name: filter[createdAt] + required: false + description: Equality filter for "createdAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[createdAt$lt] + required: false + description: Less-than filter for "createdAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[createdAt$lte] + required: false + description: Less-than or equal filter for "createdAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[createdAt$gt] + required: false + description: Greater-than filter for "createdAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[createdAt$gte] + required: false + description: Greater-than or equal filter for "createdAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[updatedAt] + required: false + description: Equality filter for "updatedAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[updatedAt$lt] + required: false + description: Less-than filter for "updatedAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[updatedAt$lte] + required: false + description: Less-than or equal filter for "updatedAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[updatedAt$gt] + required: false + description: Greater-than filter for "updatedAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[updatedAt$gte] + required: false + description: Greater-than or equal filter for "updatedAt" + in: query + style: form + explode: false + schema: + type: string + format: date-time + - name: filter[title] + required: false + description: Equality filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[title$contains] + required: false + description: String contains filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[title$icontains] + required: false + description: String case-insensitive contains filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[title$search] + required: false + description: String full-text search filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[title$startsWith] + required: false + description: String startsWith filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[title$endsWith] + required: false + description: String endsWith filter for "title" + in: query + style: form + explode: false + schema: + type: string + - name: filter[author] + required: false + description: Equality filter for "author" + in: query + style: form + explode: false + schema: + type: string + - name: filter[published] + required: false + description: Equality filter for "published" + in: query + style: form + explode: false + schema: + type: boolean + - name: filter[viewCount] + required: false + description: Equality filter for "viewCount" + in: query + style: form + explode: false + schema: + type: integer + - name: filter[viewCount$lt] + required: false + description: Less-than filter for "viewCount" + in: query + style: form + explode: false + schema: + type: integer + - name: filter[viewCount$lte] + required: false + description: Less-than or equal filter for "viewCount" + in: query + style: form + explode: false + schema: + type: integer + - name: filter[viewCount$gt] + required: false + description: Greater-than filter for "viewCount" + in: query + style: form + explode: false + schema: + type: integer + - name: filter[viewCount$gte] + required: false + description: Greater-than or equal filter for "viewCount" + in: query + style: form + explode: false + schema: + type: integer + - name: filter[notes] + required: false + description: Equality filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[notes$contains] + required: false + description: String contains filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[notes$icontains] + required: false + description: String case-insensitive contains filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[notes$search] + required: false + description: String full-text search filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[notes$startsWith] + required: false + description: String startsWith filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[notes$endsWith] + required: false + description: String endsWith filter for "notes" + in: query + style: form + explode: false + schema: + type: string + - name: filter[likes] + required: false + description: Equality filter for "likes" + in: query + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/postLikeListResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + post: + operationId: create-postLike + description: Create a "postLike" resource + tags: + - postLike + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/postLikeCreateRequest' + responses: + '201': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/postLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' components: schemas: _jsonapi: From 14827ee02ac5c478b0feb3670b857d160d9dc981 Mon Sep 17 00:00:00 2001 From: Thomas Sunde Nielsen Date: Tue, 8 Oct 2024 10:51:23 +0200 Subject: [PATCH 7/7] Update baseline files --- .../tests/baseline/rest-3.0.0.baseline.yaml | 784 ++++++++++++------ .../tests/baseline/rest-3.1.0.baseline.yaml | 583 +++++++++++++ 2 files changed, 1110 insertions(+), 257 deletions(-) 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 0a1a17918..0b05005a6 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 @@ -1929,265 +1929,21 @@ paths: - $ref: '#/components/parameters/sort' - $ref: '#/components/parameters/page-offset' - $ref: '#/components/parameters/page-limit' - - name: filter[id] - required: false - description: Id filter - in: query - style: form - explode: false - schema: - type: string - - name: filter[createdAt] - required: false - description: Equality filter for "createdAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[createdAt$lt] - required: false - description: Less-than filter for "createdAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[createdAt$lte] - required: false - description: Less-than or equal filter for "createdAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[createdAt$gt] - required: false - description: Greater-than filter for "createdAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[createdAt$gte] - required: false - description: Greater-than or equal filter for "createdAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[updatedAt] - required: false - description: Equality filter for "updatedAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[updatedAt$lt] - required: false - description: Less-than filter for "updatedAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[updatedAt$lte] - required: false - description: Less-than or equal filter for "updatedAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[updatedAt$gt] - required: false - description: Greater-than filter for "updatedAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[updatedAt$gte] - required: false - description: Greater-than or equal filter for "updatedAt" - in: query - style: form - explode: false - schema: - type: string - format: date-time - - name: filter[title] - required: false - description: Equality filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[title$contains] - required: false - description: String contains filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[title$icontains] - required: false - description: String case-insensitive contains filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[title$search] - required: false - description: String full-text search filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[title$startsWith] - required: false - description: String startsWith filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[title$endsWith] - required: false - description: String endsWith filter for "title" - in: query - style: form - explode: false - schema: - type: string - - name: filter[author] - required: false - description: Equality filter for "author" - in: query - style: form - explode: false - schema: - type: string - - name: filter[published] - required: false - description: Equality filter for "published" - in: query - style: form - explode: false - schema: - type: boolean - - name: filter[viewCount] - required: false - description: Equality filter for "viewCount" - in: query - style: form - explode: false - schema: - type: integer - - name: filter[viewCount$lt] - required: false - description: Less-than filter for "viewCount" - in: query - style: form - explode: false - schema: - type: integer - - name: filter[viewCount$lte] - required: false - description: Less-than or equal filter for "viewCount" - in: query - style: form - explode: false - schema: - type: integer - - name: filter[viewCount$gt] - required: false - description: Greater-than filter for "viewCount" - in: query - style: form - explode: false - schema: - type: integer - - name: filter[viewCount$gte] - required: false - description: Greater-than or equal filter for "viewCount" - in: query - style: form - explode: false - schema: - type: integer - - name: filter[notes] - required: false - description: Equality filter for "notes" - in: query - style: form - explode: false - schema: - type: string - - name: filter[notes$contains] - required: false - description: String contains filter for "notes" - in: query - style: form - explode: false - schema: - type: string - - name: filter[notes$icontains] - required: false - description: String case-insensitive contains filter for "notes" - in: query - style: form - explode: false - schema: - type: string - - name: filter[notes$search] + - name: filter[post] required: false - description: String full-text search filter for "notes" + description: Equality filter for "post" in: query style: form explode: false schema: type: string - - name: filter[notes$startsWith] - required: false - description: String startsWith filter for "notes" - in: query - style: form - explode: false - schema: - type: string - - name: filter[notes$endsWith] - required: false - description: String endsWith filter for "notes" - in: query - style: form - explode: false - schema: - type: string - - name: filter[likes] + - name: filter[user] required: false - description: Equality filter for "likes" + description: Equality filter for "user" in: query style: form explode: false schema: - type: array - items: type: string responses: '200': @@ -2195,38 +1951,396 @@ paths: content: application/vnd.api+json: schema: - $ref: '#/components/schemas/postLikeListResponse' + $ref: '#/components/schemas/PostLikeListResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + post: + operationId: create-PostLike + description: Create a "PostLike" resource + tags: + - postLike + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeCreateRequest' + responses: + '201': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}: + get: + operationId: fetch-PostLike + description: Fetch a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-put + description: Update a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeUpdateRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-patch + description: Update a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeUpdateRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + delete: + operationId: delete-PostLike + description: Delete a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/post: + get: + operationId: fetch-PostLike-related-post + description: Fetch the related "post" resource for "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/post_ItemResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/relationships/post: + get: + operationId: fetch-PostLike-relationship-post + description: Fetch the "post" relationships for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-relationship-post-put + description: Update "post" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' '403': description: Request is forbidden content: application/vnd.api+json: schema: $ref: '#/components/schemas/_errorResponse' - post: - operationId: create-postLike - description: Create a "postLike" resource + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-relationship-post-patch + description: Update "post" relationship for a "PostLike" tags: - postLike + parameters: + - $ref: '#/components/parameters/id' requestBody: content: application/vnd.api+json: schema: - $ref: '#/components/schemas/postLikeCreateRequest' + $ref: '#/components/schemas/_toOneRelationshipRequest' responses: - '201': + '200': description: Successful operation content: application/vnd.api+json: schema: - $ref: '#/components/schemas/postLikeResponse' + $ref: '#/components/schemas/_toOneRelationshipResponse' '403': description: Request is forbidden content: application/vnd.api+json: schema: $ref: '#/components/schemas/_errorResponse' - '422': - description: Request is unprocessable due to validation errors + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/user: + get: + operationId: fetch-PostLike-related-user + description: Fetch the related "user" resource for "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/UserResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/relationships/user: + get: + operationId: fetch-PostLike-relationship-user + description: Fetch the "user" relationships for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-relationship-user-put + description: Update "user" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-relationship-user-patch + description: Update "user" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found content: application/vnd.api+json: schema: @@ -2966,6 +3080,162 @@ components: allOf: - $ref: '#/components/schemas/_links' - $ref: '#/components/schemas/_pagination' + PostLike: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + id: + type: string + type: + type: string + attributes: + type: object + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationshipWithLinks' + user: + $ref: '#/components/schemas/_toOneRelationshipWithLinks' + PostLikeCreateRequest: + type: object + description: Input for creating a "PostLike" + required: + - data + properties: + data: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + type: + type: string + attributes: + type: object + required: + - postId + - userId + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + PostLikeUpdateRequest: + type: object + description: Input for updating a "PostLike" + required: + - data + properties: + data: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + id: + type: string + type: + type: string + attributes: + type: object + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + PostLikeResponse: + type: object + description: Response for a "PostLike" + required: + - data + properties: + jsonapi: + $ref: '#/components/schemas/_jsonapi' + data: + allOf: + - $ref: '#/components/schemas/PostLike' + - type: object + properties: + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + included: + type: array + items: + $ref: '#/components/schemas/_resource' + links: + $ref: '#/components/schemas/_links' + PostLikeListResponse: + type: object + description: Response for a list of "PostLike" + required: + - data + - links + properties: + jsonapi: + $ref: '#/components/schemas/_jsonapi' + data: + type: array + items: + allOf: + - $ref: '#/components/schemas/PostLike' + - type: object + properties: + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + included: + type: array + items: + $ref: '#/components/schemas/_resource' + links: + allOf: + - $ref: '#/components/schemas/_links' + - $ref: '#/components/schemas/_pagination' parameters: id: name: id 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 760ce93f9..8096c90d6 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 @@ -1918,6 +1918,433 @@ paths: application/vnd.api+json: schema: $ref: '#/components/schemas/_errorResponse' + /postLike: + get: + operationId: list-PostLike + description: List "PostLike" resources + tags: + - postLike + parameters: + - $ref: '#/components/parameters/include' + - $ref: '#/components/parameters/sort' + - $ref: '#/components/parameters/page-offset' + - $ref: '#/components/parameters/page-limit' + - name: filter[post] + required: false + description: Equality filter for "post" + in: query + style: form + explode: false + schema: + type: string + - name: filter[user] + required: false + description: Equality filter for "user" + in: query + style: form + explode: false + schema: + type: string + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeListResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + post: + operationId: create-PostLike + description: Create a "PostLike" resource + tags: + - postLike + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeCreateRequest' + responses: + '201': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}: + get: + operationId: fetch-PostLike + description: Fetch a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-put + description: Update a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeUpdateRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-patch + description: Update a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeUpdateRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/PostLikeResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '422': + description: Request is unprocessable due to validation errors + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + delete: + operationId: delete-PostLike + description: Delete a "PostLike" resource + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/post: + get: + operationId: fetch-PostLike-related-post + description: Fetch the related "post" resource for "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/post_ItemResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/relationships/post: + get: + operationId: fetch-PostLike-relationship-post + description: Fetch the "post" relationships for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-relationship-post-put + description: Update "post" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-relationship-post-patch + description: Update "post" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/user: + get: + operationId: fetch-PostLike-related-user + description: Fetch the related "user" resource for "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + - $ref: '#/components/parameters/include' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/UserResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + /postLike/{id}/relationships/user: + get: + operationId: fetch-PostLike-relationship-user + description: Fetch the "user" relationships for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + put: + operationId: update-PostLike-relationship-user-put + description: Update "user" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + patch: + operationId: update-PostLike-relationship-user-patch + description: Update "user" relationship for a "PostLike" + tags: + - postLike + parameters: + - $ref: '#/components/parameters/id' + requestBody: + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipRequest' + responses: + '200': + description: Successful operation + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_toOneRelationshipResponse' + '403': + description: Request is forbidden + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' + '404': + description: Resource is not found + content: + application/vnd.api+json: + schema: + $ref: '#/components/schemas/_errorResponse' components: schemas: _jsonapi: @@ -2667,6 +3094,162 @@ components: allOf: - $ref: '#/components/schemas/_links' - $ref: '#/components/schemas/_pagination' + PostLike: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + id: + type: string + type: + type: string + attributes: + type: object + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationshipWithLinks' + user: + $ref: '#/components/schemas/_toOneRelationshipWithLinks' + PostLikeCreateRequest: + type: object + description: Input for creating a "PostLike" + required: + - data + properties: + data: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + type: + type: string + attributes: + type: object + required: + - postId + - userId + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + PostLikeUpdateRequest: + type: object + description: Input for updating a "PostLike" + required: + - data + properties: + data: + type: object + description: The "PostLike" model + required: + - id + - type + - attributes + properties: + id: + type: string + type: + type: string + attributes: + type: object + properties: + postId: + type: string + userId: + type: string + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + PostLikeResponse: + type: object + description: Response for a "PostLike" + required: + - data + properties: + jsonapi: + $ref: '#/components/schemas/_jsonapi' + data: + allOf: + - $ref: '#/components/schemas/PostLike' + - type: object + properties: + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + included: + type: array + items: + $ref: '#/components/schemas/_resource' + links: + $ref: '#/components/schemas/_links' + PostLikeListResponse: + type: object + description: Response for a list of "PostLike" + required: + - data + - links + properties: + jsonapi: + $ref: '#/components/schemas/_jsonapi' + data: + type: array + items: + allOf: + - $ref: '#/components/schemas/PostLike' + - type: object + properties: + relationships: + type: object + properties: + post: + $ref: '#/components/schemas/_toOneRelationship' + user: + $ref: '#/components/schemas/_toOneRelationship' + meta: + $ref: '#/components/schemas/_meta' + included: + type: array + items: + $ref: '#/components/schemas/_resource' + links: + allOf: + - $ref: '#/components/schemas/_links' + - $ref: '#/components/schemas/_pagination' parameters: id: name: id