2

I am using swagger/openAPI 3.0.0 to generate a python3-flask API. This API gives JSON responses. If the value for a property of my JSON response is None I need it to come out as null in the response. Instead, the property is getting completely dropped from the response. I understand that this is a dumb requirement, but I do not have a choice in the matter.

In my swagger definition I have:

my_property:
  type: number
  nullable: true 

I have also tried

my_property:
  type: number
  nullable: true 
  default: null

but the results were the same.

How do I make it so that my_property is not dropped from the response when the value is None?

davidism
  • 121,510
  • 29
  • 395
  • 339
Mike Furlender
  • 3,869
  • 5
  • 47
  • 75

1 Answers1

4

Figured it out. The beginning of the generated __main__.py looks like this:

from swagger_server import encoder


def main():
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.app.json_encoder = encoder.JSONEncoder

I needed to add

app.app.json_encoder.include_nulls = True

Afterwards.

Mike Furlender
  • 3,869
  • 5
  • 47
  • 75