Skip to content

Commit 33bae35

Browse files
committed
Update README.md
1 parent f456ade commit 33bae35

File tree

2 files changed

+81
-38
lines changed

2 files changed

+81
-38
lines changed

README.md

+80-37
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,80 @@
44
[![crates.io](https://img.shields.io/static/v1?label=crates.io&message=0.1.0-beta.0&color=orange&logo=rust)](https://crates.io/crates/utoipa/0.1.0-beta.0)
55
[![docs.rs](https://img.shields.io/static/v1?label=docs.rs&message=utoipa&color=blue&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K)](https://docs.rs/utoipa/0.1.0-beta.0/utoipa/)
66

7-
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.
813

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.
1217

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.
1520

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+
```
1855

1956
## Current project status
2057

2158
**This project is currently in active development and not ready for PRODUCTION use!**
2259

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.
2463

2564
See https://github.com/juhaku/utoipa/projects for more details about the progress of the project implementation.
2665

27-
## 30 sec Lesson
66+
## Examples
2867

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.
3070
```rust
31-
#[derive(Deserialize, Serialize, Component)]
71+
use utoipa::Component;
72+
#[derive(Component)]
3273
struct Pet {
33-
id: u64,
34-
name: String,
35-
age: Option<i32>,
74+
id: u64,
75+
name: String,
76+
age: Option<i32>,
3677
}
3778
```
3879

39-
Create your Get pet API.
80+
Create an handler that would handle your business logic and add `path` proc attribute macro over it.
4081
```rust
4182
mod pet_api {
4283
/// Get pet by id
@@ -63,9 +104,12 @@ mod pet_api {
63104
}
64105
```
65106

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.
67108
```rust
68-
#[derive(OpenApi, Default)]
109+
use utoipa::OpenApi;
110+
use crate::Pet;
111+
112+
#[derive(OpenApi)]
69113
#[openapi(handlers = [pet_api::get_pet_by_id], components = [Pet])]
70114
struct ApiDoc;
71115

@@ -156,25 +200,24 @@ This would produce api doc something similar to:
156200
}
157201
```
158202

159-
## Goals
160-
161-
Eeasy of use, and easy of development along with avoinding excessive cloning and keeping perfomance in
162-
mind while developing the library. It should follow the general rust quidelines and latest conventions
163-
of the Rust.
164-
165-
Goal|Status
166-
-|-
167-
Necessary subset implementation of OpenAPI spec in Rust| :heavy_minus_sign: Some definitions missing
168-
Macros for autogenerating documentation | :heavy_check_mark: Done, but some things missing
169-
Embed Swagger UI for OpenAPI documentation | :heavy_check_mark: Done
170-
Embed ReDocly for OpenAPI documentation | :x: Not done
171-
Integration with Actix web framework | :heavy_check_mark: Done
172-
Integration with Rocker framework | :x: Not done
173-
Write exessive documentation & Book & Examples | :x: Not done
174-
At least 90 % tested code | :heavy_minus_sign: Still ongoing along with the other development
175-
176-
Integration with other frameworks are not planned as of this stage but when the intial set of features are
177-
complete the integrations with other frameworks can be prioritized.
203+
If you have *swagger_ui* and the *actix-web* features enabled you can display the openapi documentation
204+
as easily as follows:
205+
```rust
206+
HttpServer::new(move || {
207+
App::new()
208+
.service(
209+
SwaggerUi::new("/swagger-ui/{_:.*}")
210+
.with_url("/api-doc/openapi.json", ApiDoc::openapi()),
211+
)
212+
})
213+
.bind(format!("{}:{}", Ipv4Addr::UNSPECIFIED, 8989))?
214+
.run()
215+
.await
216+
```
217+
218+
See more details in `swagger_ui` module of [utoipa docs](https://docs.rs/utoipa/0.1.0-beta.0/utoipa/).
219+
You can also browse to [examples](https://github.com/juhaku/utoipa/tree/master/examples) for
220+
more comprehensinve examples.
178221

179222
# License
180223

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
//! path = "/pets/{id}"
7373
//! responses = [
7474
//! (status = 200, description = "Pet found succesfully", body = Pet),
75-
//! (status = 404, description = "Pet was not found", body = NotFoundError)
75+
//! (status = 404, description = "Pet was not found")
7676
//! ],
7777
//! params = [
7878
//! ("id" = u64, path, description = "Pet database id to get Pet for"),

0 commit comments

Comments
 (0)