From a55022d573eb4d15307fe86c9fe24297f24baf59 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Thu, 13 Oct 2022 17:56:19 +0200 Subject: [PATCH] reproduce issue #618 Signed-off-by: Pierre Fenoll --- openapi3/issue618_test.go | 41 ++++++++++++++++++++++ openapi3/testdata/schema618.yml | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 openapi3/issue618_test.go create mode 100644 openapi3/testdata/schema618.yml diff --git a/openapi3/issue618_test.go b/openapi3/issue618_test.go new file mode 100644 index 000000000..84d943c9e --- /dev/null +++ b/openapi3/issue618_test.go @@ -0,0 +1,41 @@ +package openapi3 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIssue618(t *testing.T) { + spec := ` +openapi: 3.0.0 +info: + title: foo + version: 0.0.0 +paths: + /foo: + get: + responses: + '200': + description: Some description value text + content: + application/json: + schema: + $ref: ./testdata/schema618.yml#/components/schemas/JournalEntry +`[1:] + + loader := NewLoader() + loader.IsExternalRefsAllowed = true + ctx := loader.Context + + doc, err := loader.LoadFromData([]byte(spec)) + require.NoError(t, err) + + doc.InternalizeRefs(ctx, nil) + + t.Logf(">>> %+v", doc.Components.Schemas) + + require.Contains(t, doc.Components.Schemas, "JournalEntry") + require.Contains(t, doc.Components.Schemas, "Record") + require.Contains(t, doc.Components.Schemas, "Account") +} diff --git a/openapi3/testdata/schema618.yml b/openapi3/testdata/schema618.yml new file mode 100644 index 000000000..1ab400075 --- /dev/null +++ b/openapi3/testdata/schema618.yml @@ -0,0 +1,62 @@ +components: + schemas: + Account: + required: + - name + - nature + type: object + properties: + id: + type: string + name: + type: string + description: + type: string + type: + type: string + enum: + - assets + - liabilities + nature: + type: string + enum: + - asset + - liability + Record: + required: + - account + - concept + type: object + properties: + account: + $ref: "#/components/schemas/Account" + concept: + type: string + partial: + type: number + credit: + type: number + debit: + type: number + JournalEntry: + required: + - type + - creationDate + - records + type: object + properties: + id: + type: string + type: + type: string + enum: + - daily + - ingress + - egress + creationDate: + type: string + format: date + records: + type: array + items: + $ref: "#/components/schemas/Record"