GetRequestSchema returns the simplified schema properties for a request type.
(schemaRef string)
| 417 | |
| 418 | // GetRequestSchema returns the simplified schema properties for a request type. |
| 419 | func (idx *OpenAPIIndex) GetRequestSchema(schemaRef string) []PropertyInfo { |
| 420 | if schemaRef == "" || idx.doc.Model.Components == nil || idx.doc.Model.Components.Schemas == nil { |
| 421 | return nil |
| 422 | } |
| 423 | |
| 424 | // Extract schema name from ref: "#/components/schemas/bytebase.v1.QueryRequest" |
| 425 | parts := strings.Split(schemaRef, "/") |
| 426 | schemaName := parts[len(parts)-1] |
| 427 | |
| 428 | schemaProxy, ok := idx.doc.Model.Components.Schemas.Get(schemaName) |
| 429 | if !ok || schemaProxy == nil { |
| 430 | return nil |
| 431 | } |
| 432 | |
| 433 | schema := schemaProxy.Schema() |
| 434 | if schema == nil { |
| 435 | return nil |
| 436 | } |
| 437 | |
| 438 | var props []PropertyInfo |
| 439 | requiredSet := make(map[string]bool) |
| 440 | for _, r := range schema.Required { |
| 441 | requiredSet[r] = true |
| 442 | } |
| 443 | |
| 444 | if schema.Properties == nil { |
| 445 | return nil |
| 446 | } |
| 447 | |
| 448 | for pair := schema.Properties.First(); pair != nil; pair = pair.Next() { |
| 449 | name := pair.Key() |
| 450 | prop := pair.Value() |
| 451 | |
| 452 | propType, desc := extractPropertyTypeAndDesc(prop) |
| 453 | |
| 454 | props = append(props, PropertyInfo{ |
| 455 | Name: name, |
| 456 | Type: propType, |
| 457 | Description: desc, |
| 458 | Required: requiredSet[name], |
| 459 | }) |
| 460 | } |
| 461 | |
| 462 | // Sort by name for consistent output |
| 463 | slices.SortFunc(props, func(a, b PropertyInfo) int { |
| 464 | return strings.Compare(a.Name, b.Name) |
| 465 | }) |
| 466 | |
| 467 | return props |
| 468 | } |
| 469 | |
| 470 | // extractPropertyTypeAndDesc extracts the type string and description from a schema property. |
| 471 | // For arrays, it includes the item type (e.g., "array<string>"). |
no test coverage detected