kin-openapi
                                
                                
                                
                                    kin-openapi copied to clipboard
                            
                            
                            
                        openapi2conv: v2 Response examples are lost after conversion
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.