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

Bug: Unexpected openapi type in typescript generation #3276

Open
1 of 4 tasks
bpereto opened this issue Mar 28, 2024 · 2 comments
Open
1 of 4 tasks

Bug: Unexpected openapi type in typescript generation #3276

bpereto opened this issue Mar 28, 2024 · 2 comments
Labels
Bug 🐛 This is something that is not working as expected

Comments

@bpereto
Copy link

bpereto commented Mar 28, 2024

Description

Generating typescript from openapi schema results in an Error: TypeError: received an unexpected openapi type: None

I think this is due to the Response Object "400" contains "null", but I didn't went into the schema generation rabbit hole.

{
  "400": {
    "description": "Bad request syntax or unsupported method",
    "content": {
      "application/json": {
        "schema": {
          "properties": {
            "status_code": {
              "type": "integer"
            },
            "detail": {
              "type": "string"
            },
            "extra": {
              "additionalProperties": {},
              "type": [
                "null",
                "object",
                "array"
              ]
            }
          }
        }
      }
    }
  }
}

URL to code causing the issue

raise TypeError(f"received an unexpected openapi type: {schema.type}") # pragma: no cover

MCVE

Use litestar fullstack.

Steps to reproduce

git clone https://github.com/litestar-org/litestar-fullstack.git
cd litestar-fullstack
make install
source .venv/bin/activate
app schema typescript

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

Traceback (most recent call last):
  File ".venv/bin/app", line 8, in <module>
    sys.exit(run_cli())
             ^^^^^^^^^
  File "src/app/__main__.py", line 25, in run_cli
    run_litestar_cli()
  File ".venv/lib/python3.12/site-packages/litestar/__main__.py", line 6, in run_cli
    litestar_group()
  File ".venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 273, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 273, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/cli/commands/schema.py", line 75, in generate_typescript_specs
    specs = convert_openapi_to_typescript(app.openapi_schema, namespace)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/converter.py", line 299, in convert_openapi_to_typescript
    responses = parse_responses(operation.responses or {}, components=openapi_schema.components)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/converter.py", line 228, in parse_responses
    ts_type = parse_schema(content[0])
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 146, in parse_schema
    return TypeScriptArray(parse_schema(schema.items))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 148, in parse_schema
    return create_interface(
           ^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 95, in create_interface
    parsed_properties = tuple(
                        ^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 98, in <genexpr>
    value=parse_schema(schema),
          ^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 152, in parse_schema
    return parse_type_schema(schema=schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/litestar/_openapi/typescript_converter/schema_parsing.py", line 129, in parse_type_schema
    raise TypeError(f"received an unexpected openapi type: {schema.type}")  # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: received an unexpected openapi type: None

Litestar Version

2.7.1

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@bpereto bpereto added the Bug 🐛 This is something that is not working as expected label Mar 28, 2024
@bpereto bpereto changed the title Bug: <title> Bug: Unexpected openapi type in typescript generation Mar 28, 2024
@provinzkraut
Copy link
Member

provinzkraut commented Mar 29, 2024

@cofin? I feel like we've hit this before in fullstack 👀

@bpereto
Copy link
Author

bpereto commented Mar 30, 2024

I'm not sure of its fullstack related, but currently didn't reproduced it from plain litestar as I'm using fullstack as base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants