1

I'm designing my API using Swagger in Restlet studio, and there are some calls that use the same model.

In my case the model is an Array of objects.

I would like to declare some of the object parameters as required and some as optional (as they are by default).

However it's something that should vary in different calls. I couldn't find a way to that in YAML nor in Restled studio.

Is my only option to create different models for each API call?

I did find a similar question here 2 years ago without any reponse:

How can I make parameter optional in some but required in other cases in Swagger/PHP?

Miss Take
  • 71
  • 1
  • 7
  • 1
    Possible duplicate of [Combining defintions in Swagger docs](https://stackoverflow.com/questions/29463634/combining-defintions-in-swagger-docs) – Aleksi Aug 31 '19 at 11:41

1 Answers1

0

This answer helped,

Combining defintions in Swagger docs

I specified all of the parameters in the main object and used 'allOf' attribute for the specific calls and described the required parameters there.

An example:

definitions:
      Pet:
    type: object
    discriminator: petType
    properties:
      name:
        type: string
      petType:
        type: string
    required:
    - petType
  Cat:
    description: A representation of a cat
    allOf:
    - $ref: '#/definitions/Pet'
    - type: object
      properties:
        huntingSkill:
          type: string
          description: The measured skill for hunting
          default: lazy
          enum:
          - clueless
          - lazy
          - adventurous
          - aggressive
      required:
      - huntingSkill
      - name

Swagger viewer result

Miss Take
  • 71
  • 1
  • 7