diff --git a/openapi3/internalize_refs.go b/openapi3/internalize_refs.go index e313e5535..191c14f7e 100644 --- a/openapi3/internalize_refs.go +++ b/openapi3/internalize_refs.go @@ -351,7 +351,10 @@ func (doc *T) derefPaths(paths map[string]*PathItem, refNameResolver RefNameReso ops.Ref = "" for _, param := range ops.Parameters { - doc.addParameterToSpec(param, refNameResolver, pathIsExternal) + isExternal := doc.addParameterToSpec(param, refNameResolver, pathIsExternal) + if param.Value != nil { + doc.derefParameter(*param.Value, refNameResolver, pathIsExternal || isExternal) + } } for _, op := range ops.Operations() { diff --git a/openapi3/internalize_refs_test.go b/openapi3/internalize_refs_test.go index b5ceb6905..90e73f234 100644 --- a/openapi3/internalize_refs_test.go +++ b/openapi3/internalize_refs_test.go @@ -23,6 +23,7 @@ func TestInternalizeRefs(t *testing.T) { {"testdata/spec.yaml"}, {"testdata/callbacks.yml"}, {"testdata/issue831/testref.internalizepath.openapi.yml"}, + {"testdata/issue959/openapi.yml"}, } for _, test := range tests { diff --git a/openapi3/testdata/issue959/components.yml b/openapi3/testdata/issue959/components.yml new file mode 100644 index 000000000..c7095e90d --- /dev/null +++ b/openapi3/testdata/issue959/components.yml @@ -0,0 +1,4 @@ +components: + schemas: + External1: + type: string \ No newline at end of file diff --git a/openapi3/testdata/issue959/openapi.yml b/openapi3/testdata/issue959/openapi.yml new file mode 100644 index 000000000..de5bbfe48 --- /dev/null +++ b/openapi3/testdata/issue959/openapi.yml @@ -0,0 +1,16 @@ +openapi: 3.0.0 +info: + title: foo + version: 0.0.0 +paths: + /{external1}: + parameters: + - in: path + name: external1 + required: true + schema: + $ref: './components.yml#/components/schemas/External1' + get: + responses: + '204': + description: No content \ No newline at end of file diff --git a/openapi3/testdata/issue959/openapi.yml.internalized.yml b/openapi3/testdata/issue959/openapi.yml.internalized.yml new file mode 100644 index 000000000..3cbe674d6 --- /dev/null +++ b/openapi3/testdata/issue959/openapi.yml.internalized.yml @@ -0,0 +1,35 @@ +{ + "components": { + "schemas": { + "External1": { + "type": "string" + } + } + }, + "info": { + "title": "foo", + "version": "0.0.0" + }, + "openapi": "3.0.0", + "paths": { + "/{external1}": { + "get": { + "responses": { + "204": { + "description": "No content" + } + } + }, + "parameters": [ + { + "in": "path", + "name": "external1", + "required": true, + "schema": { + "$ref": "#/components/schemas/External1" + } + } + ] + } + } +} \ No newline at end of file