extractPropertyTypeAndDesc extracts the type string and description from a schema property. For arrays, it includes the item type (e.g., "array ").
(prop *v3base.SchemaProxy)
| 470 | // extractPropertyTypeAndDesc extracts the type string and description from a schema property. |
| 471 | // For arrays, it includes the item type (e.g., "array<string>"). |
| 472 | func extractPropertyTypeAndDesc(prop *v3base.SchemaProxy) (string, string) { |
| 473 | if prop == nil { |
| 474 | return "object", "" |
| 475 | } |
| 476 | |
| 477 | propSchema := prop.Schema() |
| 478 | propType := "object" |
| 479 | |
| 480 | if propSchema != nil && len(propSchema.Type) > 0 { |
| 481 | propType = propSchema.Type[0] |
| 482 | |
| 483 | // For arrays, get the item type |
| 484 | if propType == "array" && propSchema.Items != nil && propSchema.Items.A != nil { |
| 485 | // Check for $ref first (before resolving schema) |
| 486 | if propSchema.Items.A.GetReference() != "" { |
| 487 | refParts := strings.Split(propSchema.Items.A.GetReference(), "/") |
| 488 | propType = fmt.Sprintf("array<%s>", refParts[len(refParts)-1]) |
| 489 | } else if itemSchema := propSchema.Items.A.Schema(); itemSchema != nil && len(itemSchema.Type) > 0 { |
| 490 | propType = fmt.Sprintf("array<%s>", itemSchema.Type[0]) |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | if prop.GetReference() != "" { |
| 496 | // It's a reference to another type |
| 497 | refParts := strings.Split(prop.GetReference(), "/") |
| 498 | propType = refParts[len(refParts)-1] |
| 499 | } |
| 500 | |
| 501 | desc := "" |
| 502 | if propSchema != nil { |
| 503 | desc = propSchema.Description |
| 504 | } |
| 505 | |
| 506 | return propType, desc |
| 507 | } |
| 508 | |
| 509 | // GetSchema returns the schema properties for a component schema by name. |
| 510 | // Supports both full name (bytebase.v1.Instance) and short name (Instance). |
no outgoing calls
no test coverage detected