OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] Syntax error in generated code with certain additionalProperties.

Open
#17,447 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Certain combinations of $ref and additionalProperties produces invalid Python.

openapi-generator version

Latest master

OpenAPI declaration file content or url

https://gist.github.com/jaklaassen-affirm/409fad729dd913427dde3aac86c9c751 contains the api.yaml that produces the error condition, the Python file showing the syntax error, and the Python file after applying the linked fix.

Generation Details

openapi-generator generate -g python -i api.yaml

Suggest a fix

This change fixed it for me: https://github.com/jaklaassen-affirm/openapi-generator/commit/74d1837ad50e78c43b98353a60a482704d5f608f. But I freely admit I don't understand the code well enough. Happy to write a test if someone can suggest the best way to test this and make a PR.

Thanks!

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 api.yaml and generated Python files in the linked gist, then reproduce the issue with openapi-generator generate -g python -i api.yaml. Compare the invalid output with the linked fix and locate the Python generator test coverage for this schema pattern. Done means the generated Python is syntactically valid and a regression test covers the $ref and additionalProperties combination.

Written by the indexing model from the issue text.

Assessment

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