OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.33k stars 6.45k forks source link

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

Open rashmi6225 opened 3 years ago

rashmi6225 commented 3 years ago

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'
  2. 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                           
rashmi6225 commented 3 years ago

@spacether could you please look into this issue.

spacether commented 3 years ago

What is the spec that shows this issue? What template or output file includes the problem that you show? It looks like it may be the model tests. Please provide a sample spec. Without one I can't investigate this.

rashmi6225 commented 3 years ago

@spacether openAPI spec is 4.3.1, yes it is with model test. please find the sample json attached. swagger.docx attcachment of json was not allowed so i just renamed file extension. let me know any you need anything

spacether commented 3 years ago

Can you try this again using the latest master branch? Improvements were made to setting example values in the test files.

rashmi6225 commented 3 years ago

@spacether i tried with the latest master branch openapi-generator-cli-5.0.0.jar still the same issue. Could you please check again.

spacether commented 3 years ago

Hi there. So I have a lot of work at the moment and don't have time to investigate this right now. If you want to submit a PR to fix this issue, please take a look at the toExampleValueRecursive method. That method sets default example values for all models, model properties, and endpoint parameters.