openapi-generator
openapi-generator copied to clipboard
[BUG] component that refs another component doesn't work
Bug Report Checklist
- [ ] Have you provided a full/minimal spec to reproduce the issue?
- [ ] Have you validated the input using an OpenAPI validator (example)?
- [ ] Have you tested with the latest master to confirm the issue still exists?
- [ ] Have you searched for related issues/PRs?
- [ ] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
component that refs another component doesn't work This came up when working on https://github.com/OpenAPITools/openapi-generator/pull/12619
Feature: jsonschema.$ref
openapi-generator version
6.0.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: openapi 3.0.3 sample spec
description: sample spec for testing openapi functionality, built from json schema
tests for draft6
version: 0.0.1
paths: {}
components:
schemas:
PropertyNamedRefThatIsNotAReference:
properties:
$ref:
type: string
ComponentRefsAnotherComponent:
$ref: '#/components/schemas/PropertyNamedRefThatIsNotAReference'
Generation Details
Generate with python-experimental
Steps to reproduce
See above
Related issues/PRs
N/A
Suggest a fix
An import should be generated I think that this used to work
EDIT: moved to https://github.com/OpenAPITools/openapi-json-schema-generator/issues/3 as my original comment is in fact a separate, unrelated issue and I don't want to cause confusion to anyone else reading this.
@mikeknep can you make a separate issue for that? The property that you mention is a codegenProperty whereas the one that I am mentioning is a codegenModel so they work differently. Hmm this may be because Animal sees Age as an AnyTypeSchema but a Dog instance is a DynamicSchema instance but it should be let through because Age is a DictSchema. Why are you AllOf including Animal in Dog and Cat? Doing that is not adding any useful validation.
This bug is also tracked here: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/issues/126
FYi if you want to use this it is working in the v2.0.0 release of openapi-json-schema-generator. That is where further development is being done on the python generator. Here is the definition of the component schema RefPet
RefPet:
$ref: '#/components/schemas/Pet'
And here is the generated class
from petstore_api.components.schema import pet
RefPet = pet.Pet
If you want this to work use it from the new location