From 61b5dd987e6b84bc563b3dc7f2ad1a48d3c16a85 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Fri, 23 Apr 2021 13:00:20 +0200 Subject: [PATCH] reproduce failing to load JSON refs in non-openapi document (#314) --- openapi3/swagger_loader_outside_refs_test.go | 20 +++++++++++++ .../testdata/303bis/common/properties.yaml | 16 +++++++++++ openapi3/testdata/303bis/service.yaml | 28 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 openapi3/swagger_loader_outside_refs_test.go create mode 100644 openapi3/testdata/303bis/common/properties.yaml create mode 100644 openapi3/testdata/303bis/service.yaml diff --git a/openapi3/swagger_loader_outside_refs_test.go b/openapi3/swagger_loader_outside_refs_test.go new file mode 100644 index 000000000..1a5cb1c62 --- /dev/null +++ b/openapi3/swagger_loader_outside_refs_test.go @@ -0,0 +1,20 @@ +package openapi3 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestLoadOutsideRefs(t *testing.T) { + loader := NewSwaggerLoader() + loader.IsExternalRefsAllowed = true + doc, err := loader.LoadSwaggerFromFile("testdata/303bis/service.yaml") + require.NoError(t, err) + require.NotNil(t, doc) + + err = doc.Validate(loader.Context) + require.NoError(t, err) + + require.Equal(t, "string", doc.Paths["/service"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Items.Value.AllOf[0].Value.Properties["created_at"].Value.Type) +} diff --git a/openapi3/testdata/303bis/common/properties.yaml b/openapi3/testdata/303bis/common/properties.yaml new file mode 100644 index 000000000..e5b6cdb46 --- /dev/null +++ b/openapi3/testdata/303bis/common/properties.yaml @@ -0,0 +1,16 @@ +timestamp: + type: string + description: Date and time in ISO 8601 format. + example: "2020-04-09T18:14:30Z" + readOnly: true + nullable: true + +timestamps: + type: object + properties: + created_at: + $ref: "#/timestamp" + deleted_at: + $ref: "#/timestamp" + updated_at: + $ref: "#/timestamp" diff --git a/openapi3/testdata/303bis/service.yaml b/openapi3/testdata/303bis/service.yaml new file mode 100644 index 000000000..39dd06639 --- /dev/null +++ b/openapi3/testdata/303bis/service.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.0 +info: + title: 'some service spec' + version: 1.2.3 + +paths: + /service: + get: + tags: + - services/service + summary: List services + description: List services. + operationId: list-services + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/model_service" + +components: + schemas: + model_service: + allOf: + - $ref: "common/properties.yaml#/timestamps"