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_build::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::{PlainTextEndpoint, ProjectConfig, TransformConfig};
24pub use discover::{discover, ProtoMetadata};
25pub use error::{Error, Result};
26pub use patch::{patch, PatchConfig};
27
28/// Internal types for advanced use and testing.
29///
30/// **Not covered by semver guarantees.** These re-exports are `#[doc(hidden)]`
31/// and may change in any release, including patch versions. They exist for
32/// integration testing and advanced use cases only.
33#[doc(hidden)]
34pub mod internal {
35    pub use crate::discover::{
36        resolve_operation_ids, EnumRewrite, FieldConstraint, OperationEntry, PathParamConstraint,
37        PathParamInfo, SchemaConstraints, StreamingOp,
38    };
39
40    use std::collections::HashMap;
41
42    use crate::discover::ProtoMetadata;
43
44    /// Builder extension for populating `ProtoMetadata` fields in tests.
45    ///
46    /// These bypass the normal `discover()` path for fixture-based testing.
47    impl ProtoMetadata {
48        /// Set streaming ops (test helper).
49        pub fn set_streaming_ops(&mut self, ops: Vec<StreamingOp>) {
50            self.streaming_ops = ops;
51        }
52
53        /// Set operation IDs (test helper).
54        pub fn set_operation_ids(&mut self, ids: Vec<OperationEntry>) {
55            self.operation_ids = ids;
56        }
57
58        /// Set field constraints (test helper).
59        pub fn set_field_constraints(&mut self, constraints: Vec<SchemaConstraints>) {
60            self.field_constraints = constraints;
61        }
62
63        /// Set enum rewrites (test helper).
64        pub fn set_enum_rewrites(&mut self, rewrites: Vec<EnumRewrite>) {
65            self.enum_rewrites = rewrites;
66        }
67
68        /// Set enum value map (test helper).
69        pub fn set_enum_value_map(&mut self, map: HashMap<String, String>) {
70            self.enum_value_map = map;
71        }
72    }
73}