Skip to content

Commit

Permalink
Prepare v1
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran committed Dec 22, 2024
1 parent 48aeeac commit cf40515
Show file tree
Hide file tree
Showing 105 changed files with 9,007 additions and 1,502 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
- v1
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
Expand Down
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ edition = "2021"
repository = "https://github.com/netwo-io/apistos"
documentation = "https://docs.rs/apistos/"
license = "MIT OR Apache-2.0"
rust-version = "1.75"
rust-version = "1.77"
publish = true
version = "0.4.1"
version = "1.0.0-pre-release.9"

[workspace.dependencies]
actix-service = "2"
actix-web = "4"
actix-web-grants = "4"
actix-web-lab = "0.20"
actix-web-lab = "0.22"
assert-json-diff = "2.0.2"
convert_case = "0.6"
darling = "0.20"
Expand All @@ -41,21 +40,23 @@ md5 = "0.7.0"
once_cell = "1"
pin-project = "1"
proc-macro2 = "1.0"
proc-macro-error = "1.0"
proc-macro-error2 = "2.0"
quote = "1.0"
regex = ">=1.5.5"
schemars = { package = "apistos-schemars", version = "0.8", features = ["chrono", "uuid1", "url", "rust_decimal"] }
serde = "1"
schemars = { version = "1.0.0-alpha.15", features = ["chrono04", "uuid1", "url2", "rust_decimal1"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
syn = "2.0"

actix-multipart = "0.6"
garde-actix-web = "0.9"
actix-multipart = "0.7"
actix-web-grants = "4"
garde-actix-web = "0.10"
chrono = "0.4.20"
garde = { version = "0.20", features = ["derive", "serde"] }
ipnetwork = "0.20"
rust_decimal = "1"
serde_qs = "0.13"
shuttle-runtime = { version = "0.46", default-features = false }
shuttle-runtime = { version = "0.47", default-features = false }
uuid = { version = "1", features = ["serde", "v4"] }
url = "2"

Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ carpenters, craftsmen, metallurgy ... which can also be considered by some as th

```toml
[dependencies]
#schemars = "0.8"
# 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
schemars = { package = "apistos-schemars", version = "0.8" }
apistos = "0.4"
schemars = "1.0.0-alpha.14"
apistos = "1.0.0-pre-release.9"
```

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

### Feature flags

| name | description | extra dependencies |
|--------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------|
| `query` (default) | Enables documenting `actix_web::web::Query` | |
| `actix` (default) | Enables documenting types from `actix` | |
| `lab_query` | Enables documenting `actix_web_lab::extract::Query` | [`actix-web-lab`](https://crates.io/crates/actix-web-lab) |
| `garde` | Enables input validation through `garde` | [`garde`](https://crates.io/crates/garde) |
| `actix-web-grants` | Enables support for `actix-web-grants` | [`actix-web-grants`](https://crates.io/crates/actix-web-grants) |
| `rapidoc` | Enables RapiDoc to expose the generated openapi file | |
| `redoc` | Enables Redoc to expose the generated openapi file | |
| `swagger-ui` | Enables Swagger UI to expose the generated openapi file | |
| `qs_query` | Enables documenting types from `serde_qs` | [`serde_qs`](https://crates.io/crates/serde-qs) |
| `chrono` | Enables documenting types from `chrono` | [`chrono`](https://crates.io/crates/chrono) |
| `multipart` | Enables documenting types from `actix-multipart` | [`actix-multipart`](https://crates.io/crates/actix-multipart) |
| `rust_decimal` | Enables documenting types from `rust_decimal` | [`rust_decimal`](https://crates.io/crates/rust-decimal) |
| `uuid` | Enables documenting types from `uuid` | [`uuid`](https://crates.io/crates/uuid) |
| `url` | Enables documenting types from `url` | [`url`](https://crates.io/crates/url) |
| `extras` | Enables `chrono`, `multipart`, `rust_decimal`, `uuid` and `url` features | All from previous features |
| name | description | extra dependencies |
|--------------------|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| `query` (default) | Enables documenting `actix_web::web::Query` | |
| `actix` (default) | Enables documenting types from `actix` | |
| `lab_query` | Enables documenting `actix_web_lab::extract::Query` | [`actix-web-lab`](https://crates.io/crates/actix-web-lab) |
| `garde` | Enables input validation through `garde` | [`garde`](https://crates.io/crates/garde) |
| `actix-web-grants` | Enables support for `actix-web-grants` | [`actix-web-grants`](https://crates.io/crates/actix-web-grants) |
| `rapidoc` | Enables RapiDoc to expose the generated openapi file | |
| `redoc` | Enables Redoc to expose the generated openapi file | |
| `swagger-ui` | Enables Swagger UI to expose the generated openapi file | |
| `qs_query` | Enables documenting types from `serde_qs` | [`serde_qs`](https://crates.io/crates/serde-qs) |
| `chrono` | Enables documenting types from `chrono` | [`chrono`](https://crates.io/crates/chrono) |
| `ipnetwork` | Enables documenting types from `ipnetwork`. Supported via `apistos::ipnetwork` mod. | [`ipnetwork`](https://crates.io/crates/ipnetwork) |
| `multipart` | Enables documenting types from `actix-multipart`. `Tempfile` is supported though `apistos::multipart::Tempfile` struct. | [`actix-multipart`](https://crates.io/crates/actix-multipart) |
| `rust_decimal` | Enables documenting types from `rust_decimal` | [`rust_decimal`](https://crates.io/crates/rust-decimal) |
| `uuid` | Enables documenting types from `uuid` | [`uuid`](https://crates.io/crates/uuid) |
| `url` | Enables documenting types from `url` | [`url`](https://crates.io/crates/url) |
| `extras` | Enables `chrono`, `multipart`, `rust_decimal`, `uuid` and `url` features | All from previous features |

### What's next

Expand Down
24 changes: 15 additions & 9 deletions apistos-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@ rust-version.workspace = true
license.workspace = true

[dependencies]
pin-project = { workspace = true, optional = true }
log = { workspace = true }
pin-project = { workspace = true }
serde_json = { workspace = true }
schemars = { workspace = true }

actix-web = { workspace = true, optional = true }
actix-web-lab = { workspace = true, optional = true }
actix-web-grants = { workspace = true, optional = true }
actix-web-lab = { workspace = true, optional = true }
actix-multipart = { workspace = true, optional = true }
futures-core = { workspace = true, optional = true }
garde-actix-web = { workspace = true, optional = true }
chrono = { workspace = true, optional = true }
ipnetwork = { workspace = true, optional = true }
rust_decimal = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_qs = { workspace = true, features = ["actix4"], optional = true }
uuid = { workspace = true, optional = true }
url = { workspace = true, optional = true }

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

[dev-dependencies]
assert-json-diff = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }

[lints]
workspace = true

[features]
actix = ["dep:actix-web", "dep:pin-project"]
actix = ["dep:actix-web"]
actix-web-grants = ["dep:actix-web-grants"]

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

# extra types related features
chrono = ["dep:chrono", "schemars/chrono"]
multipart = ["actix", "dep:serde", "dep:actix-multipart"]
rust_decimal = ["dep:rust_decimal", "schemars/rust_decimal"]
chrono = ["dep:chrono", "schemars/chrono04"]
ipnetwork = ["dep:serde", "dep:ipnetwork"]
multipart = ["actix", "dep:serde", "dep:actix-multipart", "dep:futures-core"]
rust_decimal = ["dep:rust_decimal", "schemars/rust_decimal1"]
uuid = ["dep:uuid", "schemars/uuid1"]
url = ["dep:url", "schemars/url"]
extras = ["chrono", "multipart", "rust_decimal", "uuid", "url"]
url = ["dep:url", "schemars/url2"]
extras = ["chrono", "ipnetwork", "multipart", "rust_decimal", "uuid", "url"]

default = ["actix", "query"]
80 changes: 80 additions & 0 deletions apistos-core/src/__internal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use std::collections::BTreeMap;

use apistos_models::paths::{MediaType, Response, Responses};
use apistos_models::reference_or::ReferenceOr;
use apistos_models::{ApistosSchema, OpenApiVersion, VersionSpecificSchema};

pub fn response_from_schema(
oas_version: OpenApiVersion,
status: &str,
schema: Option<(String, ReferenceOr<ApistosSchema>)>,
) -> Option<Responses> {
schema.map(|(name, schema)| match schema {
ReferenceOr::Reference { _ref } => Responses {
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]),
..Default::default()
},
ReferenceOr::Object(sch) => {
let schema = match oas_version {
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(ReferenceOr::Reference {
_ref: format!("#/components/schemas/{}", name),
}),
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch),
};
let response = Response {
content: BTreeMap::from_iter(vec![(
"application/json".to_string(),
MediaType {
schema: Some(schema),
..Default::default()
},
)]),
..Default::default()
};
Responses {
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]),
..Default::default()
}
}
})
}

pub fn response_from_raw_schema(
oas_version: OpenApiVersion,
status: &str,
raw_schema: Option<ReferenceOr<ApistosSchema>>,
) -> Option<Responses> {
raw_schema.map(|schema| match schema {
ReferenceOr::Reference { _ref } => Responses {
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Reference { _ref })]),
..Default::default()
},
ReferenceOr::Object(sch) => {
let schema = match oas_version {
OpenApiVersion::OAS3_0 => VersionSpecificSchema::OAS3_0(sch.into()),
OpenApiVersion::OAS3_1 => VersionSpecificSchema::OAS3_1(sch),
};
let response = Response {
content: BTreeMap::from_iter(vec![(
"application/json".to_string(),
MediaType {
schema: Some(schema),
..Default::default()
},
)]),
..Default::default()
};
Responses {
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(response))]),
..Default::default()
}
}
})
}

pub fn response_for_status(status: &str) -> Responses {
Responses {
responses: BTreeMap::from_iter(vec![(status.to_string(), ReferenceOr::Object(Default::default()))]),
..Default::default()
}
}
Loading

0 comments on commit cf40515

Please sign in to comment.