Skip to content

[BUG] Python generator html encodes default parameter values for enums #21849

Description

@pergardebrink

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When generating a client for the Pinterest API using their openapi spec, I get weird html encoded text in the generated pydantic model. I have managed to narrow it down to the default values for enum parameters

openapi-generator version

openapi-generator-cli version 7.15.0

OpenAPI declaration file content or url

https://gist.github.com/pergardebrink/ddebb6d358763e823cf851571b73c950

Generation Details

Python: version 3.12
Install openapi-generator-cli and run the following command:

openapi-generator-cli generate -g python -o ./generated -i ./openapi.yaml
Steps to reproduce

By running the command above, the ads_analytics_post_request.py will have multiple errors.

  1. report_format instance variable (line 30) is initialized using a string instead of the enum:
report_format: Optional[DataOutputFormat] = 'JSON'
  1. The from_dict method has a syntax error in the model_validate call (line 84):
_obj = cls.model_validate({
    "report_format": obj.get("report_format") if obj.get("report_format") is not None else 'JSON'
})
return _obj
Related issues/PRs

This looks related, but not the same: #15685

Suggest a fix

I haven't looked through the codebase enough to understand exactly where the problem happens.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions