-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: openapi2conv respects produces field (#575)
- Loading branch information
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package openapi2conv | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIssue573(t *testing.T) { | ||
spec := []byte(`paths: | ||
/ping: | ||
get: | ||
produces: | ||
- application/toml | ||
- application/xml | ||
responses: | ||
200: | ||
schema: | ||
type: object | ||
properties: | ||
username: | ||
type: string | ||
description: The user name. | ||
post: | ||
responses: | ||
200: | ||
schema: | ||
type: object | ||
properties: | ||
username: | ||
type: string | ||
description: The user name.`) | ||
|
||
v3, err := v2v3YAML(spec) | ||
require.NoError(t, err) | ||
|
||
// Make sure the response content appears for each mime-type originally | ||
// appeared in "produces". | ||
pingGetContent := v3.Paths["/ping"].Get.Responses["200"].Value.Content | ||
require.Len(t, pingGetContent, 2) | ||
require.Contains(t, pingGetContent, "application/toml") | ||
require.Contains(t, pingGetContent, "application/xml") | ||
|
||
// Is "produces" is not explicitly specified, default to "application/json". | ||
pingPostContent := v3.Paths["/ping"].Post.Responses["200"].Value.Content | ||
require.Len(t, pingPostContent, 1) | ||
require.Contains(t, pingPostContent, "application/json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters