Describe the bug
I have been trying to use datamodel-code-generator
with the following specification: https://github.com/hashintel/hash/blob/main/apps/hash-graph/openapi/openapi.json.
The current workflow is that I first bundle all references using @redocly/cli
and then pipe it into datamodel-code-generator
, but from my understanding, datamodel-code-generator
actually supports loading local files.
Sadly it seems like something in our configuration is going wrong, as datamodel-code-generator
terminates unsuccessfully, claiming it cannot resolve a reference (which one is unclear). Shown from the bundle commands before, our schema is certainly well-formed, so I do not fully understand what the problem is.
Any help would be greatly appreciated. Thank you! This app has already been a huge help!
To Reproduce
https://github.com/hashintel/hash/blob/bm/graph/name-fix/apps/hash-graph/openapi/openapi.json
(I'd love to show a minimal reproducible example here, but I haven't been able to minimize the input yet)
Used commandline:
poetry run datamodel-codegen \
--input "openapi.json" \
--output "$DIR/../graph_client/models.py" \
--output-model-type pydantic_v2.BaseModel \
--input-file-type openapi \
--use-standard-collections \
--use-union-operator \
--target-python-version 3.11 \
--use-schema-description \
--snake-case-field \
--disable-timestamp \
--enable-version-header \
--enum-field-as-literal one \
--use-double-quotes \
--field-constraints \
--allow-population-by-field-name \
--strict-nullable \
--use-title-as-name
Expected behavior
datamodel-code-generator
is able to generate a schema.
Version:
Additional context
The error I am encountering is:
Exception: A Parser can not resolve classes: [class: openapi.json#/components/schemas/CreatePropertyTypeRequest references: frozenset({'models/property_type.json#', 'openapi.json#/components/schemas/OwnedById', 'openapi.json#/components/schemas/RecordCreatedById'})], [class: models/property_type.json# references: frozenset({'models/shared.json#/definitions/VersionedUrl', 'models/property_type.json#/definitions/PropertyValues'})], [class: openapi.json#/components/schemas/DataTypeStructuralQuery references: frozenset({'openapi.json#/components/schemas/GraphResolveDepths', 'openapi.json#/components/schemas/Filter', 'openapi.json#/components/schemas/QueryTemporalAxesUnresolved'})], [class: openapi.json#/components/schemas/EntityStructuralQuery references: frozenset({'openapi.json#/components/schemas/GraphResolveDepths', 'openapi.json#/components/schemas/Filter', 'openapi.json#/components/schemas/QueryTemporalAxesUnresolved'})], [class: openapi.json#/components/schemas/EntityTypeStructuralQuery references: frozenset({'openapi.json#/components/schemas/GraphResolveDepths', 'openapi.json#/components/schemas/Filter', 'openapi.json#/components/schemas/QueryTemporalAxesUnresolved'})], [class: openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/0#-datamodel-code-generator-#-object-#-special-# references: frozenset({'openapi.json#/components/schemas/Filter'})], [class: openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/1#-datamodel-code-generator-#-object-#-special-# references: frozenset({'openapi.json#/components/schemas/Filter'})], [class: openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/2#-datamodel-code-generator-#-object-#-special-# references: frozenset({'openapi.json#/components/schemas/Filter'})], [class: openapi.json#/components/schemas/Filter references: frozenset({'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/7#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/5#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/0#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/6#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/4#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/1#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/2#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/Filter/Filter#-datamodel-code-generator-#-oneOf-#-special-#/3#-datamodel-code-generator-#-object-#-special-#'})], [class: openapi.json#/components/schemas/OntologyVertex/OntologyVertex#-datamodel-code-generator-#-oneOf-#-special-#/1#-datamodel-code-generator-#-object-#-special-# references: frozenset({'openapi.json#/components/schemas/PropertyTypeWithMetadata'})], [class: openapi.json#/components/schemas/OntologyVertex references: frozenset({'openapi.json#/components/schemas/OntologyVertex/OntologyVertex#-datamodel-code-generator-#-oneOf-#-special-#/1#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/OntologyVertex/OntologyVertex#-datamodel-code-generator-#-oneOf-#-special-#/2#-datamodel-code-generator-#-object-#-special-#', 'openapi.json#/components/schemas/OntologyVertex/OntologyVertex#-datamodel-code-generator-#-oneOf-#-special-#/0#-datamodel-code-generator-#-object-#-special-#'})], [class: openapi.json#/components/schemas/OntologyVertices references: frozenset({'openapi.json#/components/schemas/OntologyVertex'})], [class: openapi.json#/components/schemas/PropertyTypeStructuralQuery references: frozenset({'openapi.json#/components/schemas/GraphResolveDepths', 'openapi.json#/components/schemas/Filter', 'openapi.json#/components/schemas/QueryTemporalAxesUnresolved'})], [class: openapi.json#/components/schemas/PropertyTypeWithMetadata references: frozenset({'openapi.json#/components/schemas/OntologyElementMetadata', 'models/property_type.json#'})], [class: openapi.json#/components/schemas/Subgraph references: frozenset({'openapi.json#/components/schemas/GraphResolveDepths', 'openapi.json#/components/schemas/GraphElementVertexId', 'openapi.json#/components/schemas/SubgraphTemporalAxes', 'openapi.json#/components/schemas/Vertices', 'openapi.json#/components/schemas/Edges'})], [class: openapi.json#/components/schemas/UpdatePropertyTypeRequest references: frozenset({'models/update_property_type.json#', 'openapi.json#/components/schemas/RecordCreatedById'})], [class: models/update_property_type.json# references: frozenset({'models/update_property_type.json#/definitions/PropertyValuesUpdate'})], [class: openapi.json#/components/schemas/Vertex references: frozenset({'openapi.json#/components/schemas/KnowledgeGraphVertex', 'openapi.json#/components/schemas/OntologyVertex'})], [class: openapi.json#/components/schemas/Vertices references: frozenset({'openapi.json#/components/schemas/KnowledgeGraphVertex', 'openapi.json#/components/schemas/OntologyVertex'})].
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