You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/features/request-inputs.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,21 @@ description: Path, query, and header input parameters as well as input request b
8
8
9
9
Requests can have parameters and/or a body as input to the handler function. Inputs use standard Go structs with special fields and/or tags. Here are the available tags:
|`path`| Name of the path parameter |`path:"thing-id"`|
14
+
|`query`| Name of the query string parameter |`query:"q"`|
15
+
|`header`| Name of the header parameter |`header:"Authorization"`|
16
+
|`cookie`| Name of the cookie parameter |`cookie:"session"`|
17
+
|`required`| Mark a cookie/header/query param as required |`required:"true"`|
18
+
19
+
!!! info "Default Optionality"
20
+
21
+
Cookier, header, and query parameters are **optional by default**. Path parameters are always required. This differs from object fields (e.g. in a request body), which are required by default unless `omitempty` or `omitzero` is used.
18
22
19
23
!!! info "Required"
20
24
21
-
The `required` tag is discouraged and is only used for query/header params, which should generally be optional for clients to send.
25
+
The `required` tag is discouraged and is only used for header/query params, which should generally be optional for clients to send.
Copy file name to clipboardExpand all lines: docs/docs/features/request-validation.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,14 @@ The standard `json` tag is supported and can be used to rename a field. Any fiel
23
23
24
24
Fields being optional/required is determined automatically but can be overridden as needed using the logic below:
25
25
26
-
1. Start with all fields required.
26
+
1. Start with all fields required, **except for cookie, header, and query parameters which are optional by default**.
27
27
2. If a field has `omitempty`, it is optional.
28
28
3. If a field has `omitzero`, it is optional.
29
29
4. If a field has `required:"false"`, it is optional.
30
30
5. If a field has `required:"true"`, it is required.
31
31
32
+
Path parameters are always required. Cookie, header, and query parameters are optional unless explicitly marked with `required:"true"`. All other fields (like those in a request body or multipart form) follow the default required status.
33
+
32
34
Pointers have no effect on optional/required. The same rules apply regardless of whether the struct is being used for request input or response output. Some examples:
0 commit comments