Skip to content
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
8 changes: 7 additions & 1 deletion bundler/detect_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func hasPathItemProperties(node *yaml.Node) bool {
}

// Helper function to get all keys from a mapping node
// Excludes quoted keys since they should be treated as literal strings, not OpenAPI keywords
func getNodeKeys(node *yaml.Node) []string {
if node.Kind != yaml.MappingNode {
return nil
Expand All @@ -157,7 +158,12 @@ func getNodeKeys(node *yaml.Node) []string {
var keys []string
for i := 0; i < len(node.Content); i += 2 {
if i < len(node.Content) {
keys = append(keys, node.Content[i].Value)
keyNode := node.Content[i]
// Skip quoted keys - they should not be treated as OpenAPI keywords
if keyNode.Style == yaml.SingleQuotedStyle || keyNode.Style == yaml.DoubleQuotedStyle {
continue
}
keys = append(keys, keyNode.Value)
}
}
return keys
Expand Down
57 changes: 57 additions & 0 deletions bundler/detect_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,60 @@ func parseYaml(t *testing.T, yamlStr string) *yaml.Node {
}
return &node
}

func TestDetectOpenAPIComponentType_QuotedKeys(t *testing.T) {
// Test that quoted "items" key is NOT treated as schema
quotedItemsYaml := `
"items":
- product_id: 1000012
fulfillment_node_id: US01
count: 10
`
node := parseYaml(t, quotedItemsYaml)
componentType, detected := DetectOpenAPIComponentType(node)
assert.Equal(t, "", componentType)
assert.False(t, detected)

// Test that unquoted items key IS treated as schema
unquotedItemsYaml := `
items:
type: string
`
node = parseYaml(t, unquotedItemsYaml)
componentType, detected = DetectOpenAPIComponentType(node)
assert.Equal(t, v3.SchemasLabel, componentType)
assert.True(t, detected)

// Test that quoted "type" key is NOT treated as schema
quotedTypeYaml := `
"type": "user"
"name": "John"
`
node = parseYaml(t, quotedTypeYaml)
componentType, detected = DetectOpenAPIComponentType(node)
assert.Equal(t, "", componentType)
assert.False(t, detected)

// Test that unquoted type key IS treated as schema
unquotedTypeYaml := `
type: object
properties:
name:
type: string
`
node = parseYaml(t, unquotedTypeYaml)
componentType, detected = DetectOpenAPIComponentType(node)
assert.Equal(t, v3.SchemasLabel, componentType)
assert.True(t, detected)

// Test mixed quoted and unquoted keys - should detect schema from unquoted key
mixedYaml := `
type: object
"items":
- some: data
`
node = parseYaml(t, mixedYaml)
componentType, detected = DetectOpenAPIComponentType(node)
assert.Equal(t, v3.SchemasLabel, componentType)
assert.True(t, detected)
}