I'm using OpenAPI 3.0 to describe an API where each resource has a subtly different schema based on its operation. Essentially certain properties are editable and/or required based on whether it's a POST or PUT request.
Is there a better way to do this other than specify a schema for each operation like this? (where field2 is readOnly on the PUT)
Ideally, I'd like to specify the schema (i.e. all the properties) in one place and then override some properties (e.g. readOnly) on each operation.
{
"paths":{
"/users":{
"put":{
"responses":{
"200":{
"$ref":"#/components/schemas/users_put"
}
}
},
"post":{
"responses":{
"200":{
"$ref":"#/components/schemas/users_post"
}
}
}
}
},
"components":{
"schemas":{
"users_post":{
"properties":{
"field1":{
"readOnly":true,
"type":"integer"
},
"field2":{
"type":"string"
}
}
},
"users_put":{
"properties":{
"field1":{
"readOnly":true,
"type":"integer"
},
"field2":{
"type":"string",
"readOnly":true
}
}
}
}
}
}