-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Change OpenAPI code generator to extract request objects #14217
Conversation
sdk/framework/backend.go
Outdated
// the plugin is enabled (mounted). If specified in the request, the type | ||
// will be used as part of the request/response body names in the OAS | ||
// document | ||
var requestResponsePrefix 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.
Is there a possibility of this variable staying as an empty string? And if so will that cause any problems with the spec generation?
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.
Yes, it is possible if whoever calls the plugin's /help endpoint does not specify the "requestResponsePrefix". In this case, the generated request name will be missing that prefix. For example "KvLookupRequest" would be replaced with just "LookupRequest". I'm not really sure what the best way of dealing with this is (or if it should be of concern). In the OpenAPI generation workflow, the prefix will always be set.
@@ -32,6 +32,9 @@ func NewOASDocument() *OASDocument { | |||
}, | |||
}, | |||
Paths: make(map[string]*OASPathItem), | |||
Components: OASComponents{ | |||
Schemas: make(map[string]*OASSchema), |
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.
Good job utilizing this more modern OAS concept! (reference schema components)
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.
Small typo in a comment but otherwise it looks good to me, good job thinking through how best to get the mount type in there.
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.
This looks good to me! I briefly walked through the API Explorer in the FE and that also seems to be happy with your changes. 🎉
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.
LGTM. Does the generated doc still pass the swagger.io inspector OK?
Yes, tested it in swagger.io 👍 |
)" This reverts commit dcb5942.
Current generated OpenAPI json
The current generated spec has request bodies anonymously defined inline:
New generated OpenAPI spec:
The new generated spec has the request bodies extracted out under
/components/schemas
and referenced with$ref
tags. The advantage of this style is that the spec can now be used for code generation. The generated request structs will have human-readable names (e.g.KvLookupRequest
in the example below):Implementation
The struct schemas are extracted individually for each plugin in
openapi.go
and then combined invault/logical_system.go
. Since the plugins don't have names (types) associated with them until they are mounted, we pass the plugin name to each plugin through its help endpoint within the "data" map.