I'm looking for some advice with my Open API 3.0 Spec, This is an example of my User schema object. I'm hoping to make some of the fields optional somehow but I'm not sure how to define them.
When I paste the full spec in https://editor.swagger.io it displays everything in the 'Try it out' function. Some of the other models are larger so it can be quite cumbersome deleting all the related fields, maybe they could show fieldName: {} so you know they're there available? I'm not sure how this should be handled.
This schema object is used for POST, PUT and GET as a $ref object, I'm trying to keep it DRY as possible.
It maybe also worth noting that due to tooling not working quite right just yet (or maybe it's my spec) I'm converting the end built result to swagger 2.0 to generate Swift 4 and Angular Typescript libraries.
Also it's worth noting I call these extra fields with the api by using an includes query string param e.g. users?includes=person,person.telephone,createdByUser,repStats etc... So I only want them when included in a GET request.
See the commented fields below.
User:
type: object
properties:
uuid:
type: string
username:
type: string
password:
type: string
format: password
email:
type: string
personUuid:
type: string
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
deletedAt:
type: string
format: date-time
createdByUuid:
type: string
updatedByUuid:
type: string
# Relations.
# I want these read only and optional on GET requests.
# They can be there on PUT/POST requests, the server will simply
# ignore them.
person:
$ref: '#/components/schemas/Person'
createdByUser:
$ref: '#/components/schemas/User'
updatedByUser:
$ref: '#/components/schemas/User'
repStats:
$ref: '#/components/schemas/RepStats'