Skip to main content

openapi_nexus/ir/types/
operation.rs

1//! Operation types — fully resolved API operations.
2
3use indexmap::IndexMap;
4use serde::Serialize;
5
6use super::type_expr::IrTypeExpr;
7
8/// A fully resolved API operation (one HTTP method + path).
9#[derive(Debug, Clone, Serialize)]
10pub struct IrOperation {
11    pub operation_id: String,
12    pub tags: Vec<String>,
13    pub method: String,
14    pub path: String,
15    pub summary: Option<String>,
16    pub description: Option<String>,
17    pub deprecated: bool,
18    pub parameters: Vec<IrParameter>,
19    pub request_body: Option<IrRequestBody>,
20    pub responses: Vec<IrResponse>,
21    pub security: Vec<IrSecurityRequirement>,
22}
23
24/// A fully resolved parameter.
25#[derive(Debug, Clone, Serialize)]
26pub struct IrParameter {
27    pub name: String,
28    pub location: ParameterLocation,
29    pub type_expr: IrTypeExpr,
30    pub required: bool,
31    pub description: Option<String>,
32    pub default_value: Option<serde_json::Value>,
33}
34
35/// Where a parameter is located.
36#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
37pub enum ParameterLocation {
38    Query,
39    Header,
40    Path,
41    Cookie,
42}
43
44/// A fully resolved request body.
45#[derive(Debug, Clone, Serialize)]
46pub struct IrRequestBody {
47    pub required: bool,
48    pub description: Option<String>,
49    /// Media type -> resolved schema type.
50    pub content: IndexMap<String, IrTypeExpr>,
51}
52
53/// A fully resolved response.
54#[derive(Debug, Clone, Serialize)]
55pub struct IrResponse {
56    pub status: String,
57    pub description: String,
58    pub content: IndexMap<String, IrTypeExpr>,
59    /// Streaming item types (from OAS 3.2 `itemSchema`).
60    /// Non-empty when the response is a streaming endpoint (e.g. text/event-stream).
61    pub item_content: IndexMap<String, IrTypeExpr>,
62    pub headers: IndexMap<String, IrHeader>,
63}
64
65/// A resolved response header.
66#[derive(Debug, Clone, Serialize)]
67pub struct IrHeader {
68    pub description: Option<String>,
69    pub type_expr: IrTypeExpr,
70    pub required: bool,
71}
72
73/// Security requirement (operation-level or spec-level).
74#[derive(Debug, Clone, Serialize)]
75pub struct IrSecurityRequirement {
76    pub scheme_name: String,
77    pub scopes: Vec<String>,
78}