MCPcopy Create free account
hub / github.com/docker/docker-agent / schemaProxyToProperty

Function schemaProxyToProperty

pkg/tools/builtin/openapi/openapi.go:356–387  ·  view source on GitHub ↗

schemaProxyToProperty converts a libopenapi SchemaProxy to a JSON Schema property map.

(proxy *base.SchemaProxy)

Source from the content-addressed store, hash-verified

354
355// schemaProxyToProperty converts a libopenapi SchemaProxy to a JSON Schema property map.
356func 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.

Callers 1

operationSchemaFunction · 0.85

Calls 2

schemaTypeFunction · 0.85
yamlNodeToValueFunction · 0.85

Tested by

no test coverage detected