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
Want to document your utopic api? Want it to feel as fuzzy as cold ipa? Then you are probably in need of utoipa.
7
+
Want to have your API documented with OpenAPI? But you dont want to see the
8
+
trouble with manual yaml or json tweaking? Would like it to be so easy that it would almost
9
+
be like utopic? Don't worry utoipa is just there to fill this gap. It aims to do if not all then
10
+
the most of heavy lifting for you enabling you to focus writing the actual API logic instead of
11
+
documentation. It aims to be *minimal*, *simple* and *fast*. It uses simple proc macros which
12
+
you can use to annotate your code to have items documented.
8
13
9
-
Utoipa crate provides autogenerated OpenAPI documentation for Rust REST APIs. It treats code first appoach as a
10
-
first class citizen and simplifies API documentation by providing simple macros for generating the
11
-
documentation from your code.
14
+
Utoipa crate provides autogenerated OpenAPI documentation for Rust REST APIs. It treats
15
+
code first appoach as a first class citizen and simplifies API documentation by providing
16
+
simple macros for generating the documentation from your code.
12
17
13
-
It also contains Rust types of OpenAPI spec allowing you to write the OpenAPI spec only using Rust if
14
-
autogeneration is not your flavor or does not fit your purpose.
18
+
It also contains Rust types of OpenAPI spec allowing you to write the OpenAPI spec only using
19
+
Rust if autogeneration is not your flavor or does not fit your purpose.
15
20
16
-
In future there are plans to support more sophisticated code generation from generated OpenAPI spec and as well
17
-
to support contract first approach.
21
+
Long term goal of the library is to be the place to go when OpenAPI documentation is needed in Rust
22
+
codebase.
23
+
24
+
# What's up with the word play?
25
+
26
+
The name comes from words `utopic` and `api` where `uto` is the first three letters of utopic
27
+
and the `ipa` is api reversed.
28
+
29
+
# Features
30
+
31
+
***default** Default enabled features are **json**.
32
+
***json** Enables some advanced features for openapi which otherwise are not available. Thus is
33
+
enabled by default.
34
+
***swagger_ui** Enables the embedded Swagger UI to view openapi api documentation.
35
+
***actix-web** Enables actix-web integration with pre-configured SwaggerUI service factory allowing
36
+
users to use the Swagger UI without a hazzle.
37
+
***actix_extras** Enhances actix-web intgration with being able to parse some documentation
38
+
from actix web macro attributes and types.
39
+
***debug** Add extra traits such as debug traits to openapi definitions and elsewhere.
40
+
41
+
# Install
42
+
43
+
Add minimal dependency declaration to Cargo.toml.
44
+
```
45
+
[dependencies]
46
+
utoipa = "0.1.beta.0"
47
+
```
48
+
49
+
To enable more features such as use of swagger together with actix-web framework you could define the
50
+
dependency as follows.
51
+
```
52
+
[dependencies]
53
+
utoipa = { version = "0.1.beta.0", features = ["swagger_ui", "actix-web", "actix_extras"] }
54
+
```
18
55
19
56
## Current project status
20
57
21
58
**This project is currently in active development and not ready for PRODUCTION use!**
22
59
23
-
The reference implementation is almost there which enables people to play around with the library. It is yet to be released to crates later on when the api and the functionalities are mature enough for wider scale adoption.
60
+
The basic features are nearly implemented and the it can handle the OpenApi generation in most typical situations.
61
+
It is yet to be released to crates later on when the api and the functionalities gets mature enough. Before initial
62
+
release there are going to be still couple of beta releases and one or few rc releases.
24
63
25
64
See https://github.com/juhaku/utoipa/projects for more details about the progress of the project implementation.
26
65
27
-
## 30 sec Lesson
66
+
## Examples
28
67
29
-
Create type for API. Crusial part is the `Component` derive which will create OpenAPI component for the struct or enum.
68
+
Create a struct or it could be an enum also. Add `Component` derive macro to it so it can be registered
69
+
as a component in OpenApi schema.
30
70
```rust
31
-
#[derive(Deserialize, Serialize, Component)]
71
+
useutoipa::Component;
72
+
#[derive(Component)]
32
73
structPet {
33
-
id:u64,
34
-
name:String,
35
-
age:Option<i32>,
74
+
id:u64,
75
+
name:String,
76
+
age:Option<i32>,
36
77
}
37
78
```
38
79
39
-
Create your Get pet API.
80
+
Create an handler that would handle your business logic and add `path` proc attribute macro over it.
40
81
```rust
41
82
modpet_api {
42
83
/// Get pet by id
@@ -63,9 +104,12 @@ mod pet_api {
63
104
}
64
105
```
65
106
66
-
Tie the API and Component together with the `OpenApi` derive which will create OpenAPI api doc for you.
107
+
Tie the `Component` and the api above to the OpenApi schema with following `OpenApi` derive proc macro.
0 commit comments