diff --git a/bundler/detect_type.go b/bundler/detect_type.go index f242056c..b8396c23 100644 --- a/bundler/detect_type.go +++ b/bundler/detect_type.go @@ -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 @@ -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 diff --git a/bundler/detect_type_test.go b/bundler/detect_type_test.go index dc9a87ca..8764e7d4 100644 --- a/bundler/detect_type_test.go +++ b/bundler/detect_type_test.go @@ -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) +}