oas_forge/
index.rs

1use std::collections::HashMap;
2
3#[derive(Debug, Clone)]
4pub struct Blueprint {
5    pub params: Vec<String>, // e.g. ["T", "U"] extracted from <T, U>
6    pub body: String,
7}
8
9#[derive(Debug, Clone)]
10pub struct Fragment {
11    pub params: Vec<String>,
12    pub body: String,
13}
14
15/// Stores definitions for fragments, blueprints, and concrete schemas.
16#[derive(Default, Debug)]
17pub struct Registry {
18    /// @openapi-fragment Name(arg1, arg2)
19    pub fragments: HashMap<String, Fragment>,
20    /// @openapi<T, U> -> key is Name ("Page")
21    pub blueprints: HashMap<String, Blueprint>,
22    /// Standard @openapi on structs
23    pub schemas: HashMap<String, String>,
24    /// Concrete schemas generated from generics (e.g. Page_User)
25    pub concrete_schemas: HashMap<String, String>,
26}
27
28impl Registry {
29    pub fn new() -> Self {
30        Self::default()
31    }
32
33    pub fn insert_fragment(&mut self, name: String, params: Vec<String>, content: String) {
34        self.fragments.insert(
35            name,
36            Fragment {
37                params,
38                body: content,
39            },
40        );
41    }
42
43    pub fn insert_blueprint(&mut self, name: String, params: Vec<String>, content: String) {
44        self.blueprints.insert(
45            name,
46            Blueprint {
47                params,
48                body: content,
49            },
50        );
51    }
52
53    pub fn insert_schema(&mut self, name: String, content: String) {
54        self.schemas.insert(name, content);
55    }
56}