MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / gatherClientResponseWrappers

Function gatherClientResponseWrappers

pkg/codegen/gather.go:278–319  ·  view source on GitHub ↗

gatherClientResponseWrappers creates synthetic schema entries for each operation that would generate a client response wrapper type like ` Response`. These don't correspond to a real schema in the spec but they need names that don't collide with real types.

(spec *openapi3.T)

Source from the content-addressed store, hash-verified

276// `<OperationId>Response`. These don't correspond to a real schema in the
277// spec but they need names that don't collide with real types.
278func gatherClientResponseWrappers(spec *openapi3.T) []*GatheredSchema {
279 if spec.Paths == nil {
280 return nil
281 }
282
283 // Collect all operations sorted for determinism
284 type opEntry struct {
285 path string
286 method string
287 op *openapi3.Operation
288 }
289 var ops []opEntry
290
291 pathKeys := SortedMapKeys(spec.Paths.Map())
292 for _, path := range pathKeys {
293 pathItem := spec.Paths.Find(path)
294 if pathItem == nil {
295 continue
296 }
297 for method, op := range pathItem.Operations() {
298 if op != nil && op.OperationID != "" {
299 ops = append(ops, opEntry{path: path, method: method, op: op})
300 }
301 }
302 }
303
304 // Sort by operationID for determinism
305 slices.SortFunc(ops, func(a, b opEntry) int {
306 return cmp.Compare(a.op.OperationID, b.op.OperationID)
307 })
308
309 result := make([]*GatheredSchema, 0, len(ops))
310 for _, entry := range ops {
311 result = append(result, &GatheredSchema{
312 Path: SchemaPath{"paths", entry.path, entry.method, "x-client-response-wrapper"},
313 Context: ContextClientResponseWrapper,
314 OperationID: entry.op.OperationID,
315 })
316 }
317
318 return result
319}
320
321// FormatPath returns a human-readable representation of the path for debugging.
322func (gs *GatheredSchema) FormatPath() string {

Callers 1

GatherSchemasFunction · 0.85

Calls 1

SortedMapKeysFunction · 0.85

Tested by

no test coverage detected