ParamNamestring// The original json parameter name, eg param_name
Instring// Where the parameter is defined - path, header, cookie, query
Requiredbool// Is this a required parameter?
Spec*openapi3.Parameter
SchemaSchema
// Shared is true for a parameter declared at the path-item level, which
// is inherited by every method on the path. Its helper types are declared
// once for the path item rather than once per operation, so operation type
// collection skips them (issue #2090).
Sharedbool
}
// TypeDef is here as an adapter after a large refactoring so that I don't
// have to update all the templates. It returns the type definition for a parameter,
// without the leading '*' for optional ones.
func (pdParameterDefinition) TypeDef() string {
typeDecl:=pd.Schema.TypeDecl()
returntypeDecl
}
// RequiresNilCheck indicates whether the generated property should have a nil check performed on it before other checks.
// This should be used in templates when performing `nil` checks, but NOT when i.e. determining if there should be an optional pointer given to the type - in that case, use `HasOptionalPointer`
// HasOptionalPointer indicates whether the generated property has an optional pointer associated with it.
// This takes into account the `x-go-type-skip-optional-pointer` extension, allowing a parameter definition to control whether the pointer should be skipped.
"// %s is a helper type for the shared %q parameter of %q, prefixed with a per-path hash to disambiguate it from the same-named parameter on another path.",
td.TypeName, paramRef.Value.Name, source)
}
}
}
out=append(out, described...)
}
returnout, nil
}
// markShared flags every parameter as shared at the path-item level, so its
// helper types are declared once for the path item rather than once per
// operation (issue #2090).
funcmarkShared(params []ParameterDefinition) {
fori:=rangeparams {
params[i].Shared=true
}
}
// sharedParameterTypeDefs returns the helper TypeDefinitions produced by
// path-item-level parameters. These are emitted once for the path item
// (attributed to its first operation) instead of once per operation.
// OperationId is the `operationId` field from the OpenAPI Specification, after going through a `nameNormalizer`, and will be used to generate function names
OperationIdstring
// SpecOperationId is the raw `operationId` value as it appears in the OpenAPI spec, before normalization to a Go identifier. Empty when the spec didn't supply one (in which case the codegen-generated ID is the only available identifier and is exposed via OperationId).
SpecOperationIdstring
PathParams []ParameterDefinition// Parameters in the path, eg, /path/:param
HeaderParams []ParameterDefinition// Parameters in HTTP headers
QueryParams []ParameterDefinition// Parameters in the query, /path?param
CookieParams []ParameterDefinition// Parameters in cookies
TypeDefinitions []TypeDefinition// These are all the types we need to define for this operation
SecurityDefinitions []SecurityDefinition// These are the security providers
BodyRequiredbool
Bodies []RequestBodyDefinition// The list of bodies for which to generate handlers.
Responses []ResponseDefinition// The list of responses that can be accepted by handlers.
Summarystring// Summary string from Swagger, used to generate a comment
Methodstring// GET, POST, DELETE, etc.
Pathstring// The Swagger path for the operation, like /resource/{id}
// SpecOrder is the source line on which this operation's path is
// declared in the spec, used to register routes in the order the paths
// appear in the spec rather than sorted (issue #1887). Zero when the
// source location is unavailable (e.g. a programmatically-built spec),
// in which case route registration falls back to the default order.
SpecOrderint
Spec*openapi3.Operation
IsAliasbool// True when this path is a $ref alias of another path item
AliasTargetstring// When IsAlias is true, this is the OperationId of the canonical operation (for route registration to reference the correct wrapper)
PathItemRefstring// The path item's $ref (if any); used to qualify externally-loaded schemas referenced from this operation's responses
// IsWebhook is true when this OperationDefinition was sourced from
// spec.Webhooks (OpenAPI 3.1+). Webhook operations have no path
// template; the target URL is supplied per-call by the initiator.
IsWebhookbool
// WebhookName is the spec.Webhooks map key when IsWebhook is true.
WebhookNamestring
// IsCallback is true when this OperationDefinition was sourced from
// a parent operation's `callbacks:` block (OpenAPI 3.0+). Callback
// operations have no path template at codegen time; the target URL
// is the runtime callback URL discovered via the spec's callback
// expression (typically a field on the parent operation's request
// body) and is supplied per-call by the initiator.
IsCallbackbool
// CallbackName is the parent operation's `callbacks:` map key
// (e.g. "treePlanted") when IsCallback is true.
CallbackNamestring
}
// HandlerName returns the OperationId to use when referencing the server-side
// wrapper function. For alias operations this is the canonical operation's ID,
// since the alias doesn't generate its own wrapper.
// GenerateFunctionComment returns a full Godoc-style multi-line comment with:
// - the Summary, if present, as the first line of the comment
// - if not present, an indication of the HTTP call this corresponds with
// - the Description, if present
// - whether this function takes a body and a content type
//
// Takes originalFunctionName (the OperationId or the function name being generated for this Operation), a suffix (if necessary) and whether this is being generated for ClientInterface or ClientWithResponsesInterface