Skip to main content

reinhardt_rest/
lib.rs

1//! # Reinhardt REST
2//!
3//! **Unified REST API framework** for Reinhardt.
4//!
5//! This crate provides a complete REST API framework by integrating:
6//! - **Serializers**: Data serialization and validation (from reinhardt-serializers)
7//! - **Parsers**: Request body parsing (from reinhardt-parsers)
8//! - **Authentication**: JWT, Token, Session, Basic auth (from reinhardt-auth)
9//! - **Routers**: Automatic URL routing for ViewSets (from reinhardt-routers)
10//! - **Browsable API**: HTML interface for API exploration (from reinhardt-browsable-api)
11//!
12//! ## Features
13//!
14//! - **default**: Enables serializers and parsers
15//! - **serializers**: Data serialization and validation components
16//! - **parsers**: Request body parsing (JSON, Form, Multipart)
17//!
18//! ## Example
19//!
20//! ```rust
21//! use reinhardt_rest::parsers::JSONParser;
22//!
23//! // Create a JSON parser
24//! let parser = JSONParser::new();
25//! ```
26//!
27//! For router integration, see [`reinhardt_urls::routers`](reinhardt_urls::routers) crate.
28//!
29//! ## Testing
30//!
31//! This crate contains unit tests for the integrated modules.
32//! Integration tests are located in `tests/integration/`.
33
34pub mod browsable_api;
35pub mod filters;
36pub mod metadata;
37pub mod serializers;
38pub mod throttling;
39pub mod versioning;
40
41// Re-export internal crates (2024 edition module system)
42// These modules represent the internal crates that are now part of reinhardt-rest
43
44// Parsers module - now part of reinhardt-rest
45#[cfg(feature = "parsers")]
46pub use reinhardt_core::parsers;
47
48// Re-export other internal crates
49pub use reinhardt_core::negotiation;
50pub use reinhardt_core::pagination;
51
52// Core modules (merged from rest-core)
53pub mod authentication;
54pub mod response;
55// NOTE: routers module removed to avoid circular dependency with reinhardt-urls
56// Use reinhardt-urls::routers directly instead
57
58#[cfg(feature = "openapi")]
59pub mod schema;
60
61// Re-export authentication types
62pub use authentication::{
63	AllowAny, AnonymousUser, AuthBackend, AuthResult, IsAdminUser, IsAuthenticated,
64	IsAuthenticatedOrReadOnly, Permission, SimpleUser, User,
65};
66
67// Re-export JWT types conditionally
68#[cfg(feature = "jwt")]
69pub use authentication::{Claims, JwtAuth};
70
71// Re-export response types
72pub use response::{ApiResponse, IntoApiResponse, PaginatedResponse, ResponseBuilder};
73
74// Re-export from specialized crates
75pub use crate::browsable_api::*;
76
77// Re-export integrated modules at top level for convenience
78#[cfg(feature = "serializers")]
79pub use crate::serializers::{
80	ContentNegotiator, Deserializer, JsonSerializer, ModelSerializer, Serializer, SerializerError,
81	UniqueTogetherValidator, UniqueValidator,
82};
83
84#[cfg(feature = "parsers")]
85pub use reinhardt_core::parsers::{
86	FileUploadParser, FormParser, JSONParser, MediaType, MultiPartParser, ParseError, ParseResult,
87	Parser,
88};
89
90// OpenAPI module - integrated from former reinhardt-openapi subcrate
91#[cfg(feature = "openapi")]
92pub mod openapi;
93
94// Re-export commonly used OpenAPI types
95#[cfg(feature = "openapi")]
96pub use crate::openapi::{
97	ComponentsExt, EnumSchemaBuilder, EnumTagging, Info, OpenApiSchema, Operation, Parameter,
98	ParameterLocation, PathItem, RequestBody, Response, Schema, SchemaExt, SchemaGenerator,
99	SchemaRegistry, Server, ToSchema,
100};
101
102// Re-export builders
103#[cfg(feature = "openapi")]
104pub use crate::openapi::openapi::{
105	ArrayBuilder, ComponentsBuilder, InfoBuilder, ObjectBuilder, OpenApiBuilder, OperationBuilder,
106	ParameterBuilder, PathItemBuilder, PathsBuilder, RequestBodyBuilder, ResponsesBuilder,
107	ServerBuilder, TagBuilder,
108};
109
110// Re-export OpenAPI ResponseBuilder with alias to avoid conflict with rest_core::ResponseBuilder
111#[cfg(feature = "openapi")]
112pub use crate::openapi::openapi::ResponseBuilder as OpenApiResponseBuilder;
113
114// Re-export UI components
115#[cfg(feature = "openapi")]
116pub use crate::openapi::swagger::SwaggerUI;
117
118#[cfg(test)]
119mod tests {
120	#[test]
121	fn test_serializers_module_available() {
122		#[cfg(feature = "serializers")]
123		{
124			use crate::JsonSerializer;
125			use serde::{Deserialize, Serialize};
126
127			#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
128			struct TestData {
129				name: String,
130			}
131
132			let _serializer = JsonSerializer::<TestData>::new();
133		}
134	}
135
136	#[test]
137	fn test_parsers_module_available() {
138		#[cfg(feature = "parsers")]
139		{
140			use crate::JSONParser;
141			let _parser = JSONParser::new();
142		}
143	}
144}