forked from getkin/kin-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4db1312
commit 2802ca3
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 |