-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add OpenAPI V2 to V3 Converter #292
Conversation
Jefftree
commented
Mar 22, 2022
•
edited
Loading
edited
- Use the CommonResponses object in OpenAPI V3 builder. (This adds the 404 Response structs)
- Create a OpenAPIV3Config struct that we can transition to in the future. Currently it is just an upsampling from the v2 Config.
- Add converter from OpenAPI V2 to V3
- Verify converter by generating the OpenAPI v2/v3 from go structs, and attempt to convert v2 to v3 and check for equality.
4515942
to
6ebf5ca
Compare
@Jefftree: GitHub didn't allow me to request PR reviews from the following users: alexzielenski. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@@ -154,18 +165,23 @@ func (o *openAPI) buildRequestBody(parameters []common.Parameter, bodySample int | |||
|
|||
func newOpenAPI(config *common.Config) openAPI { | |||
o := openAPI{ | |||
config: config, | |||
config: common.ConvertConfigToV3(config), |
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 common.Config
meant to be used for both OpenAPIV2 and OpenAPIV3?
I am concerned that over time the OpenAPI v3 config might diverge and no longer be automatically convertible from the common.Config
. It would be painful to switch the API to take a new config type at that point. We are already starting to see differences in how we want to treat GetDefinitionName
of common.Config
in OpenAPI v2 vs v3 (recall kubernetes/kubernetes#106778).
Are we able guarantee to our users the the OpenAPI config will always be automatically convertible from the OpenAPI v2 config?
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.
No, we should have separate configs for OpenAPI V2 and V3. This should apply for structs as well (spec.Info, Schema, etc).
I think making that change would be too big given our current timeline, so as a compromise I'm starting to create the V3 config but generating that from the common Config.
/cc @sttts |
a5c6ebb
to
c680601
Compare
e0d9f07
to
7d73b45
Compare
/retest |
28f39c4
to
0c9bc77
Compare
pkg/openapiconv/convert.go
Outdated
v3Schema.Items = new(spec.SchemaOrArray) | ||
v3Schema.Items.Schema = ConvertSchema(v2Schema.Items.Schema) | ||
if v2Schema.Items.Schemas != nil { | ||
v3Schema.Items.Schemas = []spec.Schema{} | ||
for _, s := range v2Schema.Items.Schemas { | ||
v3Schema.Items.Schemas = append(v3Schema.Items.Schemas, *ConvertSchema(&s)) | ||
} | ||
} |
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.
Not something I specifically want you to change, but you could have written this like:
v3Schema.Items := spec.SchemaOrArray {
Schema: ConvertSchema(v2schema.Items.Schema),
Schemas: ConvertSchemaList(v2.schema.Items.Schemas), // Move the for loop into its own function that does its own nil checks appropriately.
}
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.
You could have just said you want me to change it :)
Updated.
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.
OK Thanks, I'm happy with it. @sttts Do you want to take a look?
Feel free to squash I guess? |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse, Jefftree The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |