question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][PYTHON] inline response types generate invalid code referring to UNKNOWNBASETYPE

See original GitHub issue

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

using inline responses can generate unknown base types resulting in bad docs on 4.3.0 and bad code on 5.0.x

openapi-generator version

5.0.1 snapshot, 5.0, master

OpenAPI declaration file content or url

https://gist.github.com/RonnyPfannschmidt/71a7d9bc344be968f0fed5559b5ee502#file-apispec-json

Generation Details
docker run --rm --volume "${PWD}":/local:z \
    openapitools/openapi-generator-cli generate \
    -i /local/apispec.json \
    -g python \
    -o /local/package

and for comparison with 4.3.1


docker run --rm --volume "${PWD}":/local:z \
    openapitools/openapi-generator-cli:v4.3.1 generate \
    -i /local/apispec.json \
    -g python \
    -o /local/package
Steps to reproduce
$ ag UNKNOWNBASETYPE package/
package/openapi_client/api/example_api.py
25:from openapi_client.model.unknownbasetype import UNKNOWNBASETYPE

package/docs/ExampleApi.md
24:from openapi_client.model.unknownbasetype import UNKNOWNBASETYPE

package/README.md
54:from openapi_client.model.unknownbasetype import UNKNOWNBASETYPE

and on v4.3.1

$ ag UNKN package/
package/openapi_client/api/example_api.py
50:        :param UNKNOWN_BASE_TYPE unknown_base_type:
76:        :param UNKNOWN_BASE_TYPE unknown_base_type:

package/README.md
68:unknown_base_type = openapi_client.UNKNOWN_BASE_TYPE() # UNKNOWN_BASE_TYPE |  (optional)

package/docs/ExampleApi.md
37:unknown_base_type = openapi_client.UNKNOWN_BASE_TYPE() # UNKNOWN_BASE_TYPE |  (optional)
52: **unknown_base_type** | [**UNKNOWN_BASE_TYPE**](UNKNOWN_BASE_TYPE.md)|  | [optional] 
Related issues/PRs
Suggest a fix

My understanding is that a inline type should be generated for inline responses, i would expect either a creation/usage of a inline type or an error suggesting extraction of the schema

depending on how hard this is, schema validators should also report this as warning/issue

a in-spec solution is to extract inline schemas to explicit schemas

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Aug 30, 2021

@stonecharioteer as I wrote in the original post, the workaround is to extract the inlined schemas to explicit ones

0reactions
wing328commented, May 10, 2022

https://github.com/OpenAPITools/openapi-generator/pull/12293 has been merged into master. Please pull the latest to give it a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix this ValueError invalid literal for int with base 10 ...
You can solve this error by using the Python isdigit() method to check whether the value is number or not.
Read more >
PEP 484 – Type Hints - Python Enhancement Proposals
One common case of union types are optional types. By default, None is an invalid value for any type, unless a default value...
Read more >
PEP 589 – TypedDict: Type Hints for Dictionaries with a Fixed ...
A TypedDict type represents dictionary objects with a specific set of string keys, and with specific value types for each valid key.
Read more >
PEP 8 – Style Guide for Python Code
Surround top-level function and class definitions with two blank lines. Method definitions inside a class are surrounded by a single blank line.
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. The most fundamental support consists of the types Any, Union, Callable, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found