-
-
Notifications
You must be signed in to change notification settings - Fork 227
feat: Add allOf support for model definitions (#98) #321
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
Collapses the child elements into one, without class heirarchy, mixins, etc.
Codecov Report
@@ Coverage Diff @@
## main #321 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 1421 1478 +57
=========================================
+ Hits 1421 1478 +57
Continue to review full report at Codecov.
|
This PR is obviously still missing a bit of coverage and needs to be synced with main, but I'll wait on a response from the Benchling folks before putting any more effort into this branch. CC @packyg as well since I believe they did the original implementation in the fork. |
Interested to hear what @packyg and @forest-benchling think about this :) If it's just a matter of porting comments from #312 and syncing with main, I can contribute that. This feature will be great to have. |
required_properties.extend(sub_model.required_properties) | ||
optional_properties.extend(sub_model.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.
I think you need to account for a situation where one of the children of allOf
specify a property as required and one does not (in which case should make it should be required)
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.
Yeah you're right. I think attrs will implement __eq__
and maybe even __hash__
so we can remove any optional properties from the required properties list. I think we can also get duplicate properties with the current implementation.
What do you think we should do if two properties of the same name are defined but not the same? Return an error, right?
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.
Depends on why they're not the same, I think. If there are things in direct conflict (like different type
s) then error. But if it's one has it required, the other optional, then just make it required.
Different sub-properties in 2 different model props could also probably error
@dbanty This is much cleaner actually. I'm definitely not dogmatic about the implementation we did so definitely could get behind this. cc @bowenwr @dtkav @forest-benchling I hadn't looked closely enough at We had actually implemented our original version of this before the big refactor in #236/ |
Sorry for the delay, this looks good to me. Thanks for implementing it. My only question is, why did the generated code for |
817a79e
to
772dc24
Compare
Because the schema for AModel actually had several allOfs in it already, they just weren't being used 😅. The JSON was originally copied from a FastAPI app so I guess it had included some and I never noticed we were missing the functionality. |
Alright, I think I fixed the issues pointed out above and finished test coverage so in theory this code is ready to go after some reviews. Highlights
Expected behaviors
CC @packyg , @emann , @kalzoo , and @forest-benchling if any of y'all want to take another look at this. |
👍 No need to block on me, changes sound good! |
I'm gonna move this forward so it's not sitting around forever and include it in the new release (since there are other changes I want to get out). |
@bowenwr I attempted to implement what I was talking about in my review of #312 . I just cloned that branch and made the changes, so in theory they are based on top of your existing work and could be backported to your fork? Let me know if there's a problem with this implementation or you disagree that it's simpler.