Skip to content

Conversation

@sakurai-youhei
Copy link

This PR fixes the internal nesteddict2yaml() function to process empty dict values properly.

Without this PR, empty dict values are rendered to null so that openapi-spec-validator fails on the Swagger Spec file generated from app["SWAGGER_DEF_CONTENT"].

from aiohttp import web
import aiohttp_swagger

app = web.Application()
definitions = dict(
    test={
        "type": "object",
        "properties": {"prop": {"type": "object", "default": dict()}},
    }
)
aiohttp_swagger.setup_swagger(app, ui_version=3, definitions=definitions)

with open("spec.json", "w") as fp:
    print(app["SWAGGER_DEF_CONTENT"], file=fp)
{
  "openapi": "3.0.1",
  "info": {
    "title": "Swagger API",
    "description": "Swagger API definition",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "schemas": {
      "test": {
        "type": "object",
        "properties": {
          "prop": {
            "type": "object",
            "default": null
          }
        }
      }
    }
  },
  "paths": {}
}
spec.json: Validation Error: None for not nullable

Failed validating 'type' in schema:
    {'type': 'object', 'default': None}

On instance:
    None

Fixes: #106

P.S. Thank you for your great work on this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nesteddict2yaml renders empty dict value '{}' to null

1 participant