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

Function generateCandidateName

pkg/codegen/resolve_names.go:46–94  ·  view source on GitHub ↗

generateCandidateName produces an initial Go type name candidate based on the schema's location and context in the OpenAPI document.

(s *GatheredSchema)

Source from the content-addressed store, hash-verified

44// generateCandidateName produces an initial Go type name candidate based on
45// the schema's location and context in the OpenAPI document.
46func generateCandidateName(s *GatheredSchema) string {
47 if s.GoNameOverride != "" {
48 return s.GoNameOverride
49 }
50
51 switch s.Context {
52 case ContextComponentSchema:
53 return SchemaNameToTypeName(s.ComponentName)
54
55 case ContextComponentParameter:
56 return SchemaNameToTypeName(s.ComponentName)
57
58 case ContextComponentResponse:
59 return SchemaNameToTypeName(s.ComponentName)
60
61 case ContextComponentRequestBody:
62 return SchemaNameToTypeName(s.ComponentName)
63
64 case ContextComponentHeader:
65 return SchemaNameToTypeName(s.ComponentName)
66
67 case ContextClientResponseWrapper:
68 // Client response wrappers use: OperationId + responseTypeSuffix
69 return fmt.Sprintf("%s%s", SchemaNameToTypeName(s.OperationID), responseTypeSuffix)
70
71 case ContextOperationParameter:
72 if s.OperationID != "" {
73 return SchemaNameToTypeName(s.OperationID) + "Parameter"
74 }
75 return SchemaNameToTypeName(s.ComponentName) + "Parameter"
76
77 case ContextOperationRequestBody:
78 if s.OperationID != "" {
79 ct := contentTypeSuffix(s.ContentType)
80 return SchemaNameToTypeName(s.OperationID) + ct + "Request"
81 }
82 return SchemaNameToTypeName(s.ComponentName) + "Request"
83
84 case ContextOperationResponse:
85 if s.OperationID != "" {
86 ct := contentTypeSuffix(s.ContentType)
87 return SchemaNameToTypeName(s.OperationID) + s.StatusCode + ct + "Response"
88 }
89 return SchemaNameToTypeName(s.ComponentName) + "Response"
90
91 default:
92 return SchemaNameToTypeName(s.ComponentName)
93 }
94}
95
96// resolveCollisions detects and resolves naming collisions among the resolved names.
97// It applies strategies in global phases of increasing aggressiveness:

Callers 1

ResolveNamesFunction · 0.85

Calls 2

SchemaNameToTypeNameFunction · 0.85
contentTypeSuffixFunction · 0.85

Tested by

no test coverage detected