Skip to content

ApiGateway OpenApi 3.0.1 nullable properties

0

This is my input body request

{
    "storeIntegrationName": "DEV STORE",
    "storeCreationDate": "2023-12-20T05:36:56-05:00",
    "storeUpdateDate": "2023-12-20T05:37:05-05:00",
    "storeReference": "8065509753074",
    "name": "The Collection Snowboard: Oxygen",
    "bodyHtml": null
}

i have set property nullable: true for param bodyHtml in the object body of a cloudformation Resource Type: AWS::ApiGateway::RestApi

        components:
          schemas:
            Article:
              type: object
              required:
              - storeIntegrationName
              - storeCreationDate
              - storeUpdateDate
              - storeReference
              - name
              properties:
                storeIntegrationName:
                  type: string
                bodyHtml:
                  type: string
                  nullable: true
                storeCreationDate:
                  type: string
                  format: date-time
                storeUpdateDate:
                  type: string
                  format: date-time
                storeReference:
                  type: string
                  nullable: true
                type:
                  type: string
                  nullable: true
                name:
                  type: string

ApiGateay validator response is

{
    "message": "Invalid request body",
    "responseType": "BAD_REQUEST_BODY",
    "validationErrorString": "[instance type (null) does not match any allowed primitive type (allowed: [\"string\"])]"
}
2 Answers
0
Accepted Answer

Resolved using this syntax

bodyHtml:
  oneOf:
    - type: string
    - type: 'null'
answered 2 years ago
-1

That is a support issue.... API Gateway validator does not fully support the nullable attribute of the OpenAPI specification. While nullable: true is valid in OpenAPI, API Gateway might not interpret it correctly, causing it to expect a string value instead of allowing null.

As a workaround, you could consider changing the type of bodyHtml to an array that can contain either a string or null, like so:

bodyHtml:
  type: array
  items:
    type: string
  minItems: 0
  maxItems: 1
EXPERT
answered 2 years ago
  • HI i think it's not the right answer. I tried to modify the model manually from the api gateway aws console and i found the right syntax

    {
      .....
        "bodyHtml" : {
          "type" : ["string","null"]
        }
    ....
    }
    
    

    Enter image description here

    Now the problem is that i didn't know how to report the model in my yaml cloudformation template.

    I tried with as mentioned here https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0 bodyHtml: type: - string - 'null'

    But cloudformation says [/Resources/IntStoreRestApi/Type/Body/components/schemas/Article/properties/bodyHtml/type/1] 'null' values are not allowed in templates

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.