-
-
Notifications
You must be signed in to change notification settings - Fork 227
Don't generate extra models for allOf
, oneOf
, or anyOf
of one model
#361
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
Codecov Report
@@ Coverage Diff @@
## main #361 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 1478 1483 +5
=========================================
+ Hits 1478 1483 +5
Continue to review full report at Codecov.
|
@dbanty How do you want to do the commit message for this? I feel like doing a |
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.
Great, thanks for putting this together! This will fix a bug that just got reported as well, which is awesome. I have a few changes to request, then we're good to go!
@@ -0,0 +1,154 @@ | |||
from typing import Optional |
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.
The main branch no longer has golden-record-custom
. I removed the full generation there since it was redundant and we really just needed to test that a custom template would be applied. So these files can be removed
if not isinstance(json_nullable_model_prop, Unset) and json_nullable_model_prop is not None: | ||
params.update(json_nullable_model_prop) | ||
if json_nullable_required_model_prop is not None: | ||
params.update(json_nullable_required_model_prop) |
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 this is the right call, it matches the intended default of style=query,explode=true
, but it is a breaking change we'll have to remember to note.
for attribute in ["allOf", "anyOf", "oneOf"]: | ||
sub_data = getattr(data, attribute) | ||
if sub_data and len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference): | ||
return _property_from_ref( | ||
name=name, required=required, nullable=data.nullable, data=sub_data[0], schemas=schemas | ||
) |
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 don't think there's anything illegal about having more than one of those properties, so we only want to do the pass through if only 1 ref exists in all of those properties. So something like:
for attribute in ["allOf", "anyOf", "oneOf"]: | |
sub_data = getattr(data, attribute) | |
if sub_data and len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference): | |
return _property_from_ref( | |
name=name, required=required, nullable=data.nullable, data=sub_data[0], schemas=schemas | |
) | |
sub_data = (data.allOf or []) + data.anyOf + data.oneOf | |
if len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference): | |
return _property_from_ref( | |
name=name, required=required, nullable=data.nullable, data=sub_data[0], schemas=schemas | |
) |
This also means no getattr
so we get better type checking!
@emann this is also fixing the issue for oneOf and anyOf so I think fix: is the right call. Although it will be |
Also noting that it is a breaking change because people may be depending on the models that are getting removed by this PR (Benchling certainly is) |
Currently, we have tons of places where we do something like
which causes an unnecessary model
AaSequenceCustomFields
to be generated, rather than directly referencing the existingCustomFields
model.The OpenAPI 3.1 spec is going to add support for direct sibling properties:
But since that may be a long ways away, we directly implement a workaround in this PR.
This workaround also applies for
oneOf
andanyOf
.