Is there a way to represent a property as generally readOnly, but allow the property to be written during a POST or PUT (i.e. a create or replace) action?
In other words, when creating the resource, I'd like the property to be writable. But once the resource is created, I'd like to keep it immutable. Can a property be POSTable/PUTable, but not PATCHable?
Example:
# OK example.
/AwesomeResource POST
{"owner": "ownerID123"}
vs
# Bad Request example.
/AwesomeResource/456 PATCH
{"owner": "ownerID789"}
You'll need separate models for POST/PUT and PATCH/GET. The POST/PUT model with writable owner property can be the base model, which the PATCH/GET model will extend by adding the readOnly constraint.
# openapi: 3.0.0
components:
schemas:
# Model for POST and PUT
NewAwesomeResource:
type: object
properties:
owner:
type: string
example: ownerID789
...
# Model for PATCH and GET
AwesomeResource:
allOf:
- $ref: '#/components/schemas/NewAwesomeResource'
properties:
owner:
readOnly: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With