-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* repro #883 Signed-off-by: Pierre Fenoll <[email protected]> * try harder Signed-off-by: Pierre Fenoll <[email protected]> * skip yaml unmarshaler for maplike types for now Signed-off-by: Pierre Fenoll <[email protected]> * docs.sh Signed-off-by: Pierre Fenoll <[email protected]> --------- Signed-off-by: Pierre Fenoll <[email protected]>
- Loading branch information
Showing
3 changed files
with
105 additions
and
2 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
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,103 @@ | ||
package openapi3_test | ||
|
||
import ( | ||
"testing" | ||
|
||
invopopYaml "github.com/invopop/yaml" | ||
"github.com/stretchr/testify/require" | ||
v3 "gopkg.in/yaml.v3" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
) | ||
|
||
func TestIssue883(t *testing.T) { | ||
spec := ` | ||
openapi: '3.0.0' | ||
info: | ||
version: '1.0.0' | ||
title: Swagger Petstore | ||
license: | ||
name: MIT | ||
servers: | ||
- url: http://petstore.swagger.io/v1 | ||
paths: | ||
/simple: | ||
get: | ||
summary: A simple GET request | ||
responses: | ||
'200': | ||
description: OK | ||
`[1:] | ||
|
||
sl := openapi3.NewLoader() | ||
doc, err := sl.LoadFromData([]byte(spec)) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
|
||
err = doc.Validate(sl.Context) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
|
||
t.Run("Roundtrip invopop/yaml", func(t *testing.T) { | ||
justPaths, err := invopopYaml.Marshal(doc.Paths) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
require.YAMLEq(t, ` | ||
/simple: | ||
get: | ||
summary: A simple GET request | ||
responses: | ||
'200': | ||
description: OK | ||
`[1:], string(justPaths)) | ||
|
||
marshalledYaml, err := invopopYaml.Marshal(doc) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
require.YAMLEq(t, spec, string(marshalledYaml)) | ||
|
||
var newDoc openapi3.T | ||
err = invopopYaml.Unmarshal(marshalledYaml, &newDoc) | ||
require.NoError(t, err) | ||
require.NotNil(t, newDoc.Paths) | ||
require.Equal(t, doc, &newDoc) | ||
}) | ||
|
||
t.Run("Roundtrip yaml.v3", func(t *testing.T) { | ||
justPaths, err := doc.Paths.MarshalJSON() | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
require.YAMLEq(t, ` | ||
/simple: | ||
get: | ||
summary: A simple GET request | ||
responses: | ||
'200': | ||
description: OK | ||
`[1:], string(justPaths)) | ||
|
||
justPaths, err = v3.Marshal(doc.Paths) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
require.YAMLEq(t, ` | ||
/simple: | ||
get: | ||
summary: A simple GET request | ||
responses: | ||
'200': | ||
description: OK | ||
`[1:], string(justPaths)) | ||
|
||
marshalledYaml, err := v3.Marshal(doc) | ||
require.NoError(t, err) | ||
require.NotNil(t, doc.Paths) | ||
require.YAMLEq(t, spec, string(marshalledYaml)) | ||
|
||
t.Skip("TODO: impl https://pkg.go.dev/gopkg.in/yaml.v3#Unmarshaler on maplike types") | ||
var newDoc openapi3.T | ||
err = v3.Unmarshal(marshalledYaml, &newDoc) | ||
require.NoError(t, err) | ||
require.NotNil(t, newDoc.Paths) | ||
require.Equal(t, doc, &newDoc) | ||
}) | ||
} |
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