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    /// Media type -> property name -> request-body encoding metadata.
52    pub encoding: IndexMap<String, IndexMap<String, IrRequestBodyEncoding>>,
53}
54
55/// Request-body encoding metadata for a single media-type property.
56#[derive(Debug, Clone, Serialize)]
57pub struct IrRequestBodyEncoding {
58    pub content_type: Option<String>,
59}
60
61/// A fully resolved response.
62#[derive(Debug, Clone, Serialize)]
63pub struct IrResponse {
64    pub status: String,
65    pub description: String,
66    pub content: IndexMap<String, IrTypeExpr>,
67    /// Streaming item types (from OAS 3.2 `itemSchema`).
68    /// Non-empty when the response is a streaming endpoint (e.g. text/event-stream).
69    pub item_content: IndexMap<String, IrTypeExpr>,
70    pub headers: IndexMap<String, IrHeader>,
71}
72
73/// A resolved response header.
74#[derive(Debug, Clone, Serialize)]
75pub struct IrHeader {
76    pub description: Option<String>,
77    pub type_expr: IrTypeExpr,
78    pub required: bool,
79}
80
81/// Security requirement (operation-level or spec-level).
82#[derive(Debug, Clone, Serialize)]
83pub struct IrSecurityRequirement {
84    pub scheme_name: String,
85    pub scopes: Vec<String>,
86}