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

nesteddict2yaml renders empty dict value '{}' to null #106

Open
sakurai-youhei opened this issue Dec 2, 2024 · 0 comments · May be fixed by #107
Open

nesteddict2yaml renders empty dict value '{}' to null #106

sakurai-youhei opened this issue Dec 2, 2024 · 0 comments · May be fixed by #107

Comments

@sakurai-youhei
Copy link

sakurai-youhei commented Dec 2, 2024

Issue: Empty dict values in the definitions are rendered not to {} but to null incorrectly.

PoC code:

from json import loads
from aiohttp import web
from aiohttp_swagger.helpers import generate_doc_from_each_end_point

app = web.Application()
definitions = dict(
    test={
        "type": "object",
        "properties": {"prop": {"type": "object", "default": dict()}},
    }
)
doc = generate_doc_from_each_end_point(app, definitions=definitions)
print(doc)

test1 = definitions["test"]
test2 = loads(doc)["definitions"]["test"]

print(test1)
print(test2)
assert test1 == test2

Expectation:

  • The generated doc shall show "default": {}.
  • test2 extracted from the generated doc shall be equal to test1 from the original definitions.
{"swagger": "2.0", "info": {"description": "Swagger API definition\n", "version": "1.0.0", "title": "Swagger API"}, "basePath": "/", "schemes": ["http", "https"], "definitions": {"test": {"type": "object", "properties": {"prop": {"type": "object", "default": {}}}}}, "paths": {}}
{'type': 'object', 'properties': {'prop': {'type': 'object', 'default': {}}}}
{'type': 'object', 'properties': {'prop': {'type': 'object', 'default': {}}}}

Observation:

  • The generated doc shows "default": null.
  • test2 extracted from the generated doc isn't equal to test1 from the original definitions.
{"swagger": "2.0", "info": {"description": "Swagger API definition\n", "version": "1.0.0", "title": "Swagger API"}, "basePath": "/", "schemes": ["http", "https"], "definitions": {"test": {"type": "object", "properties": {"prop": {"type": "object", "default": null}}}}, "paths": {}}
{'type': 'object', 'properties': {'prop': {'type': 'object', 'default': {}}}}
{'type': 'object', 'properties': {'prop': {'type': 'object', 'default': None}}}
Traceback (most recent call last):
  File "C:\Users\YouheiSakurai\Desktop\poc.py", line 20, in <module>
    assert test1 == test2
           ^^^^^^^^^^^^^^
AssertionError

Environment

  • Python 3.12.7
  • aiohttp-swagger 1.0.16
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 a pull request may close this issue.

1 participant