(method string, path string, opt *openapi3.Operation, params openapi3.Parameters)
| 82 | } |
| 83 | |
| 84 | func 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 | |
| 119 | func recurseSchemaRef(ref *openapi3.SchemaRef) (map[string]interface{}, error) { |
| 120 | if ref == nil || ref.Value == nil { |
no test coverage detected