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
+38-35Lines changed: 38 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,8 @@ The library is based on [SwiftOpenAPI](https://github.com/dankinsoid/SwiftOpenAP
7
7
8
8
## Usage
9
9
10
-
### [Stoplight](https://stoplight.io) setup
11
-
1. Describe all of your routes and register all controllers as described in [Vapor docs](https://docs.vapor.codes/basics/routing). Add OpenAPI details to each route using the `route.openAPI` method.
12
-
2. Add a route via the `routes.stoplightDocumentation` to return an `OpenAPIObject` instance via the `routes.openAPI` method.
13
-
14
-
### [Swagger](https://swagger.io) setup
15
-
1. Set up a [SwaggerUI page](https://github.com/swagger-api/swagger-ui) in your Vapor project downloading the `dist` folder and placing its content in the `Public/Swagger` directory.
16
-
2. Describe all of your routes and register all controllers as described in [Vapor docs](https://docs.vapor.codes/basics/routing). Add OpenAPI details to each route using the `route.openAPI` method.
17
-
3. Add a route to return a [SwaggerUI index.html](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html). Or configure your middlewares to use 'index.html' as default page.
18
-
4. Add a route to return an `OpenAPIObject` instance via the `app.routes.openAPI` method. Make sure the path of this route matches the `swagger.json` URL in your SwaggerUI page method.
19
-
20
-
> [!IMPORTANT]
21
-
All enums in your models must implement `CaseIterable`.
22
-
23
-
### Advanced Usage
24
-
VaporToOpenAPI includes several advanced features that allow you to customize the generated OpenAPI documentation in various ways. Some of these features include:
25
-
26
-
-`openAPI`: This method is used to add OpenAPI metadata to a single Vapor route. It takes a variety of parameters, such as a summary and description of the operation, request and response bodies, query parameters, and more.\
27
-
Here's an example of how you might use it to document a POST request:
description: "Create a new user with the provided data",
36
-
body: .type(User.self),
37
-
response: .type(User.self)
38
-
)
39
-
```
40
-
-`openAPI` (on Routes): This method is used to generate an entire OpenAPI specification from your Vapor routes. It takes a variety of parameters, such as the title and description of your API, the available paths and operations, security requirements, and more.
10
+
### Create a route with an `OpenAPI` specification.
11
+
Add a route to return an `OpenAPIObject` via the `app.routes.openAPI` method. This method is used to generate an entire OpenAPI specification from all your Vapor routes. It takes a variety of parameters, such as the title and description of your API, the available paths and operations, security requirements, and more.
41
12
```swift
42
13
// generate OpenAPI documentation
43
14
routes.get("Swagger", "swagger.json") { req in
@@ -51,6 +22,32 @@ routes.get("Swagger", "swagger.json") { req in
51
22
}
52
23
.excludeFromOpenAPI()
53
24
```
25
+
You also can configure a web page:
26
+
- Use `stoplightDocumentation(openAPI:)` helper method to generate a [Stoplight](https://stoplight.io) page. This method also can return an `OpenAPIObject`.
27
+
-[Here is an example](##short-example) how to configure SwaggerUI.
28
+
29
+
### Specify all details for routes
30
+
Add `.openAPI` modifier to a route to specify a variety of parameters, such as a summary and description of the operation, request and response bodies, query parameters, headers and more.\
31
+
Here's an example of how you might use it to document a `POST` request:
description: "Create a new user with the provided data",
40
+
body: .type(User.self),
41
+
response: .type(User.self)
42
+
)
43
+
```
44
+
45
+
> [!IMPORTANT]
46
+
All enums in your models must implement `CaseIterable`.
47
+
48
+
## Advanced Usage
49
+
VaporToOpenAPI includes several advanced features that allow you to customize the generated OpenAPI documentation in various ways. Some of these features include:
50
+
54
51
-`response`: This method is used to specify an additional response body for a Vapor route. It takes a variety of parameters, such as the status code, description, and response body type.
55
52
-`groupedOpenAPI`: These methods are used to group Vapor routes together based on OpenAPI metadata, such as tags or security requirements.\
56
53
Here's an example of how you might use it to group routes with the same security requirements:
Links are one of the new features of OpenAPI 3.0. Using links, you can describe how various values returned by one operation can be used as input for other operations.
118
115
To create a Link:
119
116
1. create `LinkKey` type identifying some reusable parameter.
Change `url` in [`swagger-initializer.js`](https://github.com/swagger-api/swagger-ui/blob/master/dist/swagger-initializer.js)
139
+
### 1. SwaggerUI page
140
+
141
+
1. Set up a [SwaggerUI page](https://github.com/swagger-api/swagger-ui) in your Vapor project downloading the `dist` folder and placing its content in the `Public/Swagger` directory.
142
+
2. Describe all of your routes and register all controllers as described in [Vapor docs](https://docs.vapor.codes/basics/routing). Add OpenAPI details to each route using the `route.openAPI` method.
143
+
3. Add a route to return a [SwaggerUI index.html](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html). Or configure your middlewares to use 'index.html' as default page.
144
+
4. Add a route to return an `OpenAPIObject` instance via the `app.routes.openAPI` method. Make sure the path of this route matches the `swagger.json` URL in your SwaggerUI page method.
145
+
146
+
5. Change `url` in [`swagger-initializer.js`](https://github.com/swagger-api/swagger-ui/blob/master/dist/swagger-initializer.js)
0 commit comments