Skip to content

Support schema references #734

Description

@LadnovSasha

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:

  1. Define a swagger.json that contains a reference to another model
  2. 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_')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions