MCPcopy Create free account
hub / github.com/apache/dubbo-go / schemaToMap

Method schemaToMap

protocol/triple/openapi/encoder.go:200–248  ·  view source on GitHub ↗
(s *model.Schema)

Source from the content-addressed store, hash-verified

198}
199
200func (e *Encoder) schemaToMap(s *model.Schema) map[string]any {
201 m := make(map[string]any)
202
203 if s.Ref != "" {
204 m["$ref"] = s.Ref
205 return m
206 }
207
208 if s.Type != "" {
209 m["type"] = string(s.Type)
210 }
211 if s.Format != "" {
212 m["format"] = s.Format
213 }
214 if s.Title != "" {
215 m["title"] = s.Title
216 }
217 if s.Description != "" {
218 m["description"] = s.Description
219 }
220 if s.Required {
221 m["required"] = true
222 }
223 if len(s.Enum) > 0 {
224 m["enum"] = s.Enum
225 }
226 if s.Items != nil {
227 m["items"] = e.schemaToMap(s.Items)
228 }
229 if len(s.Properties) > 0 {
230 props := make(map[string]any)
231 for name, prop := range s.Properties {
232 props[name] = e.schemaToMap(prop)
233 }
234 m["properties"] = props
235 }
236 if s.AdditionalProperties != nil {
237 if apSchema, ok := s.AdditionalProperties.(*model.Schema); ok {
238 m["additionalProperties"] = e.schemaToMap(apSchema)
239 } else {
240 m["additionalProperties"] = s.AdditionalProperties
241 }
242 }
243 if s.Example != nil {
244 m["example"] = s.Example
245 }
246
247 return m
248}
249
250func (e *Encoder) externalDocsToMap(docs *model.ExternalDocs) map[string]any {
251 m := make(map[string]any)

Calls

no outgoing calls