Describe the bug
In our open source project reqstool we have several JSON Schemas. We would like to use datamode-code-generator to generate pydantic v2 code, but the code does not get generated correctly.
Our schemas have been validated with: check-jsonschema --verbose --schemafile "https://json-schema.org/draft/2020-12/schema" <schema_folder>/*
However, it seems as if patternProperties in JSON Schemas are not handled properly.
To Reproduce
Example schema:
All schemas are available here: https://github.com/Luftfartsverket/reqstool-client/tree/main/src/reqstool/resources/schemas/v1
The requirements.schema.json is the most advanced but it does not use pattternProperties.
An example to use is: annotations.schema.json where there is:
note: This particular case does not need to use patternProperties since the two properties implementations
and tests
and known before runtime.
"$defs": {
"requirement_annotations": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^implementations": {
"type": "object",
"$ref": "#/$defs/annotation",
"description": "requirement annotation used in implementation"
},
"^tests": {
"type": "object",
"$ref": "#/$defs/annotation",
"description": "requirement annotation used in test"
}
}
}
Used commandline:
$ DIR=. find $DIR -type f -name '*.schema.json' -exec sh -c 'base_name=$(basename "{}" .schema.json); datamodel-codegen --input "{}" --input-file-type jsonschema --output "$DIR/$base_name.py" --output-model-type pydantic_v2.BaseModel --use-annotated --use-standard-collections --capitalize-enum-members --target-python-version 3.10 --use-schema-description --wrap-string-literal --use-double-quotes --use-field-description --snake-case-field ' \;
Expected behavior
A clear and concise description of what you expected to happen.
Version:
Additional context
Add any other context about the problem here.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too