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

Function DescribeParameters

pkg/codegen/operations.go:248–292  ·  view source on GitHub ↗

DescribeParameters walks the given parameters dictionary, and generates the above descriptors into a flat list. This makes it a lot easier to traverse the data in the template engine.

(params openapi3.Parameters, path []string)

Source from the content-addressed store, hash-verified

246// descriptors into a flat list. This makes it a lot easier to traverse the
247// data in the template engine.
248func DescribeParameters(params openapi3.Parameters, path []string) ([]ParameterDefinition, error) {
249 outParams := make([]ParameterDefinition, 0, len(params))
250 for _, paramOrRef := range params {
251 param := paramOrRef.Value
252
253 goType, err := paramToGoType(param, append(path, param.Name))
254 if err != nil {
255 return nil, fmt.Errorf("error generating type for param (%s): %s",
256 param.Name, err)
257 }
258
259 pd := ParameterDefinition{
260 ParamName: param.Name,
261 In: param.In,
262 Required: param.Required,
263 Spec: param,
264 Schema: goType,
265 }
266
267 // A parameter-level `x-go-type-skip-optional-pointer` overrides the
268 // schema-level setting. `GenStructFromSchema` applies the same override
269 // when rendering the params struct; without mirroring it here, the
270 // client/server templates disagree with the struct definition and emit
271 // a dereference (`*params.Field`) on a field declared without a pointer.
272 if extension, ok := param.Extensions[extPropGoTypeSkipOptionalPointer]; ok {
273 if skipOptionalPointer, err := extParsePropGoTypeSkipOptionalPointer(extension); err == nil {
274 pd.Schema.SkipOptionalPointer = skipOptionalPointer
275 }
276 }
277
278 // If this is a reference to a predefined type, simply use the reference
279 // name as the type. $ref: "#/components/schemas/custom_type" becomes
280 // "CustomType".
281 if IsGoTypeReference(paramOrRef.Ref) {
282 goType, err := RefPathToGoType(paramOrRef.Ref)
283 if err != nil {
284 return nil, fmt.Errorf("error dereferencing (%s) for param (%s): %s",
285 paramOrRef.Ref, param.Name, err)
286 }
287 pd.Schema.GoType = goType
288 }
289 outParams = append(outParams, pd)
290 }
291 return outParams, nil
292}
293
294type SecurityDefinition struct {
295 ProviderName string

Callers 1

OperationDefinitionsFunction · 0.85

Calls 4

paramToGoTypeFunction · 0.85
IsGoTypeReferenceFunction · 0.85
RefPathToGoTypeFunction · 0.85

Tested by

no test coverage detected