-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
"A Parser can not resolve classes" error when generating code from an OpenAPI spec #1968
Comments
I managed to narrow it down to an input like this (
The crash log:
I can't reduce the example any further.
So it seems like a $ref/anyOf/enum edge case? |
Interesting, if I change that
the tool actually generates code: # generated by datamodel-codegen:
# filename: openapi.yml
# timestamp: 2024-05-23T11:41:39+00:00
from __future__ import annotations
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class MassUnit(Enum):
g = 'g'
kg = 'kg'
t = 't'
class QuantityTrunc(BaseModel):
__root__: MassUnit = Field(
...,
description='Selects to which precision to truncate quantities specific to carbon offsetting.',
example='t',
)
class CreateOrderByEstimateRequest(BaseModel):
quantity_trunc: Optional[QuantityTrunc] = None |
Hi. I'm also facing this issue. Did you find a way to resolve it other than replacing |
Hey @dpeachey, no, I had to get things done quickly so because of this and some other issues I skipped code generation completely and just wrote the types I needed by hand. :| |
Hey all, first of all thank you all for coming up with this project and the continued work on it.
I bumped into the following crash this morning. I may attempt to investigate what's wrong but I figured it wouldn't hurt to report it right away.
Describe the bug
datamodel-codegen
produced an error instead of generating code:To Reproduce
The OpenAPI schema used (too large to include): https://raw.githubusercontent.com/lune-climate/lune-docs/68726ac5b6e3b5c76cb683503311f0bb39d302f4/static/openapi.yml
There may be something non-standard or broken about this specification that I'm not aware of but it is accepted by multiple other libraries/tools and it's been working fine so far.
Used commandline:
Expected behavior
I'd expect one of the following:
Version:
Additional context
N/A
The text was updated successfully, but these errors were encountered: