Documentation
¶
Overview ¶
Copyright 2021 DeepMap, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 DeepMap, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 DeepMap, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 DeepMap, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func BindForm(ptr interface{}, form map[string][]string, ...) error
- func BindMultipart(ptr interface{}, reader multipart.Reader) error
- func BindQueryParameter(style string, explode bool, required bool, paramName string, ...) errordeprecated
- func BindQueryParameterWithOptions(style string, explode bool, required bool, paramName string, ...) error
- func BindRawQueryParameter(style string, explode bool, required bool, paramName string, rawQuery string, ...) error
- func BindStringToObject(src string, dst interface{}) error
- func BindStringToObjectWithOptions(src string, dst interface{}, opts BindStringToObjectOptions) error
- func BindStyledParameter(style string, explode bool, paramName string, value string, dest interface{}) error
- func BindStyledParameterWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, ...) error
- func BindStyledParameterWithOptions(style string, paramName string, value string, dest any, ...) error
- func JSONMerge(data, patch json.RawMessage) (json.RawMessage, error)
- func JsonMerge(data, patch json.RawMessage) (json.RawMessage, error)deprecated
- func MarshalDeepObject(i interface{}, paramName string) (string, error)
- func MarshalForm(ptr interface{}, encodings map[string]RequestBodyEncoding) (url.Values, error)
- func StyleParam(style string, explode bool, paramName string, value interface{}) (string, error)
- func StyleParamWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, ...) (string, error)
- func StyleParamWithOptions(style string, explode bool, paramName string, value interface{}, ...) (string, error)
- func UnmarshalDeepObject(dst interface{}, paramName string, params url.Values) error
- type BindQueryParameterOptions
- type BindStringToObjectOptions
- type BindStyledParameterOptions
- type Binder
- type ParamLocation
- type RequestBodyEncoding
- type StyleParamOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindForm ¶
func BindForm(ptr interface{}, form map[string][]string, files map[string][]*multipart.FileHeader, encodings map[string]RequestBodyEncoding) error
func BindMultipart ¶
func BindQueryParameter
deprecated
func BindQueryParameter(style string, explode bool, required bool, paramName string, queryParams url.Values, dest interface{}) error
BindQueryParameter works much like BindStyledParameter, however it takes a query argument input array from the url package, since query arguments come through a different path than the styled arguments. They're also exceptionally fussy. For example, consider the exploded and unexploded form parameter examples: (exploded) /users?role=admin&firstName=Alex (unexploded) /users?id=role,admin,firstName,Alex
In the first case, we can pull the "id" parameter off the context, and unmarshal via json as an intermediate. Easy. In the second case, we don't have the id QueryParam present, but must find "role", and "firstName". what if there is another parameter similar to "ID" named "role"? We can't tell them apart. This code tries to fail, but the moral of the story is that you shouldn't pass objects via form styled query arguments, just use the Content parameter form.
Deprecated: BindQueryParameter pre-decodes the query string via url.Values, which makes it impossible to distinguish literal commas from delimiter commas in form/explode=false parameters. Use BindRawQueryParameter instead, which operates on the raw query string and handles encoded delimiters correctly.
func BindQueryParameterWithOptions ¶ added in v1.2.0
func BindQueryParameterWithOptions(style string, explode bool, required bool, paramName string, queryParams url.Values, dest interface{}, opts BindQueryParameterOptions) error
BindQueryParameterWithOptions works like BindQueryParameter with additional options.
func BindRawQueryParameter ¶ added in v1.2.0
func BindRawQueryParameter(style string, explode bool, required bool, paramName string, rawQuery string, dest any) error
BindRawQueryParameter works like BindQueryParameter but operates on the raw (undecoded) query string instead of pre-parsed url.Values. This correctly handles form/explode=false parameters whose values contain literal commas encoded as %2C — something that BindQueryParameter cannot do because url.Values has already decoded %2C to ',' before we can split on the delimiter comma.
func BindStringToObject ¶
BindStringToObject takes a string, and attempts to assign it to the destination interface via whatever type conversion is necessary. We have to do this via reflection instead of a much simpler type switch so that we can handle type aliases. This function was the easy way out, the better way, since we know the destination type each place that we use this, is to generate code to read each specific type.
func BindStringToObjectWithOptions ¶ added in v1.2.0
func BindStringToObjectWithOptions(src string, dst interface{}, opts BindStringToObjectOptions) error
BindStringToObjectWithOptions takes a string, and attempts to assign it to the destination interface via whatever type conversion is necessary, with additional options.
func BindStyledParameter ¶
func BindStyledParameter(style string, explode bool, paramName string, value string, dest interface{}) error
BindStyledParameter binds a parameter as described in the Path Parameters section here to a Go object: https://swagger.io/docs/specification/serialization/ It is a backward compatible function to clients generated with codegen up to version v1.5.5. v1.5.6+ calls the function below. Deprecated: BindStyledParameter is deprecated.
func BindStyledParameterWithLocation ¶
func BindStyledParameterWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, value string, dest interface{}) error
BindStyledParameterWithLocation binds a parameter as described in the Path Parameters section here to a Go object: https://swagger.io/docs/specification/serialization/ This is a compatibility function which is used by oapi-codegen v2.0.0 and earlier. Deprecated: BindStyledParameterWithLocation is deprecated.
func BindStyledParameterWithOptions ¶ added in v1.1.0
func BindStyledParameterWithOptions(style string, paramName string, value string, dest any, opts BindStyledParameterOptions) error
BindStyledParameterWithOptions binds a parameter as described in the Path Parameters section here to a Go object: https://swagger.io/docs/specification/serialization/
func JSONMerge ¶ added in v1.1.0
func JSONMerge(data, patch json.RawMessage) (json.RawMessage, error)
JSONMerge merges two JSON representation into a single object. `data` is the existing representation and `patch` is the new data to be merged in
func JsonMerge
deprecated
func JsonMerge(data, patch json.RawMessage) (json.RawMessage, error)
JsonMerge merges two JSON representation into a single object. `data` is the existing representation and `patch` is the new data to be merged in
Deprecated: Use JSONMerge instead.
func MarshalDeepObject ¶
func MarshalForm ¶
func MarshalForm(ptr interface{}, encodings map[string]RequestBodyEncoding) (url.Values, error)
func StyleParam ¶
StyleParam is used by older generated code, and must remain compatible with that code. It is not to be used in new templates. Please see the function below, which can specialize its output based on the location of the parameter.
func StyleParamWithLocation ¶
func StyleParamWithLocation(style string, explode bool, paramName string, paramLocation ParamLocation, value interface{}) (string, error)
StyleParamWithLocation serializes a Go value into an OpenAPI-styled parameter string, performing escaping based on parameter location.
func StyleParamWithOptions ¶ added in v1.2.0
func StyleParamWithOptions(style string, explode bool, paramName string, value interface{}, opts StyleParamOptions) (string, error)
StyleParamWithOptions serializes a Go value into an OpenAPI-styled parameter string with additional options.
Types ¶
type BindQueryParameterOptions ¶ added in v1.2.0
type BindQueryParameterOptions struct {
// Type is the OpenAPI type of the parameter (e.g. "string", "integer").
Type string
// Format is the OpenAPI format of the parameter (e.g. "byte", "date-time").
// When set to "byte" and the destination is []byte, the value is
// base64-decoded rather than treated as a generic slice.
Format string
}
BindQueryParameterOptions defines optional arguments for BindQueryParameterWithOptions.
type BindStringToObjectOptions ¶ added in v1.2.0
type BindStringToObjectOptions struct {
// Type is the OpenAPI type of the parameter (e.g. "string", "integer").
Type string
// Format is the OpenAPI format of the parameter (e.g. "byte", "date-time").
// When set to "byte" and the destination is []byte, the source string is
// base64-decoded rather than treated as a generic slice.
Format string
}
BindStringToObjectOptions defines optional arguments for BindStringToObjectWithOptions.
type BindStyledParameterOptions ¶ added in v1.1.0
type BindStyledParameterOptions struct {
// ParamLocation tells us where the parameter is located in the request.
ParamLocation ParamLocation
// Whether the parameter should use exploded structure
Explode bool
// Whether the parameter is required in the query
Required bool
// Type is the OpenAPI type of the parameter (e.g. "string", "integer").
Type string
// Format is the OpenAPI format of the parameter (e.g. "byte", "date-time").
// When set to "byte" and the destination is []byte, the value is
// base64-decoded rather than treated as a generic slice.
Format string
}
BindStyledParameterOptions defines optional arguments for BindStyledParameterWithOptions
type Binder ¶
Binder is the interface implemented by types that can be bound to a query string or a parameter string The input can be assumed to be a valid string. If you define a Bind method you are responsible for all data being completely bound to the type.
By convention, to approximate the behavior of Bind functions themselves, Binder implements Bind("") as a no-op.
type ParamLocation ¶
type ParamLocation int
const ( ParamLocationUndefined ParamLocation = iota ParamLocationQuery ParamLocationPath ParamLocationHeader ParamLocationCookie )
type RequestBodyEncoding ¶
type StyleParamOptions ¶ added in v1.2.0
type StyleParamOptions struct {
// ParamLocation controls URL escaping behavior.
ParamLocation ParamLocation
// Type is the OpenAPI type of the parameter (e.g. "string", "integer").
Type string
// Format is the OpenAPI format of the parameter (e.g. "byte", "date-time").
// When set to "byte" and the value is []byte, it is base64-encoded as a
// single string rather than treated as a generic slice of uint8.
Format string
// Required indicates whether the parameter is required.
Required bool
}
StyleParamOptions defines optional arguments for StyleParamWithOptions.