Skip to main content

tonic_rest_openapi/
lib.rs

1#![allow(clippy::doc_markdown)] // README uses "OpenAPI" proper noun throughout
2#![doc = include_str!("../README.md")]
3//!
4//! ---
5//!
6//! ## API Reference
7
8#![forbid(unsafe_code)]
9#![deny(missing_docs)]
10
11mod config;
12pub(crate) use tonic_rest_core::descriptor;
13mod discover;
14mod error;
15mod patch;
16
17/// Default `$ref` path for the REST error response schema.
18///
19/// Override via [`PatchConfig::error_schema_ref`] or [`ProjectConfig::error_schema_ref`]
20/// when your proto package uses a different path (e.g., `"#/components/schemas/myapp.v1.Error"`).
21pub const DEFAULT_ERROR_SCHEMA_REF: &str = "#/components/schemas/ErrorResponse";
22
23pub use config::{
24    ContactInfo, ExternalDocsInfo, InfoOverrides, LicenseInfo, PlainTextEndpoint, ProjectConfig,
25    ServerEntry, TransformConfig,
26};
27pub use discover::{
28    EnumRewrite, FieldConstraint, OperationEntry, PathParamConstraint, PathParamInfo,
29    ProtoMetadata, SchemaConstraints, StreamingOp, discover,
30};
31pub use error::{Error, Result};
32pub use patch::{PatchConfig, patch};
33
34/// Test-support utilities for constructing `ProtoMetadata` fixtures.
35///
36/// These setters bypass the normal [`discover()`] path, allowing tests to
37/// populate individual fields without a real proto descriptor. Only available
38/// when the `test-support` feature is enabled.
39#[cfg(feature = "test-support")]
40impl ProtoMetadata {
41    /// Set streaming ops (test helper).
42    pub fn set_streaming_ops(&mut self, ops: Vec<StreamingOp>) {
43        self.streaming_ops = ops;
44    }
45
46    /// Set operation IDs (test helper).
47    pub fn set_operation_ids(&mut self, ids: Vec<OperationEntry>) {
48        self.operation_ids = ids;
49    }
50
51    /// Set field constraints (test helper).
52    pub fn set_field_constraints(&mut self, constraints: Vec<SchemaConstraints>) {
53        self.field_constraints = constraints;
54    }
55
56    /// Set enum rewrites (test helper).
57    pub fn set_enum_rewrites(&mut self, rewrites: Vec<EnumRewrite>) {
58        self.enum_rewrites = rewrites;
59    }
60
61    /// Set enum value map (test helper).
62    pub fn set_enum_value_map(&mut self, map: std::collections::HashMap<String, String>) {
63        self.enum_value_map = map;
64    }
65}