@noego/stitch 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-schema.md +139 -0
- package/bin/stitch.js +156 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/cli/StitchCLI.d.ts +12 -0
- package/dist/cli/StitchCLI.d.ts.map +1 -0
- package/dist/client.cjs +2 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.mjs +83 -0
- package/dist/client.mjs.map +1 -0
- package/dist/core/ConfigParser.d.ts +16 -0
- package/dist/core/ConfigParser.d.ts.map +1 -0
- package/dist/core/StitchEngine.d.ts +31 -0
- package/dist/core/StitchEngine.d.ts.map +1 -0
- package/dist/core/Validator.d.ts +18 -0
- package/dist/core/Validator.d.ts.map +1 -0
- package/dist/core/ViteHelper.d.ts +33 -0
- package/dist/core/ViteHelper.d.ts.map +1 -0
- package/dist/core/YamlMerger.d.ts +29 -0
- package/dist/core/YamlMerger.d.ts.map +1 -0
- package/dist/core/YamlMergerBrowser.d.ts +18 -0
- package/dist/core/YamlMergerBrowser.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types/StitchTypes.d.ts +38 -0
- package/dist/types/StitchTypes.d.ts.map +1 -0
- package/dist-ssr/browser/index.d.ts +4 -0
- package/dist-ssr/browser/index.d.ts.map +1 -0
- package/dist-ssr/cli/StitchCLI.d.ts +12 -0
- package/dist-ssr/cli/StitchCLI.d.ts.map +1 -0
- package/dist-ssr/core/ConfigParser.d.ts +16 -0
- package/dist-ssr/core/ConfigParser.d.ts.map +1 -0
- package/dist-ssr/core/StitchEngine.d.ts +31 -0
- package/dist-ssr/core/StitchEngine.d.ts.map +1 -0
- package/dist-ssr/core/Validator.d.ts +18 -0
- package/dist-ssr/core/Validator.d.ts.map +1 -0
- package/dist-ssr/core/ViteHelper.d.ts +33 -0
- package/dist-ssr/core/ViteHelper.d.ts.map +1 -0
- package/dist-ssr/core/YamlMerger.d.ts +29 -0
- package/dist-ssr/core/YamlMerger.d.ts.map +1 -0
- package/dist-ssr/core/YamlMergerBrowser.d.ts +18 -0
- package/dist-ssr/core/YamlMergerBrowser.d.ts.map +1 -0
- package/dist-ssr/index.d.ts +15 -0
- package/dist-ssr/index.d.ts.map +1 -0
- package/dist-ssr/server.cjs +574 -0
- package/dist-ssr/server.cjs.map +1 -0
- package/dist-ssr/server.d.ts +2 -0
- package/dist-ssr/server.js +554 -0
- package/dist-ssr/server.js.map +1 -0
- package/dist-ssr/types/StitchTypes.d.ts +38 -0
- package/dist-ssr/types/StitchTypes.d.ts.map +1 -0
- package/docs/advanced_validation.md +188 -0
- package/docs/middleware.md +507 -0
- package/docs/modules.md +175 -0
- package/docs/project.md +856 -0
- package/docs/validation.md +77 -0
- package/package.json +67 -0
- package/readme.md +159 -0
- package/schemas/schema.json +360 -0
- package/schemas/stitch-schema.json +38 -0
package/docs/modules.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Module Support in OpenAPI Configuration
|
|
2
|
+
|
|
3
|
+
This document explains how to use the module feature in your OpenAPI configuration to organize API routes into logical groups.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The module feature allows you to define groups of related API endpoints with a common base path. This helps in:
|
|
8
|
+
|
|
9
|
+
1. Better organization of your API specification
|
|
10
|
+
2. Avoiding duplication of base paths
|
|
11
|
+
3. Keeping related endpoints grouped together
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
### Adding Modules to Your OpenAPI Document
|
|
16
|
+
|
|
17
|
+
To use modules, add a top-level `module` field to your OpenAPI document:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
openapi: 3.0.0
|
|
21
|
+
info:
|
|
22
|
+
title: My API
|
|
23
|
+
version: 1.0.0
|
|
24
|
+
paths:
|
|
25
|
+
# Top-level paths go here
|
|
26
|
+
|
|
27
|
+
# Module definitions
|
|
28
|
+
module:
|
|
29
|
+
user: # Module name
|
|
30
|
+
basePath: "/users" # Common prefix for all routes in this module
|
|
31
|
+
paths:
|
|
32
|
+
# Module-specific paths
|
|
33
|
+
"/":
|
|
34
|
+
get:
|
|
35
|
+
x-controller: user.controller
|
|
36
|
+
x-action: getAll
|
|
37
|
+
# Other operation properties...
|
|
38
|
+
|
|
39
|
+
"/{id}":
|
|
40
|
+
get:
|
|
41
|
+
x-controller: user.controller
|
|
42
|
+
x-action: get
|
|
43
|
+
# Other operation properties...
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Module Properties
|
|
47
|
+
|
|
48
|
+
Each module requires:
|
|
49
|
+
|
|
50
|
+
1. `basePath`: The common URL prefix for all routes in this module
|
|
51
|
+
2. `paths`: An object or array containing the module's endpoint definitions
|
|
52
|
+
|
|
53
|
+
The `basePath` will be combined with each path in the `paths` object to create the full route path.
|
|
54
|
+
|
|
55
|
+
### Defining Paths
|
|
56
|
+
|
|
57
|
+
You can define paths in two ways:
|
|
58
|
+
|
|
59
|
+
#### Object Format (Recommended)
|
|
60
|
+
|
|
61
|
+
Use an object where keys are path suffixes and values are the path configurations:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
module:
|
|
65
|
+
post:
|
|
66
|
+
basePath: "/posts"
|
|
67
|
+
paths:
|
|
68
|
+
"/":
|
|
69
|
+
get:
|
|
70
|
+
x-controller: post.controller
|
|
71
|
+
x-action: getAll
|
|
72
|
+
# ...
|
|
73
|
+
|
|
74
|
+
"/{id}":
|
|
75
|
+
get:
|
|
76
|
+
x-controller: post.controller
|
|
77
|
+
x-action: get
|
|
78
|
+
# ...
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Array Format (Alternative)
|
|
82
|
+
|
|
83
|
+
Define paths as an array of strings with a separate `pathObjects` property:
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
module:
|
|
87
|
+
post:
|
|
88
|
+
basePath: "/posts"
|
|
89
|
+
paths: ["/", "/{id}", "/create"]
|
|
90
|
+
pathObjects:
|
|
91
|
+
"/":
|
|
92
|
+
get:
|
|
93
|
+
x-controller: post.controller
|
|
94
|
+
x-action: getAll
|
|
95
|
+
# ...
|
|
96
|
+
|
|
97
|
+
"/{id}":
|
|
98
|
+
get:
|
|
99
|
+
x-controller: post.controller
|
|
100
|
+
x-action: get
|
|
101
|
+
# ...
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## How It Works
|
|
105
|
+
|
|
106
|
+
When the server starts:
|
|
107
|
+
|
|
108
|
+
1. The OpenAPI parser reads the document and processes all modules
|
|
109
|
+
2. Each module path is combined with its base path to create complete paths
|
|
110
|
+
3. These combined paths are added to the main `paths` object
|
|
111
|
+
4. Routes are created as normal from the final paths object
|
|
112
|
+
|
|
113
|
+
## Example
|
|
114
|
+
|
|
115
|
+
Here's a complete example:
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
openapi: 3.0.0
|
|
119
|
+
info:
|
|
120
|
+
title: Blog API
|
|
121
|
+
version: 1.0.0
|
|
122
|
+
paths:
|
|
123
|
+
# Global routes outside of modules
|
|
124
|
+
/health:
|
|
125
|
+
get:
|
|
126
|
+
x-controller: health.controller
|
|
127
|
+
x-action: check
|
|
128
|
+
summary: Health check endpoint
|
|
129
|
+
|
|
130
|
+
# Module definitions
|
|
131
|
+
module:
|
|
132
|
+
user:
|
|
133
|
+
basePath: "/users"
|
|
134
|
+
paths:
|
|
135
|
+
"/":
|
|
136
|
+
get:
|
|
137
|
+
x-controller: user.controller
|
|
138
|
+
x-action: getAll
|
|
139
|
+
summary: Get all users
|
|
140
|
+
|
|
141
|
+
"/{id}":
|
|
142
|
+
get:
|
|
143
|
+
x-controller: user.controller
|
|
144
|
+
x-action: get
|
|
145
|
+
summary: Get user by ID
|
|
146
|
+
|
|
147
|
+
post:
|
|
148
|
+
basePath: "/posts"
|
|
149
|
+
paths:
|
|
150
|
+
"/":
|
|
151
|
+
get:
|
|
152
|
+
x-controller: post.controller
|
|
153
|
+
x-action: getAll
|
|
154
|
+
summary: Get all posts
|
|
155
|
+
|
|
156
|
+
"/{id}":
|
|
157
|
+
get:
|
|
158
|
+
x-controller: post.controller
|
|
159
|
+
x-action: get
|
|
160
|
+
summary: Get post by ID
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This will create the following routes:
|
|
164
|
+
- `GET /health`
|
|
165
|
+
- `GET /users/`
|
|
166
|
+
- `GET /users/{id}`
|
|
167
|
+
- `GET /posts/`
|
|
168
|
+
- `GET /posts/{id}`
|
|
169
|
+
|
|
170
|
+
## Best Practices
|
|
171
|
+
|
|
172
|
+
1. Use modules to group related functionality
|
|
173
|
+
2. Ensure basePath is meaningful and follows REST conventions
|
|
174
|
+
3. Keep paths consistent within modules
|
|
175
|
+
4. Document your module structure for other developers
|