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] Pydantic generator does not correctly handle nullable union #2000

Closed
2 tasks done
janne-slamcore opened this issue May 16, 2024 · 3 comments · Fixed by #2001
Closed
2 tasks done

[BUG] Pydantic generator does not correctly handle nullable union #2000

janne-slamcore opened this issue May 16, 2024 · 3 comments · Fixed by #2001
Labels
bug Something isn't working

Comments

@janne-slamcore
Copy link
Contributor

Describe the bug.

The following spec:

{
  title: 'NullableUnionTest',
  type: 'object',
  required: ['nullableUnionTest'],
  properties: {
    nullableUnionTest: {
      anyOf: [
        {
          title: 'Union1',
          type: 'object',
          properties: {
            testProp1: {
              type: 'string'
            }
          }
        },
        {
          type: 'null'
        }
      ]
    }
  }
};

generates the following Pydantic model:

class NullableUnionTest(BaseModel): 
  nullableUnionTest: Union[Union1] = Field()
  additionalProperties: Optional[dict[Any, Any]] = Field(default=None)

which does not allow the null/None value.

Expected behavior

The generated model should support null/None values.

Screenshots

modelina_pydantic

How to Reproduce

  1. Clone https://github.com/janne-slamcore/modelina/tree/pydantic-nullable-union
  2. Undo change to Pydantic.ts
  3. npx jest test/generators/python/

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

@janne-slamcore janne-slamcore added the bug Something isn't working label May 16, 2024
Copy link
Contributor

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

@janne-slamcore go for it ✌️

@jonaslagoni
Copy link
Member

@janne-slamcore there is also quite a bit of fixes to python in the next branch in case you encounter more, check it out ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants