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"
]
}
}
}
}
}
}
}
Use litestar fullstack.
git clone https://github.com/litestar-org/litestar-fullstack.git
cd litestar-fullstack
make install
source .venv/bin/activate
app schema typescript
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
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
2.7.1
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too