@type-crafter/mcp 1.2.0 → 1.3.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.
@@ -1,8 +1,34 @@
1
1
  # Composition Rules
2
2
 
3
- ## oneOf - Union Types
3
+ **Only two composition keywords exist: `oneOf` and `allOf`. No other composition mechanism exists (`anyOf`, `not`, `extends`, `implements`, `inherits`, `mixin`, `merge`, `discriminator` are all invalid).**
4
+
5
+ ---
6
+
7
+ ## Valid Composition Keywords (Complete List)
8
+
9
+ | Keyword | Use Case |
10
+ | --- | --- |
11
+ | `oneOf` | Value is one of several types (union) |
12
+ | `allOf` | Combine/merge multiple types (intersection) |
13
+
14
+ **No other composition keywords exist.**
15
+
16
+ ---
17
+
18
+ ## What Can Appear Inside `oneOf` / `allOf` Arrays
19
+
20
+ Each array item must be one of:
21
+
22
+ - `$ref` to another type
23
+ - `type: object` with `properties`
24
+ - `type: string/number/boolean/unknown` (primitives)
25
+ - `type: string` with `enum`
26
+ - `type: array` with `items`
27
+ - Nested `oneOf` or `allOf`
28
+
29
+ ---
4
30
 
5
- Creates TypeScript union: `TypeA | TypeB | TypeC`
31
+ ## oneOf - Union Types
6
32
 
7
33
  Use when a value can be ONE of several types.
8
34
 
@@ -15,8 +41,6 @@ Response:
15
41
  - $ref: '#/types/ErrorResponse'
16
42
  ```
17
43
 
18
- **TypeScript:** `export type Response = SuccessResponse | ErrorResponse;`
19
-
20
44
  ### Union with Primitives
21
45
 
22
46
  ```yaml
@@ -27,27 +51,23 @@ Value:
27
51
  - type: boolean
28
52
  ```
29
53
 
30
- **TypeScript:** `export type Value = string | number | boolean;`
31
-
32
54
  ### Union with Inline Objects
33
55
 
34
56
  ```yaml
35
57
  Result:
36
58
  oneOf:
37
59
  - type: object
38
- required: [data]
60
+ required:
61
+ - data
39
62
  properties:
40
- data: { type: string }
63
+ data:
64
+ type: string
41
65
  - type: object
42
- required: [error]
66
+ required:
67
+ - error
43
68
  properties:
44
- error: { type: string }
45
- ```
46
-
47
- **TypeScript:**
48
-
49
- ```typescript
50
- export type Result = { data: string } | { error: string };
69
+ error:
70
+ type: string
51
71
  ```
52
72
 
53
73
  ### Union with Arrays
@@ -61,21 +81,21 @@ Items:
61
81
  type: string
62
82
  ```
63
83
 
64
- **TypeScript:** `export type Items = string | string[];`
65
-
66
84
  ### Union with Enums
67
85
 
68
86
  ```yaml
69
87
  Status:
70
88
  oneOf:
71
89
  - type: string
72
- enum: [pending, loading]
90
+ enum:
91
+ - pending
92
+ - loading
73
93
  - type: string
74
- enum: [success, error]
94
+ enum:
95
+ - success
96
+ - error
75
97
  ```
76
98
 
77
- **TypeScript:** `export type Status = 'pending' | 'loading' | 'success' | 'error';`
78
-
79
99
  ### Complex Union Example
80
100
 
81
101
  ```yaml
@@ -86,10 +106,13 @@ ApiResponse:
86
106
  - type: string
87
107
  - type: number
88
108
  - type: string
89
- enum: [pending, loading]
109
+ enum:
110
+ - pending
111
+ - loading
90
112
  - type: object
91
113
  properties:
92
- status: { type: string }
114
+ status:
115
+ type: string
93
116
  - type: array
94
117
  items:
95
118
  type: string
@@ -98,26 +121,10 @@ ApiResponse:
98
121
  $ref: '#/types/User'
99
122
  ```
100
123
 
101
- **TypeScript:**
102
-
103
- ```typescript
104
- export type ApiResponse =
105
- | User
106
- | Error
107
- | string
108
- | number
109
- | ('pending' | 'loading')
110
- | { status: string | null }
111
- | string[]
112
- | User[];
113
- ```
114
-
115
124
  ---
116
125
 
117
126
  ## allOf - Intersection/Merge Types
118
127
 
119
- Creates TypeScript intersection: `TypeA & TypeB & TypeC`
120
-
121
128
  Use to combine multiple types into one (all properties merged).
122
129
 
123
130
  ### Basic Intersection
@@ -129,39 +136,29 @@ AdminUser:
129
136
  - $ref: '#/types/AdminPermissions'
130
137
  ```
131
138
 
132
- **TypeScript:** `export type AdminUser = BaseUser & AdminPermissions;`
133
-
134
139
  ### Intersection with Inline Extension
135
140
 
136
141
  ```yaml
137
142
  types:
138
143
  BaseUser:
139
144
  type: object
140
- required: [id]
145
+ required:
146
+ - id
141
147
  properties:
142
- id: { type: string }
148
+ id:
149
+ type: string
143
150
 
144
151
  ExtendedUser:
145
152
  allOf:
146
153
  - $ref: '#/types/BaseUser'
147
154
  - type: object
148
- required: [email]
155
+ required:
156
+ - email
149
157
  properties:
