Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi3: internalize refs for path parameters #960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openapi3/internalize_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions openapi3/internalize_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions openapi3/testdata/issue959/components.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components:
schemas:
External1:
type: string
16 changes: 16 additions & 0 deletions openapi3/testdata/issue959/openapi.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions openapi3/testdata/issue959/openapi.yml.internalized.yml
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
}
}
Loading