https://pantsbuild.org/ logo
#general
Title
# general
f

fresh-continent-76371

03/21/2023, 10:09 PM
We have some Pydantic data models , that we need to code generate to
jsonschema
- (openapi) The "generation" is as simple as
Copy code
from pydantic import Basemodel
...

class MyPydanticModel(BaseModel):
    ...

print(json.dumps(MyPydanticModel.schema(),indent=2))
I am happy plugging my way through writing a codegen plugin for this, but was wondering if I am able to leverage the openapi source types that exists already (for linting a openapi_document, etc) just after some guidance really. and once compete, I am happy to submit this plugin
b

broad-processor-92400

03/21/2023, 10:19 PM
If you're happy to use a pre-release, pants 2.16 contains a bunch of new target types that allow you to avoid writing a plugin. For instance, https://github.com/pantsbuild/example-adhoc/blob/main/openapi/BUILD uses
adhoc_tool
to export an OpenAPI schema from a flask app and the do some other code generation based on that... I don't know if these can hook into the
openapi_document
support; maybe @ancient-vegetable-10556 can assist.
f

fresh-continent-76371

03/21/2023, 10:38 PM
ah actually yes that is all we will need I think.
perfect.
🎉 1
a

ancient-vegetable-10556

03/23/2023, 3:16 PM
Just to follow on: they currently don’t hook into
openapi_document
, but probably could with a bit of work.
2 Views