Issue
BundleBytesComposed no longer hoists JSON $ref targets into components/schemas. It looks like it's started from 0.33.1 onwards (I noticed test failures when doing a bump and dug into it)
Repro
Tiny openapi spec with a User schema, the Go code simply prints the bundled spec.
Try swapping $ref: "User.json" for $ref: "User.yaml" and you should see the yaml one get correctly hoisted into components, while the JSON one does not.
main.go
package main
import (
"fmt"
"os"
"github.com/pb33f/libopenapi/bundler"
"github.com/pb33f/libopenapi/datamodel"
)
func main() {
specBytes, err := os.ReadFile("openapi.yaml")
if err != nil {
panic(err)
}
out, err := bundler.BundleBytesComposed(specBytes, &datamodel.DocumentConfiguration{
AllowFileReferences: true,
BasePath: ".",
SpecFilePath: "openapi.yaml",
}, &bundler.BundleCompositionConfig{
StrictValidation: true,
})
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
openapi.yaml
openapi: 3.0.3
info:
title: t
version: '1'
paths:
/x:
get:
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: "User.json" # <- Swap this for User.yaml and magically components/schemas starts to work
User.json
{
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
User.yaml
type: object
properties:
id:
type: string
Digging
I think it has something to do with this bit:
|
// Skip quoted keys - they should not be treated as OpenAPI keywords |
|
if keyNode.Style == yaml.SingleQuotedStyle || keyNode.Style == yaml.DoubleQuotedStyle { |
|
continue |
My guess is that JSON keys (because they are obviously quoted) get parsed here as yaml.DoubleQuotedStyle and are therefore skipped?
Issue
BundleBytesComposedno longer hoists JSON$reftargets intocomponents/schemas. It looks like it's started from0.33.1onwards (I noticed test failures when doing a bump and dug into it)Repro
Tiny openapi spec with a
Userschema, the Go code simply prints the bundled spec.Try swapping
$ref: "User.json"for$ref: "User.yaml"and you should see the yaml one get correctly hoisted into components, while the JSON one does not.main.goopenapi.yamlUser.json{ "type": "object", "properties": { "id": { "type": "string" } } }User.yamlDigging
I think it has something to do with this bit:
libopenapi/bundler/detect_type.go
Lines 165 to 167 in e15ee6d
My guess is that JSON keys (because they are obviously quoted) get parsed here as
yaml.DoubleQuotedStyleand are therefore skipped?