You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When I try to generate models from an OpenAPI schema containing discriminators, I get an error: RuntimeError: Discriminator type is not found.
To Reproduce
Get the OpenAPI spec for the Jira REST API, or the reduced example below. Try to convert it into Pydantic models using datamodel-code-generator.
Example schema:
{
"components": {
"schemas": {
"CustomContextVariable": {
"additionalProperties": false,
"discriminator": {
"mapping": {
"issue": "#/components/schemas/IssueContextVariable",
"json": "#/components/schemas/JsonContextVariable",
"user": "#/components/schemas/UserContextVariable"
},
"propertyName": "type"
},
"oneOf": [
{
"$ref": "#/components/schemas/UserContextVariable"
},
{
"$ref": "#/components/schemas/IssueContextVariable"
},
{
"$ref": "#/components/schemas/JsonContextVariable"
}
],
"properties": {
"type": {
"description": "Type of custom context variable.",
"type": "string"
}
},
"required": [
"type"
],
"type": "object"
},
"JsonContextVariable": {
"description": "A JSON object with custom content.",
"properties": {
"type": {
"description": "Type of custom context variable.",
"type": "string"
},
"value": {
"description": "A JSON object containing custom content.",
"type": "object"
}
},
"required": [
"type"
],
"type": "object"
},
"IssueContextVariable": {
"description": "An [issue](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#issue) specified by ID or key. All the fields of the issue object are available in the Jira expression.",
"properties": {
"id": {
"description": "The issue ID.",
"format": "int64",
"type": "integer"
},
"key": {
"description": "The issue key.",
"type": "string"
},
"type": {
"description": "Type of custom context variable.",
"type": "string"
}
},
"required": [
"type"
],
"type": "object"
},
"UserContextVariable": {
"description": "A [user](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#user) specified as an Atlassian account ID.",
"properties": {
"accountId": {
"description": "The account ID of the user.",
"type": "string"
},
"type": {
"description": "Type of custom context variable.",
"type": "string"
}
},
"required": [
"accountId",
"type"
],
"type": "object"
}
}
},
"info": {
"contact": {
"email": "ecosystem@atlassian.com"
},
"description": "Jira Cloud platform REST API documentation",
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"termsOfService": "http://atlassian.com/terms/",
"title": "The Jira Cloud platform REST API",
"version": "1001.0.0-SNAPSHOT-157e8201994ee15df4ad7fc2b41795e7c88fbc36"
},
"openapi": "3.0.1",
"paths": {},
"servers": [
{
"url": "https://your-domain.atlassian.net"
}
],
"tags": []
}
Traceback (most recent call last):
...
File ".../python3.11/site-packages/datamodel_code_generator/parser/base.py", line 772, in __apply_discriminator_type
raise RuntimeError(
RuntimeError: Discriminator type is not found. test-openapi.json#/components/schemas/CustomContextVariable#-datamodel-code-generator-#-oneOf-#-special-##-datamodel-code-generator-#-oneOfCommon-#-special-#/0
Expected behavior
The command should generate a file models.py containing pydantic models.
Version:
OS: Ubuntu
Python version: 3.11.4
datamodel-code-generator version: 0.25.3
Additional context
None
The text was updated successfully, but these errors were encountered:
Describe the bug
When I try to generate models from an OpenAPI schema containing discriminators, I get an error:
RuntimeError: Discriminator type is not found
.To Reproduce
Get the OpenAPI spec for the Jira REST API, or the reduced example below. Try to convert it into Pydantic models using
datamodel-code-generator
.Example schema:
Used commandline:
Result:
Expected behavior
The command should generate a file
models.py
containing pydantic models.Version:
Additional context
None
The text was updated successfully, but these errors were encountered: