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][Python] NameError: name 'AnyOf' is not defined #18612

Open
5 of 6 tasks
rei-ber opened this issue May 8, 2024 · 1 comment
Open
5 of 6 tasks

[BUG][Python] NameError: name 'AnyOf' is not defined #18612

rei-ber opened this issue May 8, 2024 · 1 comment

Comments

@rei-ber
Copy link

rei-ber commented May 8, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The pyhton client generates an object called AnyOf which does not exist.

openapi-generator version

7.5.0 or this for me latest main branch

OpenAPI declaration file content or url

broken: https://gist.github.com/rei-ber/53a9c9bbf57ecd4d49e955f02fe33c46
works: https://gist.github.com/rei-ber/d93abc83f7dbabb5ff673517cfc4d4a6

Generation Details

Python 3.11.9
Podman 5.0.2

Steps to reproduce
mkdir any_of_test
cd any_of_test
curl https://gist.githubusercontent.com/rei-ber/53a9c9bbf57ecd4d49e955f02fe33c46/raw/86e6d9ce1e0af5c1f2212306603714c2468f0880/gistfile1.txt -o openapi.json
podman run --rm --volume ${PWD}:/src openapitools/openapi-generator-cli:latest generate --package-name any_of_test --input-spec /src/openapi.json --generator-name python --output /src/generated --enable-post-process-file
python3 -m venv venv
source venv/bin/activate
cd generated/
pip install -r requirements.txt

echo """
from any_of_test.models.usecase_data import (
    UsecaseData,
)

usecase = UsecaseData()
obj = {
    'reputation': {'fieldref': '', 'mark': '', 'ttl': 0},
}
usecase.from_dict(obj)
""" > any_of_test.py 

python any_of_test.py

Produces the following:

Traceback (most recent call last):
  File "/home/reiber/Downloads/any_of_test/generated/any_of_test.py", line 10, in <module>
    usecase.from_dict(obj)
  File "/home/reiber/Downloads/any_of_test/generated/any_of_test/models/usecase_data.py", line 91, in from_dict
    "reputation": AnyOf.from_dict(obj["reputation"]) if obj.get("reputation") is not None else None
                  ^^^^^
NameError: name 'AnyOf' is not defined
Related issues/PRs

#17415

Suggest a fix

If I change the title and remove UUID like:

42c42
<                 "title": "UsecaseDataUUID",
---
>                 "title": "UsecaseData",
103c103
<                                     "title": "UsecaseDataUUID",
---
>                                     "title": "UsecaseData",

it works:

mkdir any_of_test
cd any_of_test
curl https://gist.githubusercontent.com/rei-ber/d93abc83f7dbabb5ff673517cfc4d4a6/raw/a1a26f7259fe589add3086ae365a2e1950f79397/gistfile1.txt -o openapi.json
podman run --rm --volume ${PWD}:/src openapitools/openapi-generator-cli:latest generate --package-name any_of_test --input-spec /src/openapi.json --generator-name python --output /src/generated --enable-post-process-file
python3 -m venv venv
source venv/bin/activate
cd generated/
pip install -r requirements.txt

echo """
from any_of_test.models.usecase_data import (
    UsecaseData,
)

usecase = UsecaseData()
obj = {
    'reputation': {'fieldref': '', 'mark': '', 'ttl': 0},
}
usecase.from_dict(obj)
""" > any_of_test.py 

python any_of_test.py
@rei-ber
Copy link
Author

rei-ber commented May 10, 2024

I tried a bit more and got another, maybe more meaningful example. This one has a get and post path and breaks by producing an AnyOf object which does not exist.

While this one, almost the same as before, but does not contain a get path, works. This one does not produce an unknown AnyOf object.

And as in #17415 someone stated out to reduce the version: if I change openapi to 3.0.3 it works well with the broken and working example (get and post path).

Anyone has a suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant