Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nesteddict2yaml not to fumble empty dict values #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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