fastapi_openapi/lib.rs
1//! OpenAPI 3.1 types and schema generation.
2//!
3//! This crate provides:
4//!
5//! - OpenAPI 3.1 document types
6//! - JSON Schema types
7//! - `JsonSchema` trait for compile-time schema generation
8//!
9//! # Role In The System
10//!
11//! `fastapi-openapi` owns the OpenAPI 3.1 and JSON Schema data model. It is
12//! fed by metadata emitted from `fastapi-macros` and by runtime route info from
13//! `fastapi-core`/`fastapi-router`. The resulting spec is then exposed through
14//! the `fastapi` facade so applications can serve or export documentation.
15//!
16//! # Example
17//!
18//! ```ignore
19//! use fastapi_openapi::{OpenApiBuilder, JsonSchema};
20//!
21//! #[derive(JsonSchema)]
22//! struct Item {
23//! id: i64,
24//! name: String,
25//! }
26//!
27//! let spec = OpenApiBuilder::new("My API", "1.0.0")
28//! .route(&get_items_route())
29//! .build();
30//! ```
31
32#![forbid(unsafe_code)]
33// Pedantic clippy lints allowed (style suggestions, not correctness issues)
34#![allow(clippy::uninlined_format_args)]
35#![allow(clippy::single_match)]
36#![allow(clippy::must_use_candidate)]
37#![allow(clippy::len_zero)]
38#![allow(clippy::single_match_else)]
39#![allow(clippy::needless_pass_by_value)]
40#![allow(clippy::needless_borrow)]
41#![allow(clippy::field_reassign_with_default)]
42#![allow(clippy::trivially_copy_pass_by_ref)]
43
44mod schema;
45mod spec;
46
47pub use schema::{
48 ArraySchema, ConstSchema, Discriminator, EnumSchema, JsonSchema, ObjectSchema, PrimitiveSchema,
49 RefSchema, Schema, SchemaRegistry, SchemaType, StringEnumSchema,
50};
51pub use spec::{
52 // Security types
53 ApiKeyLocation,
54 // Core document types
55 Components,
56 Example,
57 HasParamMeta,
58 Info,
59 MediaType,
60 OAuth2Flow,
61 OAuth2Flows,
62 OpenApi,
63 OpenApiBuilder,
64 Operation,
65 ParamMeta,
66 Parameter,
67 ParameterLocation,
68 PathItem,
69 RequestBody,
70 Response,
71 SecurityRequirement,
72 SecurityScheme,
73 Server,
74 Tag,
75 // Path parameter generation
76 converter_to_schema,
77 param_info_to_parameter,
78 path_params_to_parameters,
79};