Skip to main content

openapi_nexus/ir/types/
spec.rs

1//! Top-level IR spec types.
2
3use indexmap::IndexMap;
4use serde::Serialize;
5
6use super::operation::{IrOperation, IrSecurityRequirement};
7use super::schema::IrSchema;
8
9/// The top-level intermediate representation of an OpenAPI specification.
10/// Version-agnostic — OAS 3.0, 3.1, and 3.2 all lower into this same type.
11#[derive(Debug, Clone, Serialize)]
12pub struct IrSpec {
13    pub info: IrInfo,
14    pub servers: Vec<IrServer>,
15    pub schemas: IndexMap<String, IrSchema>,
16    pub operations: Vec<IrOperation>,
17    pub security_schemes: IndexMap<String, IrSecurityScheme>,
18    pub security: Vec<IrSecurityRequirement>,
19}
20
21/// API metadata.
22#[derive(Debug, Clone, Serialize)]
23pub struct IrInfo {
24    pub title: String,
25    pub description: Option<String>,
26    pub version: String,
27    pub terms_of_service: Option<String>,
28    pub contact: Option<IrContact>,
29    pub license: Option<IrLicense>,
30}
31
32/// Contact information.
33#[derive(Debug, Clone, Serialize)]
34pub struct IrContact {
35    pub name: Option<String>,
36    pub url: Option<String>,
37    pub email: Option<String>,
38}
39
40/// License information.
41#[derive(Debug, Clone, Serialize)]
42pub struct IrLicense {
43    pub name: String,
44    pub url: Option<String>,
45    pub identifier: Option<String>,
46}
47
48/// Server definition.
49#[derive(Debug, Clone, Serialize)]
50pub struct IrServer {
51    pub url: String,
52    pub description: Option<String>,
53}
54
55/// Security scheme definition.
56#[derive(Debug, Clone, Serialize)]
57pub enum IrSecurityScheme {
58    ApiKey {
59        name: String,
60        location: ApiKeyLocation,
61        description: Option<String>,
62    },
63    Http {
64        scheme: String,
65        bearer_format: Option<String>,
66        description: Option<String>,
67    },
68    OAuth2 {
69        flows: Box<IrOAuth2Flows>,
70        description: Option<String>,
71    },
72    OpenIdConnect {
73        open_id_connect_url: String,
74        description: Option<String>,
75    },
76    MutualTls {
77        description: Option<String>,
78    },
79}
80
81#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
82pub enum ApiKeyLocation {
83    Query,
84    Header,
85    Cookie,
86}
87
88#[derive(Debug, Clone, Default, Serialize)]
89pub struct IrOAuth2Flows {
90    pub implicit: Option<IrOAuth2Flow>,
91    pub password: Option<IrOAuth2Flow>,
92    pub client_credentials: Option<IrOAuth2Flow>,
93    pub authorization_code: Option<IrOAuth2Flow>,
94}
95
96#[derive(Debug, Clone, Serialize)]
97pub struct IrOAuth2Flow {
98    pub authorization_url: Option<String>,
99    pub token_url: Option<String>,
100    pub refresh_url: Option<String>,
101    pub scopes: IndexMap<String, String>,
102}