Skip to content
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

Merged
merged 1 commit into from
Mar 28, 2022
Merged

Conversation

Jefftree
Copy link
Member

@Jefftree Jefftree commented Mar 22, 2022

  • 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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 22, 2022
@k8s-ci-robot k8s-ci-robot requested review from roycaihw and sttts March 22, 2022 03:44
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 22, 2022
@Jefftree Jefftree force-pushed the v2v3conv branch 2 times, most recently from 4515942 to 6ebf5ca Compare March 22, 2022 23:30
@Jefftree
Copy link
Member Author

/cc @alexzielenski @jiahuif @apelisse

@k8s-ci-robot k8s-ci-robot requested a review from jiahuif March 22, 2022 23:34
@k8s-ci-robot
Copy link
Contributor

@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:

/cc @alexzielenski @jiahuif @apelisse

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.

@k8s-ci-robot k8s-ci-robot requested a review from apelisse March 22, 2022 23:34
@Jefftree Jefftree changed the title Add OpenAPI V2 to V3 Converter [WIP] Add OpenAPI V2 to V3 Converter Mar 23, 2022
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 23, 2022
pkg/builder3/openapi.go Show resolved Hide resolved
pkg/builder3/openapi.go Show resolved Hide resolved
@@ -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),
Copy link
Contributor

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?

Copy link
Member Author

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.

pkg/builder3/openapi.go Show resolved Hide resolved
pkg/openapiconv/convert.go Show resolved Hide resolved
pkg/openapiconv/convert.go Show resolved Hide resolved
pkg/openapiconv/convert.go Show resolved Hide resolved
pkg/openapiconv/convert.go Outdated Show resolved Hide resolved
pkg/openapiconv/convert.go Outdated Show resolved Hide resolved
test/integration/openapiconv/convert_test.go Show resolved Hide resolved
@Jefftree
Copy link
Member Author

/cc @sttts

pkg/builder3/openapi.go Show resolved Hide resolved
pkg/common/common.go Show resolved Hide resolved
test/integration/openapiconv/convert_test.go Outdated Show resolved Hide resolved
test/integration/openapiconv/convert_test.go Show resolved Hide resolved
pkg/openapiconv/convert.go Outdated Show resolved Hide resolved
pkg/openapiconv/convert.go Outdated Show resolved Hide resolved
@Jefftree Jefftree changed the title [WIP] Add OpenAPI V2 to V3 Converter Add OpenAPI V2 to V3 Converter Mar 24, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 24, 2022
@Jefftree Jefftree force-pushed the v2v3conv branch 3 times, most recently from a5c6ebb to c680601 Compare March 24, 2022 15:55
@Jefftree Jefftree force-pushed the v2v3conv branch 2 times, most recently from e0d9f07 to 7d73b45 Compare March 26, 2022 03:51
@Jefftree
Copy link
Member Author

/retest
hm, the tests all pass locally

@Jefftree Jefftree force-pushed the v2v3conv branch 3 times, most recently from 28f39c4 to 0c9bc77 Compare March 26, 2022 20:16
Comment on lines 108 to 111
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))
}
}
Copy link
Member

@apelisse apelisse Mar 26, 2022

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.
}

Copy link
Member Author

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.

Copy link
Member

@apelisse apelisse left a 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?

@apelisse
Copy link
Member

apelisse commented Mar 27, 2022

Feel free to squash I guess?

@apelisse
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 28, 2022
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 28, 2022
@k8s-ci-robot k8s-ci-robot merged commit 3a31a64 into kubernetes:master Mar 28, 2022
@Jefftree Jefftree deleted the v2v3conv branch March 21, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants