Skip to content

Commit

Permalink
openapi3: internalize refs for path parameters (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux authored Jun 10, 2024
1 parent 8d5ee0b commit 43846d5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
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"
}
}
]
}
}
}

0 comments on commit 43846d5

Please sign in to comment.