From b36729db85d3b9affa724af5cd310bfc0378b9fb Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Tue, 2 Mar 2021 17:26:27 +0100 Subject: [PATCH 1/2] reproduce https://github.com/getkin/kin-openapi/issues/303#issuecomment-786521697 Signed-off-by: Pierre Fenoll --- openapi3/swagger_loader_outside_refs_test.go | 22 +++++++++++++++ .../testdata/303bis/common/properties.yaml | 16 +++++++++++ openapi3/testdata/303bis/service.yaml | 28 +++++++++++++++++++ 3 files changed, 66 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..67b795d1b --- /dev/null +++ b/openapi3/swagger_loader_outside_refs_test.go @@ -0,0 +1,22 @@ +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) + + props := doc.Paths["/service"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Items.Value.Properties + require.NotNil(t, props) + require.Equal(t, "string", props["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" From 6ca798b46bbbc4f3320cf2a1e47d1f748b2f286e Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Fri, 23 Apr 2021 12:57:59 +0200 Subject: [PATCH 2/2] that test was wrong Signed-off-by: Pierre Fenoll --- openapi3/swagger_loader_outside_refs_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openapi3/swagger_loader_outside_refs_test.go b/openapi3/swagger_loader_outside_refs_test.go index 67b795d1b..1a5cb1c62 100644 --- a/openapi3/swagger_loader_outside_refs_test.go +++ b/openapi3/swagger_loader_outside_refs_test.go @@ -16,7 +16,5 @@ func TestLoadOutsideRefs(t *testing.T) { err = doc.Validate(loader.Context) require.NoError(t, err) - props := doc.Paths["/service"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Items.Value.Properties - require.NotNil(t, props) - require.Equal(t, "string", props["created_at"].Value.Type) + 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) }