150
- email: { type: string }
151
- name: { type: string }
152
- ```
153
-
154
- **TypeScript:**
155
-
156
- ```typescript
157
- export type BaseUser = {
158
- id: string;
159
- };
160
-
161
- export type ExtendedUser = BaseUser & {
162
- email: string;
163
- name: string | null;
164
- };
158
+ email:
159
+ type: string
160
+ name:
161
+ type: string
165
162
  ```
166
163
 
167
164
  ### Multiple Inheritance Pattern
@@ -170,45 +167,37 @@ export type ExtendedUser = BaseUser & {
170
167
  types:
171
168
  Timestamped:
172
169
  type: object
173
- required: [createdAt, updatedAt]
170
+ required:
171
+ - createdAt
172
+ - updatedAt
174
173
  properties:
175
- createdAt: { type: string, format: date }
176
- updatedAt: { type: string, format: date }
174
+ createdAt:
175
+ type: string
176
+ format: date
177
+ updatedAt:
178
+ type: string
179
+ format: date
177
180
 
178
181
  Identifiable:
179
182
  type: object
180
- required: [id]
183
+ required:
184
+ - id
181
185
  properties:
182
- id: { type: string }
186
+ id:
187
+ type: string
183
188
 
184
189
  User:
185
190
  allOf:
186
191
  - $ref: '#/types/Timestamped'
187
192
  - $ref: '#/types/Identifiable'
188
193
  - type: object
189
- required: [email]
194
+ required:
195
+ - email
190
196
  properties:
191
- email: { type: string }
192
- name: { type: string }
193
- ```
194
-
195
- **TypeScript:**
196
-
197
- ```typescript
198
- export type User = Timestamped &
199
- Identifiable & {
200
- email: string;
201
- name: string | null;
202
- };
203
-
204
- // Effectively:
205
- // {
206
- // createdAt: Date;
207
- // updatedAt: Date;
208
- // id: string;
209
- // email: string;
210
- // name: string | null;
211
- // }
197
+ email:
198
+ type: string
199
+ name:
200
+ type: string
212
201
  ```
213
202
 
214
203
  ---
@@ -226,12 +215,14 @@ Response:
226
215
  - $ref: '#/types/BaseResponse'
227
216
  - type: object
228
217
  properties:
229
- data: { $ref: '#/types/User' }
218
+ data:
219
+ $ref: '#/types/User'
230
220
  - allOf:
231
221
  - $ref: '#/types/BaseResponse'
232
222
  - type: object
233
223
  properties:
234
- error: { type: string }
224
+ error:
225
+ type: string
235
226
  ```
236
227
 
237
228
  ### Intersection with Union Property
@@ -245,7 +236,9 @@ Entity:
245
236
  status:
246
237
  oneOf:
247
238
  - type: string
248
- enum: [active, inactive]
239
+ enum:
240
+ - active
241
+ - inactive
249
242
  - type: number
250
243
  ```
251
244
 
@@ -259,21 +252,29 @@ Entity:
259
252
  types:
260
253
  SuccessResult:
261
254
  type: object
262
- required: [type, data]
255
+ required:
256
+ - type
257
+ - data
263
258
  properties:
264
259
  type:
265
260
  type: string
266
- enum: [success]
267
- data: { type: unknown }
261
+ enum:
262
+ - success
263
+ data:
264
+ type: unknown
268
265
 
269
266
  ErrorResult:
270
267
  type: object
271
- required: [type, message]
268
+ required:
269
+ - type
270
+ - message
272
271
  properties:
273
272
  type:
274
273
  type: string
275
- enum: [error]
276
- message: { type: string }
274
+ enum:
275
+ - error
276
+ message:
277
+ type: string
277
278
 
278
279
  Result:
279
280
  oneOf:
@@ -281,63 +282,40 @@ types:
281
282
  - $ref: '#/types/ErrorResult'
282
283
  ```
283
284
 
284
- **TypeScript:**
285
-
286
- ```typescript
287
- export type Result = { type: 'success'; data: unknown } | { type: 'error'; message: string };
288
- ```
289
-
290
285
  ### Mixin Pattern
291
286
 
292
287
  ```yaml
293
288
  types:
294
289
  WithTimestamps:
295
290
  type: object
296
- required: [createdAt]
291
+ required:
292
+ - createdAt
297
293
  properties:
298
- createdAt: { type: string, format: date }
299
- updatedAt: { type: string, format: date }
294
+ createdAt:
295
+ type: string
296
+ format: date
297
+ updatedAt:
298
+ type: string
299
+ format: date
300
300
 
301
301
  WithSoftDelete:
302
302
  type: object
303
303
  properties:
304
- deletedAt: { type: string, format: date }
304
+ deletedAt:
305
+ type: string
306
+ format: date
305
307
 
306
308
  User:
307
309
  allOf:
308
310
  - $ref: '#/types/WithTimestamps'
309
311
  - $ref: '#/types/WithSoftDelete'
310
312
  - type: object
311
- required: [id, email]
313
+ required:
314
+ - id
315
+ - email
312
316
  properties:
313
- id: { type: string }
314
- email: { type: string }
317
+ id:
318
+ type: string
319
+ email:
320
+ type: string
315
321
  ```
316
-
317
- ### Nullable Union
318
-
319
- ```yaml
320
- MaybeUser:
321
- oneOf:
322
- - $ref: '#/types/User'
323
- - type: object
324
- properties: {} # Empty object as "null" representation
325
- ```
326
-
327
- ---
328
-
329
- ## Rules Summary
330
-
331
- | Operator | TypeScript | Use Case |
332
- | -------- | ------------- | ----------------------------- |
333
- | `oneOf` | `A \| B \| C` | Value is one of several types |
334
- | `allOf` | `A & B & C` | Combine/merge multiple types |
335
-
336
- ### What Can Be in oneOf/allOf
337
-
338
- - `$ref` to other types
339
- - `type: object` with properties
340
- - `type: string/number/boolean` primitives
341
- - `type: string` with `enum`
342
- - `type: array` with items
343
- - Nested `oneOf` or `allOf`