-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
7ef87d5
2a05ca1
637832a
3a90f2b
24a9ce6
c63d42f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -123,3 +123,79 @@ def test_resolve_references(mocker): | |||||||||
assert all(p.required for p in model.required_properties) | ||||||||||
assert sorted(p.name for p in model.optional_properties) == ["Enum", "Int"] | ||||||||||
assert all(not p.required for p in model.optional_properties) | ||||||||||
|
||||||||||
|
||||||||||
def test_resolve_references_nested_allof(mocker): | ||||||||||
import openapi_python_client.schema as oai | ||||||||||
from openapi_python_client.parser.properties import build_model_property | ||||||||||
|
||||||||||
schemas = { | ||||||||||
"RefA": oai.Schema.construct( | ||||||||||
title=mocker.MagicMock(), | ||||||||||
description=mocker.MagicMock(), | ||||||||||
required=["String"], | ||||||||||
properties={ | ||||||||||
"String": oai.Schema.construct(type="string"), | ||||||||||
"Enum": oai.Schema.construct(type="string", enum=["aValue"]), | ||||||||||
"DateTime": oai.Schema.construct(type="string", format="date-time"), | ||||||||||
}, | ||||||||||
), | ||||||||||
"RefB": oai.Schema.construct( | ||||||||||
title=mocker.MagicMock(), | ||||||||||
description=mocker.MagicMock(), | ||||||||||
required=["DateTime"], | ||||||||||
properties={ | ||||||||||
"Int": oai.Schema.construct(type="integer"), | ||||||||||
"DateTime": oai.Schema.construct(type="string", format="date-time"), | ||||||||||
"Float": oai.Schema.construct(type="number", format="float"), | ||||||||||
}, | ||||||||||
), | ||||||||||
# Intentionally no properties defined | ||||||||||
"RefC": oai.Schema.construct( | ||||||||||
title=mocker.MagicMock(), | ||||||||||
description=mocker.MagicMock(), | ||||||||||
), | ||||||||||
} | ||||||||||
|
||||||||||
model_schema = oai.Schema.construct( | ||||||||||
type="object", | ||||||||||
properties={ | ||||||||||
"Key": oai.Schema.construct( | ||||||||||
allOf=[ | ||||||||||
oai.Reference.construct(ref="#/components/schemas/RefA"), | ||||||||||
oai.Reference.construct(ref="#/components/schemas/RefB"), | ||||||||||
oai.Reference.construct(ref="#/components/schemas/RefC"), | ||||||||||
oai.Schema.construct( | ||||||||||
title=mocker.MagicMock(), | ||||||||||
description=mocker.MagicMock(), | ||||||||||
required=["Float"], | ||||||||||
properties={ | ||||||||||
"String": oai.Schema.construct(type="string"), | ||||||||||
"Float": oai.Schema.construct(type="number", format="float"), | ||||||||||
}, | ||||||||||
), | ||||||||||
] | ||||||||||
), | ||||||||||
} | ||||||||||
) | ||||||||||
|
||||||||||
components = {**schemas, "Model": model_schema} | ||||||||||
|
||||||||||
from openapi_python_client.parser.properties import ModelProperty, Schemas | ||||||||||
|
||||||||||
schemas_holder = Schemas() | ||||||||||
model, schemas_holder = build_model_property( | ||||||||||
data=model_schema, name="Model", required=True, schemas=schemas_holder, parent_name=None | ||||||||||
) | ||||||||||
model.resolve_references(components, schemas_holder) | ||||||||||
assert sorted(p.name for p in model.required_properties) == [] | ||||||||||
assert sorted(p.name for p in model.optional_properties) == ["Key"] | ||||||||||
assert all(not p.required for p in model.optional_properties) | ||||||||||
|
||||||||||
key_property = model.optional_properties[0] | ||||||||||
assert isinstance(key_property, ModelProperty) | ||||||||||
key_property.resolve_references(components, schemas_holder) | ||||||||||
assert sorted(p.name for p in key_property.required_properties) == ["DateTime", "Float", "String"] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently fails with
I can't figure out why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @forest-benchling I think this is because you only resolved references on the parent model, not on the This should work if you do
Suggested change
When you actually run the code generator, all models are resolved in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wooo thanks @packyg |
||||||||||
assert all(p.required for p in key_property.required_properties) | ||||||||||
assert sorted(p.name for p in key_property.optional_properties) == ["Enum", "Int"] | ||||||||||
assert all(not p.required for p in key_property.optional_properties) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
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 aRefProperty
that gets resolved later.