()
| 100 | var permissionRegex = regexp.MustCompile(`Permissions required:\s*([^\n]+)`) |
| 101 | |
| 102 | func (idx *OpenAPIIndex) parseSpec() { |
| 103 | serviceSet := make(map[string]bool) |
| 104 | |
| 105 | if idx.doc.Model.Paths == nil { |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | for pair := idx.doc.Model.Paths.PathItems.First(); pair != nil; pair = pair.Next() { |
| 110 | path := pair.Key() |
| 111 | pathItem := pair.Value() |
| 112 | |
| 113 | // Connect RPC uses POST for all endpoints |
| 114 | op := pathItem.Post |
| 115 | if op == nil { |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | // Extract service and method from path |
| 120 | // /bytebase.v1.SQLService/Query -> service=SQLService, method=Query |
| 121 | trimmed := strings.TrimPrefix(path, "/bytebase.v1.") |
| 122 | parts := strings.Split(trimmed, "/") |
| 123 | if len(parts) != 2 { |
| 124 | continue |
| 125 | } |
| 126 | |
| 127 | service := parts[0] |
| 128 | method := parts[1] |
| 129 | |
| 130 | endpoint := EndpointInfo{ |
| 131 | OperationID: op.OperationId, |
| 132 | Path: path, |
| 133 | Service: service, |
| 134 | Method: method, |
| 135 | Summary: op.Summary, |
| 136 | Description: op.Description, |
| 137 | Permissions: extractPermissions(op.Description), |
| 138 | } |
| 139 | |
| 140 | // Extract request schema reference |
| 141 | if op.RequestBody != nil { |
| 142 | content := op.RequestBody.Content |
| 143 | if content != nil { |
| 144 | if jsonContent, ok := content.Get("application/json"); ok && jsonContent.Schema != nil { |
| 145 | endpoint.RequestSchemaRef = jsonContent.Schema.GetReference() |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Extract response schema reference (from 200 response) |
| 151 | if op.Responses != nil { |
| 152 | if resp, ok := op.Responses.Codes.Get("200"); ok && resp != nil { |
| 153 | if resp.Content != nil { |
| 154 | if jsonContent, ok := resp.Content.Get("application/json"); ok && jsonContent.Schema != nil { |
| 155 | endpoint.ResponseSchemaRef = jsonContent.Schema.GetReference() |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
no test coverage detected