-
-
Notifications
You must be signed in to change notification settings - Fork 1
Native openapi #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native openapi #73
Conversation
Deleted all benchmark server crates, micro-benchmarks, and related files from the benches directory. Updated Cargo.toml to comment out benchmark members. This reduces workspace complexity and removes external benchmark dependencies.
Refactored OpenAPI schema handling to inline simple types (primitives, empty objects, enums) instead of always referencing components in rustapi-core. Updated the OpenAPI demo example to a minimal hello world, and added a 'Zero-Config OpenAPI' recipe to the documentation. Documentation and summary files were updated to reflect the new recipe and modern usage patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request removes benchmark servers/micro-benchmarks from the workspace and introduces a “native” OpenAPI path by replacing utoipa-centric schema handling with first-party Schema/ToSchema/IntoParams types and derive macros, alongside related docs updates.
Changes:
- Removed benchmark crates, scripts, and docs; commented out benchmark members in the workspace.
- Added a native OpenAPI schema model (
schema.rs) and updated response/extractor modifiers to use structured schemas instead of JSON blobs. - Added new
ToSchemaandIntoParamsderive macros and introduced cookbook documentation for zero-config OpenAPI.
Reviewed changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/cookbook/src/recipes/zero_config_openapi.md | New recipe documenting macro-based auto OpenAPI generation. |
| docs/cookbook/src/recipes/crud_resource.md | Updates recipe to use RustApi::auto() (example snippet currently malformed). |
| docs/cookbook/src/crates/rustapi_openapi.md | Adds link to the new zero-config OpenAPI recipe. |
| docs/cookbook/src/SUMMARY.md | Adds the new recipe to the cookbook navigation. |
| crates/rustapi-view/src/view.rs | Switches HTML schema from inline JSON to structured Schema. |
| crates/rustapi-toon/src/negotiate.rs | Switches response schemas from inline JSON to structured Schema. |
| crates/rustapi-toon/src/llm_response.rs | Switches response schemas from inline JSON to structured Schema. |
| crates/rustapi-toon/src/extractor.rs | Switches request/response schemas from inline JSON to structured Schema. |
| crates/rustapi-rs/examples/openapi_demo.rs | Adds an OpenAPI demo example (currently references utoipa in the example). |
| crates/rustapi-openapi/src/v31/spec.rs | Updates OpenAPI 3.1 schema registration to use crate::ToSchema. |
| crates/rustapi-openapi/src/spec.rs | Replaces JSON-value schemas with RefOr<Schema>, adds ParameterIn, and updates registration APIs. |
| crates/rustapi-openapi/src/schemas.rs | Drops utoipa derives and adds manual ToSchema impls for error schemas. |
| crates/rustapi-openapi/src/schema.rs | New native schema model + primitive ToSchema implementations. |
| crates/rustapi-openapi/src/lib.rs | Exposes new schema module and removes utoipa re-exports from the public API. |
| crates/rustapi-openapi/Cargo.toml | Removes utoipa dependency; adds optional uuid feature/dependency. |
| crates/rustapi-macros/src/schema.rs | New #[derive(ToSchema)] proc-macro implementation. |
| crates/rustapi-macros/src/params.rs | New #[derive(IntoParams)] proc-macro implementation. |
| crates/rustapi-macros/src/lib.rs | Wires up new derive macros; schema attribute docs still reference utoipa/Schema. |
| crates/rustapi-core/src/sse.rs | Switches SSE schema from inline JSON to structured Schema. |
| crates/rustapi-core/src/response.rs | Migrates response schema handling to ToSchema + RefOr<Schema>. |
| crates/rustapi-core/src/extract.rs | Migrates extractor OpenAPI modifiers to ToSchema/IntoParams + structured schemas. |
| crates/rustapi-core/src/app.rs | Migrates path param schema inference to structured schemas; test messages/comments need cleanup. |
| benches/toon_bench/src/lib.rs | Removed benchmark placeholder crate file. |
| benches/toon_bench/benches/toon_bench.rs | Removed TOON benchmarks. |
| benches/toon_bench/Cargo.toml | Removed TOON benchmark crate manifest. |
| benches/test_body.json | Removed benchmark fixture. |
| benches/rustapi_bench/src/lib.rs | Removed benchmark placeholder crate file. |
| benches/rustapi_bench/benches/websocket_bench.rs | Removed WebSocket benchmarks. |
| benches/rustapi_bench/benches/middleware_bench.rs | Removed middleware benchmarks. |
| benches/rustapi_bench/benches/extractor_bench.rs | Removed extractor benchmarks. |
| benches/rustapi_bench/Cargo.toml | Removed RustAPI benchmark crate manifest. |
| benches/run_benchmarks.ps1 | Removed benchmark runner script. |
| benches/routing_bench.rs | Removed routing micro-benchmarks. |
| benches/json_bench.rs | Removed JSON micro-benchmarks. |
| benches/bench_server/src/main.rs | Removed RustAPI benchmark server. |
| benches/bench_server/Cargo.toml | Removed RustAPI benchmark server manifest. |
| benches/actix_bench_server/src/main.rs | Removed Actix benchmark server. |
| benches/actix_bench_server/Cargo.toml | Removed Actix benchmark server manifest. |
| benches/README.md | Removed benchmark documentation. |
| Cargo.toml | Comments out benchmark workspace members. |
| Cargo.lock | Removes dependencies pulled in by deleted benchmark crates and utoipa usage. |
Comments suppressed due to low confidence (2)
crates/rustapi-macros/src/lib.rs:75
- The
#[rustapi_rs::schema]docs still refer to derivingSchemafromutoipa::ToSchemaand the example uses#[derive(Serialize, Schema)]. With the new native schema system andToSchemaderive, this documentation is now outdated and likely confuses users about which derive macro/trait to use.
/// Auto-register a schema type for zero-config OpenAPI.
///
/// Attach this to a `struct` or `enum` that also derives `Schema` (utoipa::ToSchema).
/// This ensures the type is registered into RustAPI's OpenAPI components even if it is
/// only referenced indirectly (e.g. as a nested field type).
///
/// ```rust,ignore
/// use rustapi_rs::prelude::*;
///
/// #[rustapi_rs::schema]
/// #[derive(Serialize, Schema)]
/// struct UserInfo { /* ... */ }
crates/rustapi-core/src/app.rs:1248
- The comment
// Integer patternsis duplicated back-to-back, which looks like an accidental copy/paste. Please remove the extra line.
// Integer patterns
// Integer patterns
let is_integer = lower == "page"
| // In main.rs | ||
| RustApi::auto() // Automatic registration! | ||
| .run("127.0.0.1:8080") | ||
| .await? | ||
|
|
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code snippet is no longer valid Rust as written: it contains a bare chain ending with .await? outside of any async main/function, and the ? requires a compatible Result return type. Consider showing a complete #[tokio::main] async fn main() -> Result<...> example (or drop the ? and show .await).
| //! ## Run | ||
| //! ```bash | ||
| //! cargo run -p hello-world | ||
| //! ``` |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run instructions in the doc comment appear incorrect for an example target: cargo run -p hello-world doesn’t match this file’s location/name. Consider updating to the standard Cargo example invocation used elsewhere in this crate (e.g., cargo run -p rustapi-rs --example openapi_demo).
| rustapi_openapi::SchemaRef::T(s) => { | ||
| assert_eq!(s.schema_type, Some(SchemaType::String)); | ||
| assert_eq!(s.format, Some("uuid".to_string())); | ||
| } | ||
| _ => panic!("Expected inline schema for uuid"), | ||
| } |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These panic messages still say “Expected inline schema …”, but the match arms now expect SchemaRef::T(...). Updating the messages will make failures clearer and avoid confusion during debugging.
| use rustapi_rs::prelude::*; | ||
| use serde::Serialize; | ||
|
|
||
| #[derive(Serialize, utoipa::ToSchema)] | ||
| struct Message { |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example references utoipa::ToSchema, but the crate is moving toward the native ToSchema derive provided by RustAPI. Using utoipa here makes the example inconsistent with the rest of the docs and can mislead users about which derive to use.
| } | ||
|
|
||
| /// Convert a schema type string to an OpenAPI schema reference | ||
| /// Convert a schema type string to an OpenAPI schema reference |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a duplicated doc comment line here (same sentence repeated twice). Please remove the duplicate to keep docs clean.
| /// Convert a schema type string to an OpenAPI schema reference |
| let schema_ref = match ref_or_schema { | ||
| SchemaRef::Ref(r) => SchemaRef::Ref(r), | ||
| SchemaRef::T(s) => { | ||
| let should_inline = match s.schema_type { | ||
| Some(rustapi_openapi::schema::SchemaType::Array) | ||
| | Some(rustapi_openapi::schema::SchemaType::Boolean) | ||
| | Some(rustapi_openapi::schema::SchemaType::Integer) | ||
| | Some(rustapi_openapi::schema::SchemaType::Number) | ||
| | Some(rustapi_openapi::schema::SchemaType::String) => true, | ||
| Some(rustapi_openapi::schema::SchemaType::Object) => { | ||
| s.properties.as_ref().map_or(true, |p| p.is_empty()) | ||
| && s.enum_values.as_ref().map_or(true, |e| e.is_empty()) | ||
| } | ||
| None => true, | ||
| }; |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The should_inline heuristic (match on SchemaType + object property checks) is repeated in multiple places (e.g., ValidatedJson<T>, Json<T>, Created<T>). Consider extracting this into a shared helper (e.g., in rustapi_openapi or a local fn) to avoid divergence and make future schema decisions consistent.
Refactored the 401 Unauthorized response in AuthUser's OperationModifier to use the new Reference struct for schema references. Also added a use statement for rustapi_openapi::schema::Reference. Added initial release notes for RustAPI 0.2.0.
This pull request removes all RustAPI and Actix-web HTTP benchmark servers and related micro-benchmarks from the repository. The change eliminates both the code and documentation for these benchmarks, as well as their references in the workspace configuration.
Removal of HTTP Benchmark Servers and Workspace References:
bench-server(RustAPI) andactix-bench-server(Actix-web) benchmark servers, including theirCargo.tomlfiles and all source code (benches/bench_server/Cargo.toml,benches/bench_server/src/main.rs,benches/actix_bench_server/Cargo.toml,benches/actix_bench_server/src/main.rs). [1] [2] [3] [4]Cargo.tomlto comment out the benchmark server crates, removing them from the workspace build.Removal of Micro-benchmarks:
benches/routing_bench.rs,benches/json_bench.rs). [1] [2]Documentation Cleanup:
benches/README.md.