Skip to content

Commit cf40515

Browse files
committed
Prepare v1
1 parent 48aeeac commit cf40515

File tree

105 files changed

+9007
-1502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+9007
-1502
lines changed

.github/workflows/draft.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
- v1
8+
workflow_dispatch:
79

810
env:
911
CARGO_TERM_COLOR: always

Cargo.toml

+11-10
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ edition = "2021"
2020
repository = "https://github.com/netwo-io/apistos"
2121
documentation = "https://docs.rs/apistos/"
2222
license = "MIT OR Apache-2.0"
23-
rust-version = "1.75"
23+
rust-version = "1.77"
2424
publish = true
25-
version = "0.4.1"
25+
version = "1.0.0-pre-release.9"
2626

2727
[workspace.dependencies]
2828
actix-service = "2"
2929
actix-web = "4"
30-
actix-web-grants = "4"
31-
actix-web-lab = "0.20"
30+
actix-web-lab = "0.22"
3231
assert-json-diff = "2.0.2"
3332
convert_case = "0.6"
3433
darling = "0.20"
@@ -41,21 +40,23 @@ md5 = "0.7.0"
4140
once_cell = "1"
4241
pin-project = "1"
4342
proc-macro2 = "1.0"
44-
proc-macro-error = "1.0"
43+
proc-macro-error2 = "2.0"
4544
quote = "1.0"
4645
regex = ">=1.5.5"
47-
schemars = { package = "apistos-schemars", version = "0.8", features = ["chrono", "uuid1", "url", "rust_decimal"] }
48-
serde = "1"
46+
schemars = { version = "1.0.0-alpha.15", features = ["chrono04", "uuid1", "url2", "rust_decimal1"] }
47+
serde = { version = "1", features = ["derive"] }
4948
serde_json = "1"
5049
syn = "2.0"
5150

52-
actix-multipart = "0.6"
53-
garde-actix-web = "0.9"
51+
actix-multipart = "0.7"
52+
actix-web-grants = "4"
53+
garde-actix-web = "0.10"
5454
chrono = "0.4.20"
5555
garde = { version = "0.20", features = ["derive", "serde"] }
56+
ipnetwork = "0.20"
5657
rust_decimal = "1"
5758
serde_qs = "0.13"
58-
shuttle-runtime = { version = "0.46", default-features = false }
59+
shuttle-runtime = { version = "0.47", default-features = false }
5960
uuid = { version = "1", features = ["serde", "v4"] }
6061
url = "2"
6162

README.md

+20-21
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ carpenters, craftsmen, metallurgy ... which can also be considered by some as th
5959

6060
```toml
6161
[dependencies]
62-
#schemars = "0.8"
63-
# sadly we currently rely on a fork to fix multiple flatten for enums, related PR can be found here: https://github.com/GREsau/schemars/pull/264
64-
schemars = { package = "apistos-schemars", version = "0.8" }
65-
apistos = "0.4"
62+
schemars = "1.0.0-alpha.14"
63+
apistos = "1.0.0-pre-release.9"
6664
```
6765

