Repository navigation
Support schema references #734
Copy link
Copy link
Closed
Labels
🍭 OpenAPI ComplianceSupporting a new bit of the OpenAPI specSupporting a new bit of the OpenAPI spec
Description
Describe the bug
If swagger.json contains a reference like:
"SchemaA": {
"$ref": "#/components/schemas/SchemaB"
},
python client unable to generate a proper model for this definition
To Reproduce
Steps to reproduce the behavior:
- Define a swagger.json that contains a reference to another model
- Generate a client
openapi-python-client generate --path swagger.json
Expected behavior
Client should contain generated endpoint and contain a model
OpenAPI Spec File
{
"components": {
"examples": {},
"headers": {},
"parameters": {},
"requestBodies": {},
"responses": {},
"schemas": {
"SchemaB_string_": {
"properties": {
"foo": {
"type": "string"
}
},
"required": [
"foo"
],
"type": "object",
"additionalProperties": true
},
"SchemaA": {
"$ref": "#/components/schemas/SchemaB_string_"
}
},
"securitySchemes": {}
},
"info": {
"title": "bar-service",
"version": "1.0.0",
"description": "bar service",
"license": {
"name": "ISC"
}
},
"openapi": "3.0.0",
"paths": {
"/foo": {
"post": {
"operationId": "Foo",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SchemaA"
}
}
}
}
},
"tags": [
"foobar"
],
"security": [],
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SchemaA"
}
}
}
}
}
}
},
"servers": [
{
"url": "/"
}
]
}
Desktop (please complete the following information):
- OS: macOS
- Python Version: 3.9.9
- openapi-python-client version: 0.13.1
Additional context
Stdout:
Generating bar-service-client
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
WARNING parsing POST /foo within foobar. Endpoint will not be generated.
Could not find reference in parsed models or enums
Reference(ref='#/components/schemas/SchemaA')
Unable to parse this part of your OpenAPI document:
Reference schemas are not supported.
Reference(ref='#/components/schemas/SchemaB_string_')
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🍭 OpenAPI ComplianceSupporting a new bit of the OpenAPI specSupporting a new bit of the OpenAPI spec
Activity
[-]Schema $ref is not supported[/-][+]Support schema references[/+]joaonc commentedon May 3, 2023
Yes please!
Currently reference schemas are explicitly not supported (here), but it's unclear why as adding this support seems not too difficult and increasingly necessary, especially as more people use TypeScript with models defined in objects (
constortypeinstead ofinterface). TS linters (Pretty, at least) discourages the use ofinterfacein favor oftype, which creates the reference schema.aletor123 commentedon May 22, 2023
+1
M1troll commentedon May 23, 2023
+1
yu-iskw commentedon Jun 20, 2023
+1
authentichamza commentedon Jun 21, 2023
+1
paulo-raca commentedon Jul 6, 2023
+1
seanhumbarger commentedon Jul 12, 2023
+1
Mexflubber commentedon Jul 19, 2023
+1
mikedavidson-evertz commentedon Jul 26, 2023
+1
rshah-evertz commentedon Aug 1, 2023
+1
dbanty commentedon Aug 13, 2023
Folks seem to really want to vote for features, given all the “+1”, so I’m converting features to discussions so y’all can click the up arrow instead. Then, anyone contributing code can sort by most-voted-for 😁.