poolster_core/adapter/mod.rs
1//! Source-format adapters.
2//!
3//! The codegen core only consumes [`crate::Api`]. An [`Adapter`] is the
4//! public boundary for bringing another source format into that neutral model;
5//! it also carries security definitions which cannot be inferred from an
6//! operation's named requirements alone. OpenAPI parsing is supplied by
7//! Poolster's embedded Go compiler, whose JSON artifacts are read by
8//! [`openapi_sidecar`].
9
10use anyhow::Result;
11
12use crate::{Api, SecuritySchemeCatalog};
13
14pub mod openapi_sidecar;
15pub use openapi_sidecar::OpenApiSidecar;
16
17/// A normalized input contract ready for language plugins.
18///
19/// Adapters should preserve source-specific information in [`Api::annotations`]
20/// where it is useful to a generic transform, rather than exposing their
21/// parser's internal types to generators. An empty security catalog is valid
22/// for formats without reusable credential definitions.
23#[derive(Clone, Debug, Default, PartialEq, Eq)]
24pub struct AdaptedApi {
25 pub api: Api,
26 pub security_schemes: SecuritySchemeCatalog,
27}
28
29impl AdaptedApi {
30 pub fn new(api: Api, security_schemes: SecuritySchemeCatalog) -> Self {
31 Self {
32 api,
33 security_schemes,
34 }
35 }
36}
37
38/// Converts a source contract into Poolster's target-neutral AST.
39///
40/// Implement this trait in an application or integration crate to support
41/// formats such as AsyncAPI, GraphQL, or a company-specific contract format.
42/// It is deliberately synchronous and object-safe, so adapters can be passed
43/// as `&dyn Adapter` when a caller selects an input format at runtime.
44///
45/// Output customization does not use a separate parser trait: it belongs to
46/// Poolster's existing [`crate::engine::Language`] and [`crate::engine::Plugin`]
47/// extension points after an adapter has produced an [`Api`].
48pub trait Adapter {
49 fn adapt(&self) -> Result<AdaptedApi>;
50}