Van
Van

Reputation: 41

(Swagger 2.0/ Connexion) None type is not of type 'string'

I am trying to create one simple post API through python connexion. Here is my api yaml file:

swagger: "2.0"

info:
  title: "My first API"
  version: "1.0"

basePath: /v1.0

paths:
  /potential:
    post:
      operationId: api.data.create_potential_data
      summary: Create the potential data
      parameters:
        - name: alertCategory
          in: body
          required: True
          description: The potential API request AlertCategoryDto object with settings of alert category (categorySystemName, alert Kpis etc.)
          schema:
            $ref: "#/definitions/alert"
      responses:
        201:
          description: Successfully created potential data


definitions:
  alert:
    properties:
      systemName:
        type: string
      name:
        type: string
      moduleSystemName:
        type: string

But for one of the attributes name we allow user to enter null value. And if they really do this, we will get the error: None type is not of type 'string'

So is there anyway in swagger 2.0 to make the attributes nullable? Cannot find much information online. Thanks!

Upvotes: 1

Views: 3718

Answers (2)

Van
Van

Reputation: 41

Thanks to @Danilo's help I found the answer from connexion's documentation here:

https://connexion.readthedocs.io/en/latest/request.html

In a word, adding x-nullable = true will resolve this issue.

Upvotes: 3

Danilo Toro
Danilo Toro

Reputation: 597

I think you should put down type: string nullable: true

From here I obtained the information This link

It would be something like this:

definitions:
  alert:
    properties:
      systemName:
        type: string
      name:
        type: string
        nullable: true
      moduleSystemName:
        type: string

Upvotes: 4

Related Questions