-
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
Conversation
allOf in nested keys BNCH-20174
|
cc @bowenwr |
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.
@forest-benchling In scope of this how would you feel about fixing another issue with allOf that is blocking moving forward with the SDK?
Specifically that given this parameter in AaSequenceUpdate definition:
fields:
allOf:
- $ref: "#/components/schemas/Fields"
- description: >
Fields to set on the AA sequence. Must correspond with the schema's field definitions.
Every field should have its name as a key, mapping to an object with information about the value of
the field.We generate a field definition like:
fields: Union[Unset, AaSequenceBaseRequestFields] = UNSETWhereas we want to generate:
fields: Union[Unset, Fields] = UNSETThe key to this is setting additionalProperties: false which would ideally be part of the allOf definition but setting it there has no effect in our current implementations.
If we corrected the spec to read:
AaSequenceUpdate:
allOf:
- "$ref": "#/components/schemas/AaSequenceBaseRequest"
- "$ref": "#/components/schemas/AaSequenceRequestAuthorIds"
- "$ref": "#/components/schemas/AaSequenceRequestRegistryFields"
- additionalProperties: falseI'd want it to work as specified above.
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.
LGMT, though you should revert poetry.lock - we should keep in line with upstream dependencies.
|
@bowenwr it seems like you are getting at 2 distinct issues:
I think the first point is less critical - we can comment out the description part for now, use the Either way, we should keep this PR's scope as-is and follow up in a separate PR for any more changes. |
|
After we merge this, we may want to do some massaging of the git history and squash this into the original Or we could do that next time we rebase from upstream and cut a |
| assert all(not p.required for p in model.optional_properties) | ||
|
|
||
| key_property = model.optional_properties[0] | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Currently fails with
> assert sorted(p.name for p in key_property.required_properties) == ["DateTime", "Float", "String"]
E AssertionError: assert ['Float'] == ['DateTime', ...at', 'String']
E At index 0 diff: 'Float' != 'DateTime'
E Right contains 2 more items, first extra item: 'Float'
E Use -v to get the full diff
I can't figure out why.
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.
@forest-benchling I think this is because you only resolved references on the parent model, not on the key_property.
This should work if you do
| assert sorted(p.name for p in key_property.required_properties) == ["DateTime", "Float", "String"] | |
| 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"] |
When you actually run the code generator, all models are resolved in build_schemas but we don't use that code path here.
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.
wooo thanks @packyg
|
|
||
| for key, value in all_props.items(): | ||
| prop_required = key in required_set | ||
| if not isinstance(value, oai.Reference) and value.allOf: |
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 a RefProperty that gets resolved later.
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.
👍
Description
Our code was not correctly generating models where
allOfwas done on a nested key, such asNotFoundError:The generated model has no
errorproperty.This bug also affects
ContainerContent,Folder,AssayRunSchema,AssayRequestSchema, and potentially more.This PR tries to fix the bug by changing
_property_from_dataandbuild_model_property.Test Plan
poetry run task checkpoetry run task reopenapi-specssubmodule and rebuilt the client. Got these classes: