Last active
October 25, 2024 18:34
-
-
Save alexcastrodev/c198b6d9d2e483ed5922146c12dccee6 to your computer and use it in GitHub Desktop.
reuse openapi params 3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openapi: 3.0.0 | |
info: | |
title: Thing API | |
version: 1.0.0 | |
description: An API to create and update Thing objects using JSON:API specification | |
paths: | |
/things: | |
post: | |
summary: Create a new Thing | |
requestBody: | |
required: true | |
content: | |
application/vnd.api+json: # JSON:API media type | |
schema: | |
$ref: '#/components/schemas/ThingCreate' | |
responses: | |
'201': | |
description: Thing created successfully | |
content: | |
application/vnd.api+json: | |
schema: | |
$ref: '#/components/schemas/ThingResponse' | |
'400': | |
description: Bad request | |
/things/{id}: | |
put: | |
summary: Update an existing Thing | |
parameters: | |
- name: id | |
in: path | |
required: true | |
schema: | |
type: integer | |
requestBody: | |
required: true | |
content: | |
application/vnd.api+json: | |
schema: | |
$ref: '#/components/schemas/ThingUpdate' | |
responses: | |
'200': | |
description: Thing updated successfully | |
content: | |
application/vnd.api+json: | |
schema: | |
$ref: '#/components/schemas/ThingResponse' | |
'400': | |
description: Bad request | |
'404': | |
description: Thing not found | |
components: | |
schemas: | |
Thing: | |
type: object | |
properties: | |
id: | |
type: integer | |
type: | |
type: string | |
enum: [thing] # JSON:API requires a type identifier | |
attributes: | |
type: object | |
properties: | |
prop1: | |
type: string | |
prop2: | |
type: string | |
prop3: | |
type: string | |
required: | |
- id | |
- type | |
additionalProperties: false | |
ThingCreate: | |
allOf: | |
- $ref: '#/components/schemas/Thing' | |
required: | |
- attributes | |
properties: | |
attributes: | |
type: object | |
required: | |
- prop1 | |
- prop2 | |
- prop3 | |
properties: | |
prop1: | |
type: string | |
prop2: | |
type: string | |
prop3: | |
type: string | |
ThingUpdate: | |
allOf: | |
- $ref: '#/components/schemas/Thing' | |
properties: | |
attributes: | |
type: object | |
properties: | |
prop1: | |
type: string | |
prop2: | |
type: string | |
prop3: | |
type: string | |
minProperties: 2 # Requires at least two properties, such as id and one attribute for update | |
ThingResponse: | |
type: object | |
properties: | |
data: | |
type: object | |
properties: | |
id: | |
type: integer | |
type: | |
type: string | |
enum: [thing] | |
attributes: | |
type: object | |
properties: | |
prop1: | |
type: string | |
prop2: | |
type: string | |
prop3: | |
type: string | |
required: | |
- data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment