Skip to content

fix: Fix bug parsing allOf in nested keys BNCH-20174 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ def build_model_property(

for key, value in all_props.items():
prop_required = key in required_set
if not isinstance(value, oai.Reference) and value.allOf:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I remember this being important for some reason..
I think removing this might inlines all references rather than referencing them as objects.
You might have more context at this point though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtkav Can you clarify what you mean that it might inline all references?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generated the benchling client with both branches, and I think this is actually fine.
I was just trying (but failing) to remember the context around the "resolved later" comment.

It look like your PR generates 40 additional models which seem to correspond to actual missing functionality. 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a refactor upstream which I adapted the initial allOf implementation for. I think I shouldn't have included this there.
In that refactor, he changed the way property_from_data works such that it resolves references to models it has already built instead of returning a RefProperty that gets resolved later.

# resolved later
continue
prop, schemas = property_from_data(
name=key, required=prop_required, data=value, schemas=schemas, parent_name=class_name
)
Expand Down Expand Up @@ -463,9 +460,6 @@ def _property_from_data(
)
if data.anyOf or data.oneOf:
return build_union_property(data=data, name=name, required=required, schemas=schemas, parent_name=parent_name)
if not data.type:
return NoneProperty(name=name, required=required, nullable=False, default=None), schemas

if data.type == "string":
return _string_based_property(name=name, required=required, data=data), schemas
elif data.type == "number":
Expand Down Expand Up @@ -500,8 +494,10 @@ def _property_from_data(
)
elif data.type == "array":
return build_list_property(data=data, name=name, required=required, schemas=schemas, parent_name=parent_name)
elif data.type == "object":
elif data.type == "object" or data.allOf:
return build_model_property(data=data, name=name, schemas=schemas, required=required, parent_name=parent_name)
elif not data.type:
return NoneProperty(name=name, required=required, nullable=False, default=None), schemas
return PropertyError(data=data, detail=f"unknown type {data.type}"), schemas


Expand Down
Loading