OpenAPITools / OpenAPITools/openapi-generator

[REQ] [python-fastapi] Need support for generating Strict Types in pydantic models as part of python-fastapi generator

Open
#11,610 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

As part of the python-fastapi generator, the generated models inherit from the pydantic BaseModel class.

But, the data types used in the generated models currently support basic types and not Strict Types.

Due to this, as mentioned in this issue, pydantic will try to parse values into the shape specified by the model, including coercing the types.

Describe the solution you'd like

The openapi-generator can add an option to the python-fastapi generator, where the generated models will use Strict Types, instead of plain types.

Describe alternatives you've considered

Currently, the generated models need to be edited manually to convert from Types to Strict Types.

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 python-fastapi generator and inspect how generated models inherit from pydantic BaseModel and map OpenAPI types. Define the generator option and expected Strict Types behavior, then verify that generated models use strict types instead of plain types without requiring manual edits.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, tooling
Issue type
Feature
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.