schemaProxyToProperty converts a libopenapi SchemaProxy to a JSON Schema property map.
(proxy *base.SchemaProxy)
| 354 | |
| 355 | // schemaProxyToProperty converts a libopenapi SchemaProxy to a JSON Schema property map. |
| 356 | func schemaProxyToProperty(proxy *base.SchemaProxy) map[string]any { |
| 357 | if proxy == nil { |
| 358 | return map[string]any{"type": "string"} |
| 359 | } |
| 360 | |
| 361 | s := proxy.Schema() |
| 362 | if s == nil { |
| 363 | return map[string]any{"type": "string"} |
| 364 | } |
| 365 | |
| 366 | prop := map[string]any{ |
| 367 | "type": schemaType(s), |
| 368 | } |
| 369 | |
| 370 | if s.Description != "" { |
| 371 | prop["description"] = s.Description |
| 372 | } |
| 373 | if len(s.Enum) > 0 { |
| 374 | enumValues := make([]any, 0, len(s.Enum)) |
| 375 | for _, node := range s.Enum { |
| 376 | if node != nil { |
| 377 | enumValues = append(enumValues, yamlNodeToValue(node)) |
| 378 | } |
| 379 | } |
| 380 | prop["enum"] = enumValues |
| 381 | } |
| 382 | if s.Default != nil { |
| 383 | prop["default"] = yamlNodeToValue(s.Default) |
| 384 | } |
| 385 | |
| 386 | return prop |
| 387 | } |
| 388 | |
| 389 | // schemaType returns the JSON Schema type string for an OpenAPI schema. |
| 390 | // Defaults to "string" when the type is unspecified. |
no test coverage detected