6866
### Usage example
@@ -168,23 +166,24 @@ For a complete example, see [the sample petstore](https://github.com/netwo-io/ap
168166

169167
### Feature flags
170168

171-
| name | description | extra dependencies |
172-
|--------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------|
173-
| `query` (default) | Enables documenting `actix_web::web::Query` | |
174-
| `actix` (default) | Enables documenting types from `actix` | |
175-
| `lab_query` | Enables documenting `actix_web_lab::extract::Query` | [`actix-web-lab`](https://crates.io/crates/actix-web-lab) |
176-
| `garde` | Enables input validation through `garde` | [`garde`](https://crates.io/crates/garde) |
177-
| `actix-web-grants` | Enables support for `actix-web-grants` | [`actix-web-grants`](https://crates.io/crates/actix-web-grants) |
178-
| `rapidoc` | Enables RapiDoc to expose the generated openapi file | |
179-
| `redoc` | Enables Redoc to expose the generated openapi file | |
180-
| `swagger-ui` | Enables Swagger UI to expose the generated openapi file | |
181-
| `qs_query` | Enables documenting types from `serde_qs` | [`serde_qs`](https://crates.io/crates/serde-qs) |
182-
| `chrono` | Enables documenting types from `chrono` | [`chrono`](https://crates.io/crates/chrono) |
183-
| `multipart` | Enables documenting types from `actix-multipart` | [`actix-multipart`](https://crates.io/crates/actix-multipart) |
184-
| `rust_decimal` | Enables documenting types from `rust_decimal` | [`rust_decimal`](https://crates.io/crates/rust-decimal) |
185-
| `uuid` | Enables documenting types from `uuid` | [`uuid`](https://crates.io/crates/uuid) |
186-
| `url` | Enables documenting types from `url` | [`url`](https://crates.io/crates/url) |
187-
| `extras` | Enables `chrono`, `multipart`, `rust_decimal`, `uuid` and `url` features | All from previous features |
169+
| name | description | extra dependencies |
170+
|--------------------|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
171+
| `query` (default) | Enables documenting `actix_web::web::Query` | |
172+
| `actix` (default) | Enables documenting types from `actix` | |
173+
| `lab_query` | Enables documenting `actix_web_lab::extract::Query` | [`actix-web-lab`](https://crates.io/crates/actix-web-lab) |
174+
| `garde` | Enables input validation through `garde` | [`garde`](https://crates.io/crates/garde) |
175+
| `actix-web-grants` | Enables support for `actix-web-grants` | [`actix-web-grants`](https://crates.io/crates/actix-web-grants) |
176+
| `rapidoc` | Enables RapiDoc to expose the generated openapi file | |
177+
| `redoc` | Enables Redoc to expose the generated openapi file | |
178+
| `swagger-ui` | Enables Swagger UI to expose the generated openapi file | |
179+
| `qs_query` | Enables documenting types from `serde_qs` | [`serde_qs`](https://crates.io/crates/serde-qs) |
180+
| `chrono` | Enables documenting types from `chrono` | [`chrono`](https://crates.io/crates/chrono) |
181+
| `ipnetwork` | Enables documenting types from `ipnetwork`. Supported via `apistos::ipnetwork` mod. | [`ipnetwork`](https://crates.io/crates/ipnetwork) |
182+
| `multipart` | Enables documenting types from `actix-multipart`. `Tempfile` is supported though `apistos::multipart::Tempfile` struct. | [`actix-multipart`](https://crates.io/crates/actix-multipart) |
183+
| `rust_decimal` | Enables documenting types from `rust_decimal` | [`rust_decimal`](https://crates.io/crates/rust-decimal) |
184+
| `uuid` | Enables documenting types from `uuid` | [`uuid`](https://crates.io/crates/uuid) |
185+
| `url` | Enables documenting types from `url` | [`url`](https://crates.io/crates/url) |
186+
| `extras` | Enables `chrono`, `multipart`, `rust_decimal`, `uuid` and `url` features | All from previous features |
188187

189188
### What's next
190189

apistos-core/Cargo.toml

+15-9
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ rust-version.workspace = true
1414
license.workspace = true
1515

1616
[dependencies]
17-
pin-project = { workspace = true, optional = true }
17+
log = { workspace = true }
18+
pin-project = { workspace = true }
19+
serde_json = { workspace = true }
1820
schemars = { workspace = true }
1921

2022
actix-web = { workspace = true, optional = true }
21-
actix-web-lab = { workspace = true, optional = true }
2223
actix-web-grants = { workspace = true, optional = true }
24+
actix-web-lab = { workspace = true, optional = true }
2325
actix-multipart = { workspace = true, optional = true }
26+
futures-core = { workspace = true, optional = true }
2427
garde-actix-web = { workspace = true, optional = true }
2528
chrono = { workspace = true, optional = true }
29+
ipnetwork = { workspace = true, optional = true }
2630
rust_decimal = { workspace = true, optional = true }
2731
serde = { workspace = true, optional = true }
2832
serde_qs = { workspace = true, features = ["actix4"], optional = true }
2933
uuid = { workspace = true, optional = true }
3034
url = { workspace = true, optional = true }
3135

32-
apistos-models = { path = "../apistos-models", version = "0.4.1", features = ["deserialize"] }
36+
apistos-models = { path = "../apistos-models", version = "1.0.0-pre-release.9", features = ["deserialize"] }
3337

3438
[dev-dependencies]
3539
assert-json-diff = { workspace = true }
40+
serde = { workspace = true }
3641
serde_json = { workspace = true }
3742

3843
[lints]
3944
workspace = true
4045

4146
[features]
42-
actix = ["dep:actix-web", "dep:pin-project"]
47+
actix = ["dep:actix-web"]
4348
actix-web-grants = ["dep:actix-web-grants"]
4449

4550
# query related features
@@ -51,11 +56,12 @@ lab_query = ["actix", "dep:actix-web-lab", "garde-actix-web?/lab_query"]
5156
garde = ["actix", "dep:garde-actix-web"]
5257

5358
# extra types related features
54-
chrono = ["dep:chrono", "schemars/chrono"]
55-
multipart = ["actix", "dep:serde", "dep:actix-multipart"]
56-
rust_decimal = ["dep:rust_decimal", "schemars/rust_decimal"]
59+
chrono = ["dep:chrono", "schemars/chrono04"]
60+
ipnetwork = ["dep:serde", "dep:ipnetwork"]
61+
multipart = ["actix", "dep:serde", "dep:actix-multipart", "dep:futures-core"]
62+
rust_decimal = ["dep:rust_decimal", "schemars/rust_decimal1"]
5763
uuid = ["dep:uuid", "schemars/uuid1"]
58-
url = ["dep:url", "schemars/url"]
59-
extras = ["chrono", "multipart", "rust_decimal", "uuid", "url"]
64+
url = ["dep:url", "schemars/url2"]
65+
extras = ["chrono", "ipnetwork", "multipart", "rust_decimal", "uuid", "url"]
6066

6167
default = ["actix", "query"]

apistos-core/src/__internal/mod.rs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use std::collections::BTreeMap;
2+
3+
use apistos_models::paths::{MediaType, Response, Responses};
4+
use apistos_models::reference_or::ReferenceOr;
5+
use apistos_models::{ApistosSchema, OpenApiVersion, VersionSpecificSchema};
6+
7+
pub fn response_from_schema(
8+
oas_version: OpenApiVersion,
9+
status: &str,
10+
schema: Option<(String, ReferenceOr<ApistosSchema>)>,
11+
) -> Option<Responses> {
12+
schema.map(|(name, schema)| match schema {
13+
ReferenceOr::Reference { _ref } => Responses {
14+
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]),
15+
..Default::default()
16+
},
17+
ReferenceOr::Object(sch) => {
18+
let schema = match oas_version {
19+
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(ReferenceOr::Reference {
20+
_ref: format!("#/components/schemas/{}", name),
21+
}),
22+
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch),
23+
};
24+
let response = Response {
25+
content: BTreeMap::from_iter(vec![(
26+
"application/json".to_string(),
27+
MediaType {
28+
schema: Some(schema),
29+
..Default::default()
30+
},
31+
)]),
32+
..Default::default()
33+
};
34+
Responses {
35+
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]),
36+
..Default::default()
37+
}
38+
}
39+
})
40+
}
41+
42+
pub fn response_from_raw_schema(
43+
oas_version: OpenApiVersion,
44+
status: &str,
45+
raw_schema: Option<ReferenceOr<ApistosSchema>>,
46+
) -> Option<Responses> {
47+
raw_schema.map(|schema| match schema {
48+
ReferenceOr::Reference { _ref } => Responses {
49+
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]),
50+
..Default::default()
51+
},
52+
ReferenceOr::Object(sch) => {
53+
let schema = match oas_version {
54+
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(sch.into()),
55+
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch),
56+
};
57+
let response = Response {
58+
content: BTreeMap::from_iter(vec![(
59+
"application/json".to_string(),
60+
MediaType {
61+
schema: Some(schema),
62+
..Default::default()
63+
},
64+
)]),
65+
..Default::default()
66+
};
67+
Responses {
68+
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]),
69+
..Default::default()
70+
}
71+
}
72+
})
73+
}
74+
75+
pub fn response_for_status(status: &str) -> Responses {
76+
Responses {
77+
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(Default::default()))]),
78+
..Default::default()
79+
}
80+
}

0 commit comments

Comments
 (0)