Parameter only for POST #2865
-
I have a schema that I would like to use for both POST and PUT methods but a target parameter is allowed only for the POST request. To make it clear let's imagine that there is a possibility to create and update a user. components:
schemas:
user:
type: object
properties:
name:
type: string
inviteCode:
type: string
paths:
"/user":
post:
requestBody:
content:
application/json:
schema:
"$ref": "#/components/schemas/user"
"/user/{id}":
put:
parameters:
- name: id
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
"$ref": "#/components/schemas/user" Is there a way to do it by just adding a parameter to the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
JSON Schema doesn't quite allow you to pick and choose which properties you want to use from a given schema definition.
|
Beta Was this translation helpful? Give feedback.
-
Answer accepted by OP, closing. |
Beta Was this translation helpful? Give feedback.
JSON Schema doesn't quite allow you to pick and choose which properties you want to use from a given schema definition.
You have two options:
user
into two schemas, where one usesallOf
the other and adds theinviteCode
user
schema for both, but in the case of put make it a combination ofallOf
andnot
to remove support forinviteCode