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

Swagger v2 to v3 conversion #113

Closed
eclipse1985 opened this issue Aug 30, 2019 · 5 comments
Closed

Swagger v2 to v3 conversion #113

eclipse1985 opened this issue Aug 30, 2019 · 5 comments

Comments

@eclipse1985
Copy link

eclipse1985 commented Aug 30, 2019

In the README is stated that openapi2 package supports

OpenAPI 2 files, including serialization, deserialization, and validation

But I can't find a way to read a swagger v2 file.

I need to convert a swagger v2 file to swagger v3. Is that possible in any way with kin-openapi ?

@dinusha92
Copy link

I have a similar requirement. @eclipse1985 were you able to achieve this? :)

@eclipse1985
Copy link
Author

Unfortunately no

@tschaub
Copy link
Contributor

tschaub commented Nov 3, 2019

@eclipse1985 @dinusha92 - assuming you have read your v2 spec as []byte, you can use a function like this to convert to v3:

func V2ToV3(v2Data []byte) ([]byte, error) {
	v2Spec := &openapi2.Swagger{}
	if err := json.Unmarshal(v2Data, v2Spec); err != nil {
		return nil, err
	}

	v3Spec, err := openapi2conv.ToV3Swagger(v2Spec)
	if err != nil {
		return nil, err
	}

	return json.Marshal(v3Spec)
}

@eclipse1985
Copy link
Author

Yes, I just tried, and you are right. We can close this issue.

@OneCricketeer
Copy link

Could this be a CLI command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants