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: README.md
+44-9Lines changed: 44 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,17 @@ An extension for the [Giraffe](https://github.com/giraffe-fsharp/Giraffe) Web Ap
9
9
10
10
## Table of Contents
11
11
12
-
-[About](#about)
13
-
-[Getting Started](#getting-started)
14
-
-[Documentation](#documentation)
15
-
-[Integration](#integration)
16
-
-[addOpenApi](#addopenapi)
17
-
-[addOpenApiSimple](#addopenapisimple)
18
-
-[configureEndpoint](#configureendpoint)
19
-
-[License](#license)
12
+
-[Giraffe.OpenApi](#giraffeopenapi)
13
+
-[Table of Contents](#table-of-contents)
14
+
-[About](#about)
15
+
-[Getting Started](#getting-started)
16
+
-[Documentation](#documentation)
17
+
-[Integration](#integration)
18
+
-[addOpenApi](#addopenapi)
19
+
-[addOpenApiSimple](#addopenapisimple)
20
+
-[Behavior and Nuances](#behavior-and-nuances)
21
+
-[configureEndpoint](#configureendpoint)
22
+
-[License](#license)
20
23
21
24
## About
22
25
@@ -108,12 +111,44 @@ Response body schema will be inferred from the types passed to `requestBody` and
108
111
109
112
### addOpenApiSimple
110
113
111
-
This method is a shortcut for simple cases. It accepts two generic type parameters - request and response, so the schema can be inferred from them.
114
+
This method is a shortcut for simple cases. It accepts two generic type parameters—request and response—so the schema can be inferred from them.
112
115
113
116
```fsharp
114
117
let addOpenApiSimple<'Req, 'Res> = ...
115
118
```
116
119
120
+
#### Behavior and Nuances
121
+
122
+
-**Request Type (`'Req`)**:
123
+
- If `'Req` is `unit`, the endpoint is treated as not requiring a request body (e.g., for GET endpoints).
124
+
- If `'Req` is a tuple or a primitive type (e.g., `int`, `string`), the endpoint is treated as not requiring a request body. These are typically used for path or query parameters, and the parameters are inferred from the route template.
125
+
- If `'Req` is a any other complex type (e.g., record or class types), the endpoint is treated as requiring a request body. The schema is inferred from the type's fields.
126
+
-**Response Type (`'Res`)**:
127
+
- The response schema is always inferred from the type provided as `'Res`.
128
+
- If `'Res` is `unit`, the endpoint is treated as not returning a response body.
129
+
130
+
**Important:**
131
+
- You do not need to describe route or query parameters when using `addOpenApiSimple`; they are inferred from the route template and the handler signature.
132
+
- If you want path parameters to be named, use the `routef` function with parameter labels in the route template (e.g., `routef "/users/%s:username/age/%i:age"`).
133
+
- Only use record or class types for request bodies. If you use a tuple or primitive as `'Req`, it will be treated as path/query parameters, not as a body.
134
+
- This behavior is designed with the idea that tuples and primitives are used for route parameters and records are used for complex request bodies.
135
+
136
+
**Examples:**
137
+
138
+
```fsharp
139
+
// No request body, returns a record
140
+
route "/hello" (json { Hello = "Hello from Giraffe" })
141
+
|> addOpenApiSimple<unit, FsharpMessage>
142
+
143
+
// Path parameters only, no request body
144
+
routef "/users/%s:username/age/%i:age" handler
145
+
|> addOpenApiSimple<string * int, string>
146
+
147
+
// Request body required (record type)
148
+
route "/message" handler
149
+
|> addOpenApiSimple<MyMessageRecord, string>
150
+
```
151
+
117
152
If your handler doesn't accept any input, you can pass `unit` as a request type (works for response as well).
0 commit comments