Skip to content

Commit a5ecca1

Browse files
committed
parser / properties / use lazy reference only for reference to themself
1 parent 7a0a3be commit a5ecca1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ def resolve(self, allow_lazyness: bool = True) -> Union[Property, None]:
7979
if not self._resolved:
8080
schemas = LazyReferencePropertyProxy.__GLOBAL_SCHEMAS_REF
8181
class_name = self._reference.class_name
82-
if schemas:
83-
existing = schemas.enums.get(class_name) or schemas.models.get(class_name)
84-
if existing:
85-
self._resolved = attr.evolve(existing, required=self._required, name=self._name)
82+
existing = schemas.enums.get(class_name) or schemas.models.get(class_name)
83+
if existing:
84+
self._resolved = attr.evolve(existing, required=self._required, name=self._name)
8685

8786
if self._resolved:
8887
return self._resolved
@@ -524,7 +523,10 @@ def _property_from_data(
524523
schemas,
525524
)
526525
else:
527-
return cast(Property, LazyReferencePropertyProxy.create(name, required, data, parent_name)), schemas
526+
if Reference.from_ref(f"#{parent_name}").class_name == reference.class_name:
527+
return cast(Property, LazyReferencePropertyProxy.create(name, required, data, parent_name)), schemas
528+
else:
529+
return PropertyError(data=data, detail="Could not find reference in parsed models or enums."), schemas
528530

529531
if data.enum:
530532
return build_enum_property(
@@ -701,15 +703,15 @@ def build_schemas(*, components: Dict[str, Union[oai.Reference, oai.Schema]]) ->
701703
errors.append(schemas_or_err)
702704
else:
703705
schemas = schemas_or_err
704-
processing = True # We made some progress this round, do another after it's donea
706+
processing = True # We made some progress this round, do another after it's done
705707

706708
to_process = next_round
707709

708-
for name, reference in references_to_process:
709-
schemas_or_err = resolve_reference_and_update_schemas(name, reference, schemas, references_by_name)
710+
for name, reference in references_to_process:
711+
schemas_or_err = resolve_reference_and_update_schemas(name, reference, schemas, references_by_name)
710712

711-
if isinstance(schemas_or_err, PropertyError):
712-
errors.append(schemas_or_err)
713+
if isinstance(schemas_or_err, PropertyError):
714+
errors.append(schemas_or_err)
713715

714716
schemas.errors.extend(errors)
715717
LazyReferencePropertyProxy.update_schemas(schemas)

0 commit comments

Comments
 (0)