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

openapi2conv: v2 Response examples are lost after conversion #821

Open
jspdown opened this issue Jul 27, 2023 · 0 comments
Open

openapi2conv: v2 Response examples are lost after conversion #821

jspdown opened this issue Jul 27, 2023 · 0 comments

Comments

@jspdown
Copy link

jspdown commented Jul 27, 2023

When translating v2 spec into v3, the openapi2.Response.examples property is not converted into openapi3.Response.Content[mime].Examples.

Reproducible test case:

func TestToV3Response_Examples(t *testing.T) {
	got, err := openapi2conv.ToV3Response(&openapi2.Response{
		Description: "my response",
		Schema: &openapi3.SchemaRef{
			Value: &openapi3.Schema{
				Type: "object",
			},
		},
		Examples: map[string]interface{}{
			"application/json": `{"status": "ok"}`,
		},
	}, []string{"application/json"})
	require.NoError(t, err)

	assert.Equal(t, &openapi3.ResponseRef{
		Value: &openapi3.Response{
			Description: ptrTo("my response"),
			Content: openapi3.Content{
				"application/json": &openapi3.MediaType{
					Schema: &openapi3.SchemaRef{
						Value: &openapi3.Schema{
							Type: "object",
						},
					},
					Examples: map[string]*openapi3.ExampleRef{
						"example": {
							Value: &openapi3.Example{Value: `{"status": "ok"}`},
						},
					},
				},
			},
		},
	}, got)
}

To fix this issue we should also remove the hard requirement of having a Schema to attempt adding a MediaType to the converted Response. The schema field in v2 is optional. One could be defining examples while not providing a schema.

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

1 participant