OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] deepObject parameter style creates invalid code on 5.0.1 and raises exception on 5.1.1

Open
#9,603 11 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

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?
Description

when having a spec with deep objects parameter style, the python codegen creates invalid code on generator 5.0.x and fails altogether on generator 5.1.x

on 5.0.x the bad code generated looks like
api_50/api/hosts_api.py:from api_50.model.str_bool_date_datetime_dict_float_int_list_str_none_type import StrBoolDateDatetimeDictFloatIntListStrNoneType

on 5.1.x even considering them triggers

[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `filter`. Default to type:string.
[main] ERROR o.o.codegen.DefaultCodegen - Undefined property/schema for `filter`. Default to type:string.
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
openapi-generator version
  • 5.1.1
  • 5.0.1
OpenAPI declaration file content or url

api spec

relevant item is a used


components:
  parameters:
    filter_param:
      in: query
      name: filter
      required: false
      style: deepObject
      explode: true
      schema:
       type: object
Generation Details/ steps to reproduce
Related issues/PRs

i haven't found anything quite related

Suggest a fix

my current workaround is to use 5.1.x templates , the 5.0.x codegen and to post-process the generated files dropping the bad lines
it would be nice if there was a configuration option to set a deep_object_hook so users can provide a own serialization/de-serialization for deep_objects

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

Start with the linked api YAML and generation logs, reproducing the deepObject filter parameter behavior on generator 5.0.1 and 5.1.1. Inspect the Python generator path that produces api_50/api/hosts_api.py. Done means generation completes without the exception and produces valid Python without the invalid model import.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.