Involved Source Files 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.bindform.go 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.deepobject.gojsonmerge.go 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.
Package-Level Type Names (total 5, in which 4 are exported)
/* sort exporteds by: | */
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.( Binder) Bind(src string) error
BindStyledParameterOptions defines optional arguments for BindStyledParameterWithOptions Whether the parameter should use exploded structure ParamLocation tells us where the parameter is located in the request. Whether the parameter is required in the query
func BindStyledParameterWithOptions(style string, paramName string, value string, dest any, opts BindStyledParameterOptions) 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.
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.
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.
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.
BindStyledParameterWithOptions binds a parameter as described in the Path Parameters
section here to a Go object:
https://swagger.io/docs/specification/serialization/
JSONMerge merges two JSON representation into a single object. `data` is the
existing representation and `patch` is the new data to be merged in
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.
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.
Given an input value, such as a primitive type, array or object, turn it
into a parameter based on style/explode definition, performing whatever
escaping is necessary based on parameter location
bindParamsToExplodedObject reflects the destination structure, and pulls the value for
each settable field from the given parameters map. This is to deal with the
exploded form styled object which may occupy any number of parameter names.
We don't try to be smart here, if the field exists as a query argument,
set its value. This function returns a boolean, telling us whether there was
anything to bind. There will be nothing to bind if a parameter isn't found by name,
or none of an exploded object's fields are present.
Given a set of values as a slice, create a slice to hold them all, and
assign to each one by one.
Given a set of chopped up parameter parts, bind them to a destination
struct. The exploded parameter controls whether we send key value pairs
in the exploded case, or a sequence of values which are interpreted as
tuples.
Given the struct Id { firstName string, role string }, as in the canonical
swagger examples, in the exploded case, we would pass
["firstName=Alex", "role=admin"], where in the non-exploded case, we would
pass "firstName", "Alex", "role", "admin"]
We punt the hard work of binding these values to the object to the json
library. We'll turn those arrays into JSON strings, and unmarshal
into the struct.
escapeParameterString escapes a parameter value bas on the location of that parameter.
Query params and path params need different kinds of escaping, while header
and cookie params seem not to need escaping.
Create a map of field names that we'll see in the deepObject to reflect
field indices on the given type.
This returns a field name, either using the variable name, or the json
annotation if that exists.
This is a complex set of operations, but each given parameter style can be
packed together in multiple ways, using different styles of separators, and
different packing strategies based on the explode flag. This function takes
as input any parameter format, and unpacks it to a simple list of strings
or key-values which we can then treat generically.
Why, oh why, great Swagger gods, did you have to make this so complicated?
The pages are generated with Goldsv0.7.6. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.