-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: export input and output schemas to components in OpenAPI document #131
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Enrique Lacal <[email protected]>
// Validate doesn't like references | ||
// so LoadFromData resolves those references | ||
// before we validate | ||
err = doc.Validate(sl.Context) |
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 really like the direction this is going. @EnriqueL8 do you have a small example of two structs that would be problematic with the name conflict you mentioned above? Do we have any that would hit this conflict in use today? |
@nguyer yes, getkin/kin-openapi#914 (comment) I'll check if we have any today in our repositories |
Going to pull this into a Firefly draft branch and see how it behaves! |
That revealed an issue where you get empty names for the schemas so you end up with
Will look into that! |
Oh it fails when the field is for example |
Alright put a fix into the PR in the openapi package! Apart from that all I see is when validating it
Need to check for the duplicate objects problem |
Just documenting as I go... we have this in some paths |
If this PR is consumed by Firefly , then the Node.JS SDK should also be updated with the new OpenAPI |
If just this the problem with the annotations overriding a struct with https://github.com/hyperledger/firefly/blob/577e8c47680c6230209a74829921a9c427766af8/pkg/core/message.go#L76C71-L76C91 and came across |
Actually this will still have the same problem, I wonder if I need to implement a merge instead of replace of component schemas? |
@EnriqueL8 - this seems like an important change. Are you still progressing? I see that getkin/kin-openapi#914 and getkin/kin-openapi#937 got to a conclusion. |
Need to come back to this one and make sure that we do not break existing |
Draft PR until this is merged getkin/kin-openapi#914. Note: the go.mod is pointing to a local version as you cannot reference a fork in go.mod
This PR extends the OpenAPI handler to export the input and output schemas into the OpenAPI components section to reduce the size of the OpenAPI documents generated and reduce duplication.
By default, it will not export generic schemas as such as thing does not exist in the OpenAPI specification as far as I know and will export the top level schema for the route. You can configure the latter to not export it.
There is a point of friction with the
schema customizers
, currently we have two schema customisers that look for the annotationsffexcludeinput
andffexcludeoutput
. The way a schema is added to the Components section is by name of the Golang Struct. If a route or multiple route are defined where the response type is used across both inputs and outputs where we have used the above exclude annotations, then the schema will be overridden by the last route parsed. This is not ideal and the only solution I could think of is to enforce consumers to define two different structs/pojos but this renders the above annotations mostly useless. So any thoughts appreciate!