From 7ef72a60b581acf4e5729c7b2b6026909f60cf7c Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Fri, 8 Dec 2023 13:16:53 +0100 Subject: [PATCH] repro #883 Signed-off-by: Pierre Fenoll --- openapi3/issue883_test.go | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 openapi3/issue883_test.go diff --git a/openapi3/issue883_test.go b/openapi3/issue883_test.go new file mode 100644 index 000000000..bb4c4ea59 --- /dev/null +++ b/openapi3/issue883_test.go @@ -0,0 +1,61 @@ +package openapi3_test + +import ( + "testing" + + "github.com/invopop/yaml" + "github.com/stretchr/testify/require" + + "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: {} +components: + schemas: + Kitten: + type: string +`[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) + + marshalledJson, err := doc.MarshalJSON() + require.NoError(t, err) + require.JSONEq(t, `{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "license": {"name": "MIT"} + }, + "servers": [{"url": "http://petstore.swagger.io/v1"}], + "paths": {}, + "components": { + "schemas": { + "Kitten": {"type": "string"} + } + } +}`, string(marshalledJson)) + require.NotNil(t, doc.Paths) + + marshalledYaml, err := yaml.Marshal(&doc) + require.NoError(t, err) + require.YAMLEq(t, spec, string(marshalledYaml)) + require.NotNil(t, doc.Paths) +}