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

Code-generation of type hints and handler interfaces

Open sisp opened this issue 3 years ago • 3 comments

Something still missing in all OpenAPI-first implementations I've seen for Python including openapi-core is type-safety w.r.t. the validated request body, URL parameters, and headers. openapi-core validates this data, but there currently is no way to statically type it except for manually implementing the type hints and manually typing the request handlers. This is brittle and doesn't scale well.

I suggest to generate code containing type hints and request handler interfaces for the supported web frameworks similar to oapi-codegen (Golang) or fastapi-code-generator (Python).

The details need to be discussed and figured out, of course, but I'd appreciate some feedback first. What do you think?

sisp avatar Oct 04 '21 07:10 sisp

@p1c2u Since you've been quite active again recently, I've been wondering about your opinion on this topic. 🙂 I've noticed your 👍 reaction to this vague idea. Would you (and of course also others) be interested in pursuing this idea more concretely, and would you have the capacity to discuss a concrete proposal?

sisp avatar Sep 25 '22 10:09 sisp

Hi @sisp definitely interested. Feel free to propose your ideas. I added x-model extension support with possibility to use predefined models. See x-model extension.

p1c2u avatar Sep 25 '22 10:09 p1c2u

I'm working on something like this in Lapidary.

It's not a trivial problem, here's an article why: https://modern-json-schema.com/json-schema-is-a-constraint-system

It's written mainly from java perspective, and while python class instances are a syntactic sugar over dicts (at least for simple data classes), it still applies to type hints.

rafalkrupinski avatar Jan 13 '23 19:01 rafalkrupinski