OpenAPITools / OpenAPITools/openapi-generator

[Bug] openapi-generator produce error for auto generated models file for Python when nested object used in schema in yml file

Open
#8,256 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I am trying to generate a python client library with openApI3 . For this I have created a openapi.yml file(https://github.com/shashank0201/python-client-openapi/blob/main/openapi.yml).
For this purpose I am using openApI-generator(https://github.com/OpenAPITools/openapi-generator)

This generator, producing a set of directory and files based on schema defined in yml file.

When I test it's auto generated fils, I am getting error below,
I couldn't undetstand why this error getting produced.
Does openAPI 3 not support nested schema/nested object inyml file ?

ERROR: testDatasource (test.test_datasource.TestDatasource)
Test Datasource
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/app/config/test/test_datasource.py", line 78, in testDatasource
    inst_req_and_optional = self.make_instance(include_optional=True)
  File "/usr/app/config/test/test_datasource.py", line 40, in make_instance
    properties = tech.client.config.models.datasource_properties.Datasource_properties(
AttributeError: module 'tech.client.config.models.datasource_properties' has no attribute 'Datasource_properties'

Note:
In file datasource_properties there is nothing like 'Datasource_properties' instead a class called 'DatasourceProperties' is there.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

Please refer
openapi.yml file https://github.com/shashank0201/python-client-openapi/blob/main/openapi.yml
Auto-generated model/datasource.py : https://github.com/shashank0201/python-client-openapi/blob/main/model/datasource.py
Test file : https://github.com/shashank0201/python-client-openapi/blob/main/model/datasource.py

Command line used for generation

my-python-clientr openapitools/openapi-generator-cli generate -i /my-python-client/openapi.yml -g python -o /stoplight-client/ --additional-properties=packageName=tech.client.config
https://github.com/shashank0201/python-client-openapi/blob/main/scripts/build_client.sh

Plese refer this issue. Let me know if any further information required. Thanks !

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generation with the linked openapi.yml and the reported openapi-generator 5.0.0-SNAPSHOT command. Compare the generated model/datasource.py, the datasource_properties module, and the referenced test to determine why the expected Datasource_properties name differs from DatasourceProperties; done means the generated client and test use a consistent model name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.