Skip to content

Add custom format of string and custom validation. #426

Answered by koxudaxi
gespispace asked this question in Q&A
Discussion options

You must be logged in to vote

@gespispace

Where PortRange is my custom validation class.
How to do it?

Currently, it is not supported.

We are talking about custom type in #418

How can I add my own validations to the schema, so as not to lose the model with validations in case of re-creation?

Also, validators is not supported too.
But, you can give the code generator a custom template in jinja2.
https://github.com/koxudaxi/datamodel-code-generator/blob/master/datamodel_code_generator/model/template/pydantic/BaseModel.jinja2

My idea is ...
If a special attribute will be supported in Jsonchema then we can check the value in a custom template 🤔

openapi: 3.0.0
components:
  schemas:
    Network:
      type: object
      

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by koxudaxi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants