MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / genAPI

Function genAPI

mcp-server/openapi.go:84–117  ·  view source on GitHub ↗
(method string, path string, opt *openapi3.Operation, params openapi3.Parameters)

Source from the content-addressed store, hash-verified

82}
83
84func genAPI(method string, path string, opt *openapi3.Operation, params openapi3.Parameters) (*API, error) {
85 api := &API{
86 Method: method,
87 Path: path,
88 Summary: opt.Summary,
89 Description: opt.Description,
90 Params: make([]*openapi3.Parameter, 0, len(params)+len(opt.Parameters)),
91 }
92 if api.Summary == "" {
93 api.Summary = opt.Description
94 }
95 parameters := make([]*openapi3.ParameterRef, 0, len(params)+len(opt.Parameters))
96 parameters = append(parameters, opt.Parameters...)
97 parameters = append(parameters, params...)
98 for _, param := range parameters {
99 if param.Value != nil {
100 api.Params = append(api.Params, param.Value)
101 }
102 }
103 if opt.RequestBody != nil && opt.RequestBody.Value != nil && opt.RequestBody.Value.Content != nil {
104 for mediaType, media := range opt.RequestBody.Value.Content {
105 if media != nil && media.Schema != nil {
106 api.ContentType = mediaType
107 body, err := recurseSchemaRef(media.Schema)
108 if err != nil {
109 return nil, err
110 }
111 api.Body = body
112 }
113 }
114 }
115
116 return api, nil
117}
118
119func recurseSchemaRef(ref *openapi3.SchemaRef) (map[string]interface{}, error) {
120 if ref == nil || ref.Value == nil {

Callers 1

genAPIsFunction · 0.85

Calls 1

recurseSchemaRefFunction · 0.85

Tested by

no test coverage detected