-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Don't generate extra models for allOf
of one model BNCH-20256
#44
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
cc @stepzhou |
cc @dtkav |
This is great! Thank you for looking into this - one of our main outstanding spectral errors (openapi linter) is: |
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.
Just confirming that given something like:
allOf:
- $ref/MyModel
- properties:
Would still generate a new model name since it's not just the ref?
Based on this it seems like it applies only if there is a single child that's 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.
A lot of changes in e2e tests that I'm not sure about, but looking at the spec for these I guess yeah they're a single model under an allOf
In general I agree with the idea here. I actually think it could be taken a step further, where only changes to the properties trigger a new model.
Ideally the following schema would generate a model where ParentModel.a_prop
is an instance of OtherModel
, not a new ParentModelAProp
model, since the description
and example
are superfluous for code generation.
ParentModel:
type: object
properties:
a_prop:
allOf:
- $ref: "#/components/schemas/OtherModel"
- description: A property holding another model
example:
id: id_str
OtherModel:
type: object
properties:
id:
type: string
@packyg Sorry for the long delay, I'm finally working on upstreaming this. In your example, wouldn't we want
|
@forest-benchling That should be effectively the same, I would think |
Upstream already merged |
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
.I haven't submitted this upstream as we are using it for
allOf
, which has not yet been upstreamed, but we should upstream it together with theallOf
work.This PR will also be a breaking change for the
benchling-api-client
interface, and may requirebenchling-sdk
to be updated accordingly.