OpenAPITools / OpenAPITools/openapi-generator

[BUG] Adds null to the Param which should actually be None and the attribute error. in api

Open
#7,934 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

It seems that openapi cli gererates invalid python test code

Steps to reproduce

commands
openapi-generator-cli generate 
-i api-doc.json \
-g python \
-o out/python
cd /out/python
tox
Results
  1. No atribute errors, for some reason tests think that banana_tick_bananars should have attribute bananaTick_bananars but generated code does not have that and it would be silly as api definition does not have nested bananaTickBananars.
...
        else :                                                                                                          
            return bananaTick(                                                                                        
                id = '0',                                                                                               
                name = '0',
                bananars = [                                                                                             
>                   openapi_client.models.banana_tick_bananars.bananaTick_bananars(                                   
                        provided_bananas = [                                                                             
                            openapi_client.models.provided_banana.Providedbanana(
                                snapshot = True,
                                banana = '0', )                                                                          
                            ],
                        params = null,
                        type = null,                                                                                    
                        name = '0',                                                                                     
                        id = null, )
                    ],                                                                                                  
        )                                                                                                               
E           AttributeError: module 'openapi_client.models.banana_tick_bananars' has no attribute 'bananaTick_bananars'
  1. Why genererator uses null in python code and not None?
...
        # model = openapi_client.models.tracer_res.BananarRes()  # noqa: E501
        if include_optional :                                               
            return BananarRes(                                               
                id = null,                                                  
                name = '0',                                                 
                type = null,                                                
                availability = 1.337                                        
            )                                                               
        else :                                                              
            return BananarRes(                                               
>               id = null,                                                  
                name = '0',                                                 
                type = null,                                                
                availability = 1.337,                                       
        )                                                                   
E           NameError: name 'null' is not defined                           

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 issue with openapi-generator-cli using the shown api-doc.json, the python generator, and tox. Inspect the generated Python model and test code for the invalid model attribute name and JSON-style null values; done means the generated tests use existing model attributes and valid Python None values.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.