Hello. Thanks for the wonderful library!
I've been using v0.16.4 for a long time, but upgrading to v0.37.2 broke my code.
When a parameter in components.parameters references an external file via a $ref, the resulting high-level model in Go is malformed. Instead of correctly resolving the reference and populating the parameter's fields (name, in, etc.), nothing is resolved (and, moreover, some obscure structures are placed in examples and content fields)
Related to #501 as it points to essentially the same problem, however the fix was implemented only for bundling.
Steps to Reproduce
- Create following files:
openapi.yaml:
openapi: 3.1.0
components:
parameters:
foo:
$ref: "./list.yaml#/foo"
bar:
in: query
name: bar
schema:
type: integer
required: false
list.yaml:
foo:
name: SomeName
in: path
required: true
schema:
type: string
- Load spec, build document model:
package main
import (
"encoding/json"
"os"
"path"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel"
)
func main() {
filePath := "./openapi.yaml"
config := &datamodel.DocumentConfiguration{
AllowFileReferences: true,
ExtractRefsSequentially: true,
BasePath: path.Dir(filePath),
}
b, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
doc, err := libopenapi.NewDocumentWithConfiguration(b, config)
if err != nil {
panic(err)
}
v3Model, err := doc.BuildV3Model()
if err != nil {
panic(err)
}
data, _ := json.MarshalIndent(v3Model, "", " ")
println(string(data))
}
Expected Behaviour
The parameters section in Model.Components.Parameters should contain a correctly resolved foo parameter
Actual Behaviour
The foo parameter is malformed
...
"parameters": {
"foo": {
"schema": {},
"examples": {
"name": {},
"in": {},
"required": {},
"schema": {}
},
"content": {
"name": {
"examples": {},
"encoding": {}
},
"in": {
"examples": {},
"encoding": {}
},
"required": {
"examples": {},
"encoding": {}
},
"schema": {
"examples": {},
"encoding": {}
}
}
},
"bar": {
"name": "bar",
"in": "query",
"required": false,
"schema": {},
"examples": {},
"content": {}
}
},
...
The same issue also affects the filling of Response objects when they reference external files via $ref.
Used environment:
- go version
1.26.3
- libopenapi version
v0.37.2
References
A complete example for reproduction is available in the repository: https://github.com/sanekkurt/libopenapi-mre
Hello. Thanks for the wonderful library!
I've been using v0.16.4 for a long time, but upgrading to v0.37.2 broke my code.
When a parameter in
components.parametersreferences an external file via a$ref, the resulting high-level model in Go is malformed. Instead of correctly resolving the reference and populating the parameter's fields (name,in, etc.), nothing is resolved (and, moreover, some obscure structures are placed inexamplesandcontentfields)Related to #501 as it points to essentially the same problem, however the fix was implemented only for bundling.
Steps to Reproduce
openapi.yaml:list.yaml:Expected Behaviour
The
parameterssection inModel.Components.Parametersshould contain a correctly resolvedfooparameterActual Behaviour
The
fooparameter is malformedThe same issue also affects the filling of Response objects when they reference external files via $ref.
Used environment:
1.26.3v0.37.2References
A complete example for reproduction is available in the repository: https://github.com/sanekkurt/libopenapi-mre