[BUG] ref to a property in the current component schema does not work
Created by: spacether
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
ref to a property in the current component schema does not work This came up while writing this unit test PR: https://github.com/OpenAPITools/openapi-generator/pull/12619
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:
PropertyRefsAdjacentProperty:
properties:
foo:
type: integer
bar:
$ref: '#/components/schemas/PropertyRefsAdjacentProperty/properties/foo'
Generation Details
Using python-experimental client generator
Steps to reproduce
Generate a client spec with python-experimental and notice that the type for PropertyRefsAdjacentProperty.bar is not correct.
Generated code:
class PropertyRefsAdjacentProperty(
AnyTypeSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
foo = IntSchema
@classmethod
@property
def bar(cls) -> typing.Type['Foo']:
return Foo
def __new__(
cls,
*args: typing.Union[dict, frozendict, str, date, datetime, int, float, decimal.Decimal, None, list, tuple, bytes],
foo: typing.Union[foo, Unset] = unset,
bar: typing.Union['Foo', Unset] = unset,
_configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema],
) -> 'PropertyRefsAdjacentProperty':
return super().__new__(
cls,
*args,
foo=foo,
bar=bar,
_configuration=_configuration,
**kwargs,
)
from unit_test_api.model.foo import Foo
When I would expect:
class PropertyRefsAdjacentProperty(
AnyTypeSchema
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
foo = IntSchema
bar = foo
def __new__(
cls,
*args: typing.Union[dict, frozendict, str, date, datetime, int, float, decimal.Decimal, None, list, tuple, bytes],
foo: typing.Union[foo, Unset] = unset,
bar: typing.Union['Foo', Unset] = unset,
_configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema],
) -> 'PropertyRefsAdjacentProperty':
return super().__new__(
cls,
*args,
foo=foo,
bar=bar,
_configuration=_configuration,
**kwargs,
)
Related issues/PRs
N/A
Suggest a fix
One needs to add code that:
- detects references to other locations in the self schema
- returns the correct class in that property
- does not generate an import for that property