Search code examples
amazon-web-servicesaws-api-gateway

How to give name to response model on AWS API Gateway in OpenApi specification


We are using AWS API gateway for our OpenAPI specifications. We are also using API-first approach with OpenAPI spec embedded in our SAM templates.

Everything works perfectly until the point when we deploy our API into API gateway. All models that are created from responses are re-named using some random generator. This causes us a lot of pain, because we cannot download exported API from API gateway and give it to our teams just because this is not deterministic and it changes every time.

Is there any way to force AWS API gateway to respect response name in generated model?


Solution

  • You can define the name with title property. https://spec.openapis.org/oas/v3.0.1#schema-object

    definitions:
      Pet:
        title: Pet
        required:
          - name
          - petType # required for inheritance to work
        properties:
          name: 
            type: string
          petType:
            type: string
        discriminator:
          propertyName: petType
          x-discriminator-value: Pet
      Cat:
        title: Cat
        allOf:
          - $ref: '#/definitions/Pet' # Cat has all properties of a Pet
          - properties: # extra properties only for cats
              huntingSkill:
                type: string
                default: lazy
                enum:
                  - lazy
                  - aggressive
      Dog:
        title: Dog
        allOf:
          - $ref: '#/definitions/Pet' # Dog has all properties of a Pet
          - properties: # extra properties only for dogs
              packSize:
                description: The size of the pack the dog is from
                type: integer
    

    If that doesn't work for you, then try x-discriminator-value (ref).