Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7824
Closed
Open
Issue created Oct 27, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][PYTHON] Type null not handled properly in toExampleValue

Created by: matthewfranglen

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? (tested with 5.0.0-20201027.153630-833, 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

PythonCodegen when run against https://emergin.informer.io/api/openapi.json will produce the literal string null in the tests. This is accompanied by the warning:

[main] WARN  o.o.c.languages.PythonClientCodegen - Type null not handled properly in toExampleValue 

These values can sometimes be replaced with the literal None however in other cases they should be generated recursively.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

https://emergin.informer.io/api/openapi.json

Generation Details
openapi-generator-cli generate --generator-name python --input-spec https://emergin.informer.io/api/openapi.json
Steps to reproduce
  1. Generate the client using the command above
  2. Run the tests with pytest

You will observe that 7 tests fail and 53 pass. The errors are NameError: name 'null' is not defined.

  1. Substitute all null for None using the tool of your choice (my choice: sed -i -e s/null/None/ test/*.py)
  2. Run the tests with pytest

You will observe that 4 tests fail and 56 pass. The errors are now ValueError: Invalid value for results, must not be None

Related issues/PRs

I cannot find any occurrence of this error message in these issues, open or closed.

Suggest a fix

So the code generation is capable of handling null, as we can see here. I don't understand why it tests that the example output is not the literal null as the code immediately following the warning will just return it.

It might be possible to address some of the incorrect code generation by dropping the comparison to null on line 724, linked above.

I don't know why the recursive type is not handled correctly.

Assignee
Assign to
Time tracking