openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ] Generate python client with using pydantic models

Open timothyjlaurent opened this issue 6 years ago • 2 comments

Description

Pydantic offers a clean model api with fast validation. It would be a nice enhancement to generate such models from openapi specs.

openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

timothyjlaurent avatar Jul 03 '19 05:07 timothyjlaurent

pydantic coerces data types into the defined types openapi constrains payloads to a set of allowed types and sometimes defines validations that must be done and other schemas (oneaOf/anyOf/allOf discriminated schemas that must also be validated against)

In my opinion coercion goes agains the type constraints that openapi defines because it is changing the type of the payload that you are making assertions against.

That being said, I understand the motivation. The python-fastapi server generator uses pydantic: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/python-fastapi.md#metadata

A python client that does not coerce instantiated/received data

Our python-experimental generator does NOT do coercion on received payloads and it has

  • robust run time type + validation checking
  • oneOf/anyOf/allOf support including imposing type constraints in composed schemas
  • type hints for models, properties, endpoint parameters, and responses

I encourage you to give it a look and see if it will meet your needs.

spacether avatar Jan 12 '22 07:01 spacether

Update: the python-fastapi generator was created which is a server generator and it uses pydantic for model generation So it's not a client but it uses pydantic

spacether avatar Sep 16 '22 19:09 spacether

Why did you close it? There's no pydantic client yet.

spacether avatar Sep 23 '22 16:09 spacether

It's such an old issue -- I get feedback once every year or 2 - I've moved on. Feel free to reopen it.

timothyjlaurent avatar Sep 23 '22 20:09 timothyjlaurent

No worries, I was just curious and don't want to reopen if

spacether avatar Sep 23 '22 20:09 spacether