-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3: Implement YAML Marshaler interface for AdditionalProperties (…
- Loading branch information
1 parent
05453ef
commit 7f46bdf
Showing
4 changed files
with
74 additions
and
0 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,40 @@ | ||
package openapi3_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
) | ||
|
||
func TestMarshalAdditionalProperties(t *testing.T) { | ||
ctx := context.Background() | ||
data, err := os.ReadFile("testdata/test.openapi.additionalproperties.yml") | ||
require.NoError(t, err) | ||
|
||
loader := openapi3.NewLoader() | ||
loader.IsExternalRefsAllowed = true | ||
spec, err := loader.LoadFromData(data) | ||
require.NoError(t, err) | ||
|
||
err = spec.Validate(ctx) | ||
require.NoError(t, err) | ||
|
||
var buf bytes.Buffer | ||
enc := yaml.NewEncoder(&buf) | ||
enc.SetIndent(2) | ||
err = enc.Encode(spec) | ||
require.NoError(t, err) | ||
|
||
// Load the doc from the serialized yaml. | ||
spec2, err := loader.LoadFromData(buf.Bytes()) | ||
require.NoError(t, err) | ||
|
||
err = spec2.Validate(ctx) | ||
require.NoError(t, err) | ||
} |
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,17 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: "OAI Specification in YAML" | ||
version: 0.0.1 | ||
paths: {} | ||
components: | ||
schemas: | ||
TestSchema: | ||
type: object | ||
additionalProperties: | ||
type: array | ||
items: | ||
type: string | ||
TestSchema2: | ||
type: object | ||
additionalProperties: | ||
type: string |