Skip to main content

oag_core/ir/
operations.rs

1use super::schemas::IrType;
2use super::types::NormalizedName;
3
4/// HTTP method.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum HttpMethod {
7    Get,
8    Post,
9    Put,
10    Delete,
11    Patch,
12    Options,
13    Head,
14    Trace,
15}
16
17impl HttpMethod {
18    pub fn as_str(&self) -> &'static str {
19        match self {
20            HttpMethod::Get => "GET",
21            HttpMethod::Post => "POST",
22            HttpMethod::Put => "PUT",
23            HttpMethod::Delete => "DELETE",
24            HttpMethod::Patch => "PATCH",
25            HttpMethod::Options => "OPTIONS",
26            HttpMethod::Head => "HEAD",
27            HttpMethod::Trace => "TRACE",
28        }
29    }
30}
31
32/// A fully resolved API operation.
33#[derive(Debug, Clone)]
34pub struct IrOperation {
35    pub name: NormalizedName,
36    pub method: HttpMethod,
37    pub path: String,
38    pub summary: Option<String>,
39    pub description: Option<String>,
40    pub tags: Vec<String>,
41    pub parameters: Vec<IrParameter>,
42    pub request_body: Option<IrRequestBody>,
43    pub return_type: IrReturnType,
44    pub deprecated: bool,
45}
46
47/// What an operation returns.
48#[derive(Debug, Clone)]
49pub enum IrReturnType {
50    /// Standard JSON response.
51    Standard(IrResponse),
52    /// Server-Sent Events stream.
53    Sse(IrSseReturn),
54    /// No response body (204, etc).
55    Void,
56}
57
58/// SSE return type with event schema info.
59#[derive(Debug, Clone)]
60pub struct IrSseReturn {
61    /// The type of each event yielded by the stream.
62    pub event_type: IrType,
63    /// If the itemSchema has oneOf, these are the individual variant types.
64    pub variants: Vec<IrType>,
65    /// The union type name for the stream event (e.g., `CreateChatCompletionStreamEvent`).
66    pub event_type_name: Option<String>,
67    /// Whether the endpoint also has a JSON response (dual endpoint).
68    pub also_has_json: bool,
69    /// The JSON response type if this is a dual endpoint.
70    pub json_response: Option<IrResponse>,
71}
72
73/// A resolved response.
74#[derive(Debug, Clone)]
75pub struct IrResponse {
76    pub response_type: IrType,
77    pub description: Option<String>,
78}
79
80/// A resolved path/query/header parameter.
81#[derive(Debug, Clone)]
82pub struct IrParameter {
83    pub name: NormalizedName,
84    pub original_name: String,
85    pub location: IrParameterLocation,
86    pub param_type: IrType,
87    pub required: bool,
88    pub description: Option<String>,
89}
90
91/// Parameter location.
92#[derive(Debug, Clone, Copy, PartialEq, Eq)]
93pub enum IrParameterLocation {
94    Path,
95    Query,
96    Header,
97    Cookie,
98}
99
100/// A resolved request body.
101#[derive(Debug, Clone)]
102pub struct IrRequestBody {
103    pub body_type: IrType,
104    pub required: bool,
105    pub content_type: String,
106    pub description: Option<String>,
107}