Skip to content

Commit 7d55b91

Browse files
gaspbsiku2jayvdbDrifter-Jqarmin
authored
Add OpenAPI 3.2 support with webhooks and enhanced components (#6)
* fix: simplify utoipa-gen feature gates to fix jiff_0_2 (juhaku#1575) fix: simplify utoipa-gen feature gates to fix jiff_0_2 Enabling the "jiff_0_2" feature on its own would not correctly enable the more elaborate is_primitive branch because it was mistakenly omitted from the feature gate list. Rather than merely fixing the feature gate list, this commit simplifies the logic to make such a mistake impossible in the future. * fix: workaround time/cookie incompatibility (juhaku#1577) * fix: workaround time/cookie incompatibility * Also fix examples * fix: emit vec![] instead of array literals to avoid large stack arrays (juhaku#1580) * Fix stack overflow * fix: emit vec![] instead of array literals to avoid large stack arrays Wide structs/enums generated huge `[..]` array literals in ToSchema/IntoParams, tripping clippy::large_stack_arrays and overflowing the stack. Make the Array tokenizer emit vec![] and deny the lint so it doesn't regress again (juhaku#1454). * chore: not really testing so just smoke test --------- Co-authored-by: Rafał Mikrut <mikrutrafal@protonmail.com> Co-authored-by: Jaye Park <jaye.park@helsing.ai> * Add OpenAPI 3.2 support (juhaku#1555) * Add OpenAPI 3.2 support * Fix OpenAPI 3.2 CI failures * ci: re-trigger build after upstream time 0.3.48 yank The 2026-06-12 CI run resolved time 0.3.48 (the repo intentionally does not commit a root Cargo.lock, so CI takes the latest deps). time 0.3.48 shipped an E0119 trait-coherence regression that broke the cookie crate, failing the utoipa-gen and examples jobs (and cancelling utoipa via fail-fast). time 0.3.48 has since been yanked and 0.3.49 published. This empty commit re-runs CI to pick up the fixed resolution; verified locally that the full utoipa-gen matrix and example compilation pass with time 0.3.49. * Address review feedback on OpenAPI 3.2 support - Keep `Version31` as the default OpenApiVersion; `Version32` is now opt-in (no deprecation). Reverts the default-output version back to 3.1.0 so the change is non-breaking until 3.2 tooling support is widespread. - Add `OpenApiBuilder::openapi(..)` so 3.2 output can be opted into. - Rename `self_url` field/builder to `self_uri` to match the spec wording. - Simplify `OpenApiVersion` deserialize with slice `matches!` patterns. - Drop redundant non-empty check when merging `additional_operations`. - Use `RefOr::T(parameter.into())` instead of the double `.into().into()`. - Tidy `HttpBuilder::deprecated` formatting. - Revert the actix `#[utoipa::path]` doc examples from `rust,ignore` back to `rust` (they pass under the `actix_extras` feature CI runs). * docs: add examples and changelog for PR-1555 (juhaku#1590) * docs: add examples and changelog * test: fix empty description being omitted * chore: change parameters to refs * feat: support generic types with `IntoParams` (juhaku#1588) * add example for IntoParams with generic argument * add automated test * working example of generic params it breaks everything else which is a bummer * fix implementation with into_params * update unit tests to pin behavior * minor code cleaning * remove example code I assume a reviewer might call this superfluous. This code was useful for testing locally. * shorten code * fix warning * add basic changelog * feat(gen): allow opting into OpenAPI 3.2 output via the version attribute (juhaku#1591) * feat(gen): support item_schema attribute for streaming/SSE response types (juhaku#1592) * feat(gen): support item_schema attribute for streaming/SSE response types * chore: update sse example to use programmatic openapi 3.2 version mapping * chore: use openapi version attribute As juhaku#1591 is merged, I can remove `api.openapi = utoipa::openapi::OpenApiVersion::Version32;` from the example to replace with `#[openapi(version = "3.2.0", components(schemas(PetEvent)))]`. * Recursively discover flattened fields in maps (juhaku#1582) * Recursively discover flattened fields in maps This allows the discovered fields to appear in component.schemas without having to explicitly list it as a workaround. Fixes juhaku#1330 * Use assert_value * Apply suggestion from @CommanderStorm Co-authored-by: Frank Elsinga <frank@elsinga.de> --------- Co-authored-by: Frank Elsinga <frank@elsinga.de> * Refactor documentation in lib.rs (juhaku#1581) Updated documentation comments to remove commented-out code. * chore: Update CHANGELOG.md (juhaku#1596) Add the following entry in utoipa-gen/CHANGELOG.md * Recursively discover flattened fields in maps for `#[serde(flatten)]`. (juhaku#1582) * Bump base64 from 22.1 to 23.1 (juhaku#1595) * Upgrade utoipa-gen to syn 3 (juhaku#1597) * feature: support extensions in utoipa::ToSchema named structs (juhaku#1593) * Re-enable actix auto_into_responses Result test (juhaku#1603) The test was commented out as failing to compile. It was missing imports, and the justfile did not enable `utoipa/auto_into_responses`, which gates the `IntoResponses` impl for `Result<T, E>`. * Update next release versions (juhaku#1618) * Remove support for expression ignore in `ToSchema` and `IntoParams` (juhaku#1619) This commit removes support for expression style ignore attribute from `ToSchema` and `IntoParams` macro. This is to fix issue where ignore sometimes did not ignore values, because it was evaluated in runtime and function reference ignore can be evaluated only during runtime but we need to evaluate this at build time thus removing the possibility to define function reference as ignore attribute value. ## Breaking Following syntax demonstrates what was allowed before, but will be not available in new version 6. ```rust // before allowed fn ignore_always() -> bool { true } #[derive(ToSchema)] struct Value { #[schema(ignore = ignore_always)] field: String } ``` * Fix publish crate version bash substitution pattern * Fix min properties schema generation (juhaku#1623) This bug has been around since `utoipa-gen 5.1.3` where the `#[schema(min_properties=...)]` gets generated as `max_properties` attribute. Closes juhaku#1622 * Fix utoipa-swagger-ui build (juhaku#1624) Utoipa-swagger-ui build failed to build with `cache` feature on because sha2 crate had updated its `generic-array` to `hybrid-array` dependency breaking the existing implementation hex formatting. More details here: RustCrypto/hybrid-array#201 * Fix unsigned integer known format serialization (juhaku#1554) Fix unsigned integers know format serialization. They used falsely `kebab-case` instead of `lowercase`. Now type like `UInt16` will render `uint16` instead of `u-int16`. --------- Co-authored-by: Juha Kukkonen <juha7kukkonen@gmail.com> * Accept `expr` for attr for `title` and `names` (juhaku#1524) Implements rust expression support for `names` and `title` attributes: ```rust const STRUCT_TITLE: &str = "Post Title"; let schema = api_doc! { #[schema(title = STRUCT_TITLE)] struct Post { id: i64, description: String, } }; const NEW_NAME: &str = "renamed_field"; #[derive(IntoParams)] #[into_params(parameter_in = Path, names(NEW_NAME))] struct Filter( #[allow(unused)] (), ); ``` --------- Co-authored-by: Juha Kukkonen <juha7kukkonen@gmail.com> * Fix format * Add missing utoipa-gen snapshots for rename-expression derives (juhaku#1625) Add missing snapshots for `utoipa-gen` test using newly supported expression in title and name. ```rust const NEW_NAME: &str = "renamed_field"; #[derive(IntoParams)] #[into_params(parameter_in = Path, names(NEW_NAME))] struct Filter(()); ``` --------- Co-authored-by: juhaku <26358664+juhaku@users.noreply.github.com> * Mark Option fields with deserialize_with as required (juhaku#1627) Serde only treats a missing Option field as None when the field has no deserialize_with or with attribute. With one of those and no default, a missing field is an error, so ToSchema and IntoParams should list the field as required. It stays nullable. * Support `merge` in `OpenApi` derive (juhaku#1628) Add support for `merge` in `OpenApi` derive Keep nest and merge as separate derive attributes, but parse their common api and tags arguments through OpenApiReference. List merge in the unexpected-attribute diagnostic and cover merge precedence in tests. --------- Co-authored-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> --------- Co-authored-by: Simon <simon@siku2.io> Co-authored-by: John Vandenberg <jayvdb@gmail.com> Co-authored-by: Jaye <latenytcoffee@gmail.com> Co-authored-by: Rafał Mikrut <mikrutrafal@protonmail.com> Co-authored-by: Jaye Park <jaye.park@helsing.ai> Co-authored-by: Paweł Jankiewicz <p.jankiewicz@gmail.com> Co-authored-by: Jack Ullery <46848683+jack-ullery@users.noreply.github.com> Co-authored-by: Nipunn Koorapati <nipunn1313@gmail.com> Co-authored-by: Frank Elsinga <frank@elsinga.de> Co-authored-by: n4n5 <git@n4n5.dev> Co-authored-by: Tom <1955774+tdelmas@users.noreply.github.com> Co-authored-by: Jakob Hellermann <jakob.hellermann@protonmail.com> Co-authored-by: Til Blechschmidt <til@blechschmidt.de> Co-authored-by: Mattias Eriksson <6420639+snaggen@users.noreply.github.com> Co-authored-by: Juha Kukkonen <juha7kukkonen@gmail.com> Co-authored-by: Mukunda Rao Katta <mukunda.vjcs6@gmail.com> Co-authored-by: Omid Rad <omid@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: juhaku <26358664+juhaku@users.noreply.github.com> Co-authored-by: Max Azatian <66359507+HardMax71@users.noreply.github.com> Co-authored-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com>
1 parent 35249a1 commit 7d55b91

133 files changed

Lines changed: 3625 additions & 595 deletions

File tree

Some content is hidden

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

‎.github/actions/publish/publish.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fi
4242
echo "$token" | cargo login
4343
while read -r module; do
4444
# crate=$(echo "$ref" | sed 's|-[0-9]*\.[0-9]*\.[0-9].*||')
45-
crate=${ref/-[0-9]\.[0-9]\.[0-9]*/}
45+
crate=${ref/-[0-9]*\.[0-9]*\.[0-9]*/}
4646
if [[ "$crate" != "$module" ]]; then
4747
echo "Module: $module does not match to release crate: $crate, skipping release for module"
4848
continue

‎Cargo.toml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ members = [
1616
"utoipa-actix-web",
1717
]
1818

19+
# cookie 0.18.1 (via rocket_http) does not compile against time 0.3.52+
20+
# (Parsable::parse gained a defaults argument). Cap until cookie releases a fix.
21+
# Keeps `just test` / fresh resolves working without committing Cargo.lock.
22+
[workspace.dependencies]
23+
time = { version = ">=0.3, <0.3.52" }
24+
25+
[workspace.lints.rust]
26+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }
27+
28+
[workspace.lints.clippy]
29+
# Enforced to guard against regressions of large stack allocations in generated
30+
# code (see https://github.com/juhaku/utoipa/issues/1454).
31+
large_stack_arrays = "deny"
32+
1933
# Crates published to crates.io under the meteroid-oss fork, in dependency order.
2034
# The core three (`-config`, `-gen`, `meteroid-utoipa`) carry the fork's custom
2135
# features (e.g. `tagged_discriminator`); `-axum` and `-scalar` are the framework

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Add dependency declaration to `Cargo.toml`.
138138

139139
```toml
140140
[dependencies]
141-
utoipa = "5"
141+
utoipa = "6"
142142
```
143143

144144
## Examples

‎RELEASING.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ This fork publishes five crates to crates.io, in dependency order:
44

55
| crates.io name | path | import as (unchanged) | version |
66
| ------------------------ | ---------------- | --------------------- | ------- |
7-
| `meteroid-utoipa-config` | `utoipa-config/` | `utoipa_config` | 0.1.2 |
8-
| `meteroid-utoipa-gen` | `utoipa-gen/` | `utoipa_gen` | 5.6.0 |
9-
| `meteroid-utoipa` | `utoipa/` | `utoipa` | 5.6.0 |
10-
| `meteroid-utoipa-axum` | `utoipa-axum/` | `utoipa_axum` | 0.2.0 |
11-
| `meteroid-utoipa-scalar` | `utoipa-scalar/` | `utoipa_scalar` | 0.3.0 |
7+
| `meteroid-utoipa-config` | `utoipa-config/` | `utoipa_config` | 0.1.3 |
8+
| `meteroid-utoipa-gen` | `utoipa-gen/` | `utoipa_gen` | 6.0.0 |
9+
| `meteroid-utoipa` | `utoipa/` | `utoipa` | 6.0.0 |
10+
| `meteroid-utoipa-axum` | `utoipa-axum/` | `utoipa_axum` | 0.3.0 |
11+
| `meteroid-utoipa-scalar` | `utoipa-scalar/` | `utoipa_scalar` | 0.4.0 |
1212

1313
The crates.io **package** names are prefixed with `meteroid-`, but the **library**
1414
names are kept (`utoipa`, `utoipa_gen`, `utoipa_config`, `utoipa_axum`,
1515
`utoipa_scalar`). Downstream code therefore stays a drop-in with upstream:
1616

1717
```toml
1818
[dependencies]
19-
meteroid-utoipa = "5"
19+
meteroid-utoipa = "6"
2020
```
2121

2222
```rust
@@ -67,9 +67,9 @@ you probably forgot to bump the `Cargo.toml` version(s).
6767

6868
The crates have different versions, but you only pick **one** tag, and it's
6969
just a trigger — it does not decide what gets published (that comes from each
70-
crate's `Cargo.toml`). Use the **`meteroid-utoipa` version**, e.g. `v5.6.0`. That
70+
crate's `Cargo.toml`). Use the **`meteroid-utoipa` version**, e.g. `v6.0.0`. That
7171
is the crate you and downstream depend on, so the release *is* "meteroid-utoipa
72-
5.6.0". The others ride along automatically:
72+
6.0.0". The others ride along automatically:
7373

7474
- `meteroid-utoipa-gen` moves **in lockstep** with `meteroid-utoipa` (same number —
7575
the derive-macro crate and its runtime are a matched pair), so it is covered.
@@ -87,11 +87,11 @@ are independent of upstream `utoipa` — there is no collision on crates.io. Bum
8787
only the crates that carry a change of the fork's own (versus upstream
8888
juhaku/utoipa):
8989

90-
- `meteroid-utoipa-gen` and `meteroid-utoipa` currently diverge from upstream 5.5.0
91-
by two opt-in, backward-compatible features (`tagged_discriminator` and flatten
92-
support in `IntoParams`), hence the minor bump to **5.6.0**.
93-
- `meteroid-utoipa-config` is unchanged from upstream, so it stays at **0.1.2**.
94-
- `meteroid-utoipa-axum` (**0.2.0**) and `meteroid-utoipa-scalar` (**0.3.0**) are
90+
- `meteroid-utoipa-gen` and `meteroid-utoipa` track upstream 6.0.0 plus two opt-in,
91+
backward-compatible features (`tagged_discriminator` and flatten support in
92+
`IntoParams`), and are published as **6.0.0**.
93+
- `meteroid-utoipa-config` is unchanged from upstream, so it matches it at **0.1.3**.
94+
- `meteroid-utoipa-axum` (**0.3.0**) and `meteroid-utoipa-scalar` (**0.4.0**) are
9595
the framework bindings, unchanged from upstream; they only depend on the renamed
9696
core. Bump them when their own `Cargo.toml` changes.
9797

‎examples/actix-web-multipart/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
# cookie (actix/rocket) does not build with time 0.3.52+; drop when cookie is fixed
8+
time = { version = ">=0.3, <0.3.52" }
79
actix-web = "4"
810
actix-multipart = "0.7"
911
utoipa = { path = "../../utoipa", features = ["actix_extras"] }

‎examples/actix-web-multiple-api-docs-with-scopes/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ authors = [
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14+
# cookie (actix/rocket) does not build with time 0.3.52+; drop when cookie is fixed
15+
time = { version = ">=0.3, <0.3.52" }
1416
actix-web = "4"
1517
serde = { version = "1.0", features = ["derive"] }
1618
env_logger = "0.11.0"

‎examples/actix-web-scopes-binding/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ version = "0.1.0"
55
edition = "2021"
66

77
[dependencies]
8+
# cookie (actix/rocket) does not build with time 0.3.52+; drop when cookie is fixed
9+
time = { version = ">=0.3, <0.3.52" }
810
actix-web = "4"
911
serde = { version = "1.0", features = ["derive"] }
1012
env_logger = "0.11.0"

‎examples/generics-actix/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ authors = [
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14+
# cookie (actix/rocket) does not build with time 0.3.52+; drop when cookie is fixed
15+
time = { version = ">=0.3, <0.3.52" }
1416
actix-web = "4"
1517
env_logger = "0.10.0"
1618
geo-types = { version = "0.7", features = ["serde"] }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "openapi-3_2-sse"
3+
description = "Axum example documenting a Server-Sent Events (SSE) endpoint using OpenAPI 3.2"
4+
version = "0.1.0"
5+
edition = "2021"
6+
license = "MIT"
7+
authors = ["Drifter-J <latenytcoffee@gmail.com>"]
8+
9+
[dependencies]
10+
axum = "0.8.0"
11+
futures-util = "0.3"
12+
serde = { version = "1", features = ["derive"] }
13+
serde_json = "1"
14+
tokio = { version = "1.17", features = ["full"] }
15+
tokio-stream = "0.1"
16+
utoipa = { path = "../../utoipa", features = ["axum_extras", "uuid"] }
17+
utoipa-axum = { path = "../../utoipa-axum" }
18+
utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["axum"] }
19+
uuid = { version = "1", features = ["serde", "v4"] }
20+
rand = "0.8"
21+
22+
[workspace]

‎examples/openapi-3_2-sse/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# openapi-3_2-sse
2+
3+
This example demonstrates documenting a Server-Sent Events endpoint using `utoipa`'s
4+
OpenAPI 3.2 support: opting in to `openapi: "3.2.0"` output and describing the
5+
`text/event-stream` response with the new `itemSchema` media type keyword.
6+
7+
Run with:
8+
```bash
9+
cargo run
10+
```
11+
12+
Then either:
13+
14+
- Browse to `http://localhost:8080/swagger-ui/` to inspect the generated OpenAPI 3.2 document, or
15+
- Stream events directly with `curl -N http://localhost:8080/pets/events`

0 commit comments

Comments
 (0)