@type-crafter/mcp 1.2.0 → 1.2.1
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/dist/docs/RULES_COMPOSITION.md +115 -137
- package/dist/docs/RULES_NULLABLE.md +69 -141
- package/dist/docs/RULES_PATTERNS.md +90 -85
- package/dist/docs/RULES_REFERENCES.md +46 -114
- package/dist/docs/RULES_STRUCTURE.md +58 -57
- package/dist/docs/RULES_TYPES.md +88 -91
- package/dist/docs/WRITING_GUIDE.md +144 -123
- package/package.json +1 -1
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
# Nullable Types Rules
|
|
2
2
|
|
|
3
|
-
## The
|
|
3
|
+
## The Only Mechanism
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**The `required` array is the only way to control nullability.** No other mechanism exists in Type Crafter.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Properties listed in `required` -> non-nullable
|
|
8
|
+
- Properties NOT listed in `required` -> nullable
|
|
9
|
+
- No `required` array at all -> all properties are nullable
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## What Does NOT Work
|
|
12
|
-
|
|
13
|
-
```yaml
|
|
14
|
-
# WRONG: nullable property does NOT exist
|
|
15
|
-
name:
|
|
16
|
-
type: string
|
|
17
|
-
nullable: true # INVALID - will be ignored or error
|
|
18
|
-
|
|
19
|
-
# WRONG: optional property does NOT exist
|
|
20
|
-
name:
|
|
21
|
-
type: string
|
|
22
|
-
optional: true # INVALID - will be ignored or error
|
|
23
|
-
|
|
24
|
-
# WRONG: ? suffix is NOT supported
|
|
25
|
-
properties:
|
|
26
|
-
name?: # INVALID SYNTAX
|
|
27
|
-
type: string
|
|
28
|
-
|
|
29
|
-
# WRONG: Array type syntax
|
|
30
|
-
name:
|
|
31
|
-
type: [string, null] # INVALID - not supported
|
|
32
|
-
```
|
|
11
|
+
There are no keywords like `nullable`, `optional`, `nillable`, or any other annotation. There is no `?` suffix syntax. There is no `type: [string, null]` syntax. The `required` array is it.
|
|
33
12
|
|
|
34
13
|
---
|
|
35
14
|
|
|
36
|
-
##
|
|
15
|
+
## How It Works
|
|
37
16
|
|
|
38
17
|
```yaml
|
|
39
18
|
User:
|
|
40
19
|
type: object
|
|
41
|
-
required:
|
|
42
|
-
- id
|
|
43
|
-
- email
|
|
44
|
-
# name is NOT here -> string | null
|
|
45
|
-
# age is NOT here -> number | null
|
|
20
|
+
required:
|
|
21
|
+
- id
|
|
22
|
+
- email
|
|
46
23
|
properties:
|
|
47
24
|
id:
|
|
48
25
|
type: string
|
|
@@ -54,16 +31,7 @@ User:
|
|
|
54
31
|
type: number
|
|
55
32
|
```
|
|
56
33
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
export type User = {
|
|
61
|
-
id: string; // Required
|
|
62
|
-
email: string; // Required
|
|
63
|
-
name: string | null; // Nullable (not in required)
|
|
64
|
-
age: number | null; // Nullable (not in required)
|
|
65
|
-
};
|
|
66
|
-
```
|
|
34
|
+
In this example, `id` and `email` are in `required` so they are non-nullable. `name` and `age` are not in `required` so they are nullable.
|
|
67
35
|
|
|
68
36
|
---
|
|
69
37
|
|
|
@@ -80,20 +48,17 @@ User:
|
|
|
80
48
|
- name
|
|
81
49
|
- age
|
|
82
50
|
properties:
|
|
83
|
-
id:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
51
|
+
id:
|
|
52
|
+
type: string
|
|
53
|
+
email:
|
|
54
|
+
type: string
|
|
55
|
+
name:
|
|
56
|
+
type: string
|
|
57
|
+
age:
|
|
58
|
+
type: number
|
|
87
59
|
```
|
|
88
60
|
|
|
89
|
-
|
|
90
|
-
export type User = {
|
|
91
|
-
id: string;
|
|
92
|
-
email: string;
|
|
93
|
-
name: string;
|
|
94
|
-
age: number;
|
|
95
|
-
};
|
|
96
|
-
```
|
|
61
|
+
All four properties are non-nullable.
|
|
97
62
|
|
|
98
63
|
### Some Properties Required
|
|
99
64
|
|
|
@@ -104,56 +69,46 @@ User:
|
|
|
104
69
|
- id
|
|
105
70
|
- email
|
|
106
71
|
properties:
|
|
107
|
-
id:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
72
|
+
id:
|
|
73
|
+
type: string
|
|
74
|
+
email:
|
|
75
|
+
type: string
|
|
76
|
+
name:
|
|
77
|
+
type: string
|
|
78
|
+
age:
|
|
79
|
+
type: number
|
|
111
80
|
```
|
|
112
81
|
|
|
113
|
-
|
|
114
|
-
export type User = {
|
|
115
|
-
id: string;
|
|
116
|
-
email: string;
|
|
117
|
-
name: string | null;
|
|
118
|
-
age: number | null;
|
|
119
|
-
};
|
|
120
|
-
```
|
|
82
|
+
`id` and `email` are non-nullable. `name` and `age` are nullable.
|
|
121
83
|
|
|
122
84
|
### No Properties Required (All Nullable)
|
|
123
85
|
|
|
124
86
|
```yaml
|
|
125
87
|
User:
|
|
126
88
|
type: object
|
|
127
|
-
# No required array at all
|
|
128
89
|
properties:
|
|
129
|
-
id:
|
|
130
|
-
|
|
131
|
-
|
|
90
|
+
id:
|
|
91
|
+
type: string
|
|
92
|
+
email:
|
|
93
|
+
type: string
|
|
94
|
+
name:
|
|
95
|
+
type: string
|
|
132
96
|
```
|
|
133
97
|
|
|
134
|
-
|
|
135
|
-
export type User = {
|
|
136
|
-
id: string | null;
|
|
137
|
-
email: string | null;
|
|
138
|
-
name: string | null;
|
|
139
|
-
};
|
|
140
|
-
```
|
|
98
|
+
All three properties are nullable.
|
|
141
99
|
|
|
142
100
|
### Empty Required Array (All Nullable)
|
|
143
101
|
|
|
144
102
|
```yaml
|
|
145
103
|
User:
|
|
146
104
|
type: object
|
|
147
|
-
required: []
|
|
105
|
+
required: []
|
|
148
106
|
properties:
|
|
149
|
-
id:
|
|
107
|
+
id:
|
|
108
|
+
type: string
|
|
150
109
|
```
|
|
151
110
|
|
|
152
|
-
|
|
153
|
-
export type User = {
|
|
154
|
-
id: string | null;
|
|
155
|
-
};
|
|
156
|
-
```
|
|
111
|
+
`id` is nullable.
|
|
157
112
|
|
|
158
113
|
---
|
|
159
114
|
|
|
@@ -166,31 +121,22 @@ User:
|
|
|
166
121
|
type: object
|
|
167
122
|
required:
|
|
168
123
|
- id
|
|
169
|
-
- profile
|
|
124
|
+
- profile
|
|
170
125
|
properties:
|
|
171
126
|
id:
|
|
172
127
|
type: string
|
|
173
128
|
profile:
|
|
174
129
|
type: object
|
|
175
130
|
required:
|
|
176
|
-
- name
|
|
131
|
+
- name
|
|
177
132
|
properties:
|
|
178
133
|
name:
|
|
179
134
|
type: string
|
|
180
135
|
bio:
|
|
181
|
-
type: string
|
|
136
|
+
type: string
|
|
182
137
|
```
|
|
183
138
|
|
|
184
|
-
|
|
185
|
-
export type User = {
|
|
186
|
-
id: string;
|
|
187
|
-
profile: {
|
|
188
|
-
// profile is required (non-null)
|
|
189
|
-
name: string; // name is required inside profile
|
|
190
|
-
bio: string | null; // bio is nullable inside profile
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
```
|
|
139
|
+
`profile` is non-nullable (it's in User's `required`). Inside profile, `name` is non-nullable (it's in profile's `required`), but `bio` is nullable (not in profile's `required`).
|
|
194
140
|
|
|
195
141
|
---
|
|
196
142
|
|
|
@@ -203,7 +149,7 @@ Post:
|
|
|
203
149
|
type: object
|
|
204
150
|
required:
|
|
205
151
|
- id
|
|
206
|
-
- tags
|
|
152
|
+
- tags
|
|
207
153
|
properties:
|
|
208
154
|
id:
|
|
209
155
|
type: string
|
|
@@ -211,30 +157,20 @@ Post:
|
|
|
211
157
|
type: array
|
|
212
158
|
items:
|
|
213
159
|
type: string
|
|
214
|
-
comments:
|
|
160
|
+
comments:
|
|
215
161
|
type: array
|
|
216
162
|
items:
|
|
217
163
|
type: object
|
|
218
164
|
required:
|
|
219
165
|
- text
|
|
220
166
|
properties:
|
|
221
|
-
text:
|
|
222
|
-
|
|
167
|
+
text:
|
|
168
|
+
type: string
|
|
169
|
+
author:
|
|
170
|
+
type: string
|
|
223
171
|
```
|
|
224
172
|
|
|
225
|
-
|
|
226
|
-
export type Post = {
|
|
227
|
-
id: string;
|
|
228
|
-
tags: string[]; // Required array
|
|
229
|
-
comments:
|
|
230
|
-
| {
|
|
231
|
-
// Nullable array
|
|
232
|
-
text: string;
|
|
233
|
-
author: string | null;
|
|
234
|
-
}[]
|
|
235
|
-
| null;
|
|
236
|
-
};
|
|
237
|
-
```
|
|
173
|
+
`tags` is non-nullable (in `required`). `comments` is nullable (not in `required`). Inside each comment item, `text` is non-nullable but `author` is nullable.
|
|
238
174
|
|
|
239
175
|
---
|
|
240
176
|
|
|
@@ -246,48 +182,40 @@ Referenced types maintain their own nullability. The reference's position in `re
|
|
|
246
182
|
types:
|
|
247
183
|
Profile:
|
|
248
184
|
type: object
|
|
249
|
-
required:
|
|
185
|
+
required:
|
|
186
|
+
- bio
|
|
250
187
|
properties:
|
|
251
|
-
bio:
|
|
252
|
-
|
|
188
|
+
bio:
|
|
189
|
+
type: string
|
|
190
|
+
avatar:
|
|
191
|
+
type: string
|
|
253
192
|
|
|
254
193
|
User:
|
|
255
194
|
type: object
|
|
256
195
|
required:
|
|
257
196
|
- id
|
|
258
|
-
- mainProfile
|
|
197
|
+
- mainProfile
|
|
259
198
|
properties:
|
|
260
199
|
id:
|
|
261
200
|
type: string
|
|
262
201
|
mainProfile:
|
|
263
202
|
$ref: '#/types/Profile'
|
|
264
|
-
backupProfile:
|
|
203
|
+
backupProfile:
|
|
265
204
|
$ref: '#/types/Profile'
|
|
266
205
|
```
|
|
267
206
|
|
|
268
|
-
|
|
269
|
-
export type Profile = {
|
|
270
|
-
bio: string;
|
|
271
|
-
avatar: string | null;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
export type User = {
|
|
275
|
-
id: string;
|
|
276
|
-
mainProfile: Profile; // Required reference
|
|
277
|
-
backupProfile: Profile | null; // Nullable reference
|
|
278
|
-
};
|
|
279
|
-
```
|
|
207
|
+
`mainProfile` is non-nullable (in `required`). `backupProfile` is nullable (not in `required`). Inside Profile, `bio` is non-nullable and `avatar` is nullable regardless of where Profile is referenced.
|
|
280
208
|
|
|
281
209
|
---
|
|
282
210
|
|
|
283
211
|
## Quick Reference
|
|
284
212
|
|
|
285
|
-
| Scenario
|
|
286
|
-
|
|
|
287
|
-
| Property in `required` array |
|
|
288
|
-
| Property NOT in `required`
|
|
289
|
-
| No `required` array
|
|
290
|
-
| `required: []` (empty)
|
|
291
|
-
| Nested object
|
|
292
|
-
| Array items
|
|
293
|
-
| References
|
|
213
|
+
| Scenario | Result |
|
|
214
|
+
| --- | --- |
|
|
215
|
+
| Property in `required` array | Non-nullable |
|
|
216
|
+
| Property NOT in `required` | Nullable |
|
|
217
|
+
| No `required` array | All properties nullable |
|
|
218
|
+
| `required: []` (empty) | All properties nullable |
|
|
219
|
+
| Nested object | Uses its own `required` array |
|
|
220
|
+
| Array items | Follow their own `required` rules |
|
|
221
|
+
| References | Reference position in `required` controls nullability |
|
|
@@ -38,14 +38,6 @@ types:
|
|
|
38
38
|
- $ref: '#/types/ErrorResponse'
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
**TypeScript:**
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
export type ApiResponse =
|
|
45
|
-
| { success: boolean; data: unknown }
|
|
46
|
-
| { success: boolean; error: string; code: number | null };
|
|
47
|
-
```
|
|
48
|
-
|
|
49
41
|
---
|
|
50
42
|
|
|
51
43
|
## Pattern 2: Paginated Response
|
|
@@ -88,9 +80,12 @@ types:
|
|
|
88
80
|
- id
|
|
89
81
|
- email
|
|
90
82
|
properties:
|
|
91
|
-
id:
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
id:
|
|
84
|
+
type: string
|
|
85
|
+
email:
|
|
86
|
+
type: string
|
|
87
|
+
name:
|
|
88
|
+
type: string
|
|
94
89
|
```
|
|
95
90
|
|
|
96
91
|
---
|
|
@@ -120,9 +115,12 @@ types:
|
|
|
120
115
|
- id
|
|
121
116
|
- email
|
|
122
117
|
properties:
|
|
123
|
-
id:
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
id:
|
|
119
|
+
type: string
|
|
120
|
+
email:
|
|
121
|
+
type: string
|
|
122
|
+
name:
|
|
123
|
+
type: string
|
|
126
124
|
|
|
127
125
|
Post:
|
|
128
126
|
allOf:
|
|
@@ -132,19 +130,12 @@ types:
|
|
|
132
130
|
- id
|
|
133
131
|
- title
|
|
134
132
|
properties:
|
|
135
|
-
id:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
export type User = Timestamps & {
|
|
144
|
-
id: string;
|
|
145
|
-
email: string;
|
|
146
|
-
name: string | null;
|
|
147
|
-
};
|
|
133
|
+
id:
|
|
134
|
+
type: string
|
|
135
|
+
title:
|
|
136
|
+
type: string
|
|
137
|
+
content:
|
|
138
|
+
type: string
|
|
148
139
|
```
|
|
149
140
|
|
|
150
141
|
---
|
|
@@ -224,17 +215,6 @@ types:
|
|
|
224
215
|
$ref: '#/types/MenuItem'
|
|
225
216
|
```
|
|
226
217
|
|
|
227
|
-
**TypeScript:**
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
export type MenuItem = {
|
|
231
|
-
id: string;
|
|
232
|
-
label: string;
|
|
233
|
-
url: string | null;
|
|
234
|
-
children: MenuItem[] | null;
|
|
235
|
-
};
|
|
236
|
-
```
|
|
237
|
-
|
|
238
218
|
---
|
|
239
219
|
|
|
240
220
|
## Pattern 6: Form Request/Response
|
|
@@ -294,9 +274,12 @@ types:
|
|
|
294
274
|
- id
|
|
295
275
|
- email
|
|
296
276
|
properties:
|
|
297
|
-
id:
|
|
298
|
-
|
|
299
|
-
|
|
277
|
+
id:
|
|
278
|
+
type: string
|
|
279
|
+
email:
|
|
280
|
+
type: string
|
|
281
|
+
name:
|
|
282
|
+
type: string
|
|
300
283
|
```
|
|
301
284
|
|
|
302
285
|
---
|
|
@@ -312,10 +295,15 @@ types:
|
|
|
312
295
|
- type
|
|
313
296
|
- createdAt
|
|
314
297
|
properties:
|
|
315
|
-
id:
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
298
|
+
id:
|
|
299
|
+
type: string
|
|
300
|
+
type:
|
|
301
|
+
type: string
|
|
302
|
+
createdAt:
|
|
303
|
+
type: string
|
|
304
|
+
format: date
|
|
305
|
+
read:
|
|
306
|
+
type: boolean
|
|
319
307
|
|
|
320
308
|
EmailNotification:
|
|
321
309
|
allOf:
|
|
@@ -327,9 +315,12 @@ types:
|
|
|
327
315
|
properties:
|
|
328
316
|
type:
|
|
329
317
|
type: string
|
|
330
|
-
enum:
|
|
331
|
-
|
|
332
|
-
|
|
318
|
+
enum:
|
|
319
|
+
- email
|
|
320
|
+
subject:
|
|
321
|
+
type: string
|
|
322
|
+
body:
|
|
323
|
+
type: string
|
|
333
324
|
|
|
334
325
|
SmsNotification:
|
|
335
326
|
allOf:
|
|
@@ -341,9 +332,12 @@ types:
|
|
|
341
332
|
properties:
|
|
342
333
|
type:
|
|
343
334
|
type: string
|
|
344
|
-
enum:
|
|
345
|
-
|
|
346
|
-
|
|
335
|
+
enum:
|
|
336
|
+
- sms
|
|
337
|
+
message:
|
|
338
|
+
type: string
|
|
339
|
+
phoneNumber:
|
|
340
|
+
type: string
|
|
347
341
|
|
|
348
342
|
PushNotification:
|
|
349
343
|
allOf:
|
|
@@ -354,9 +348,12 @@ types:
|
|
|
354
348
|
properties:
|
|
355
349
|
type:
|
|
356
350
|
type: string
|
|
357
|
-
enum:
|
|
358
|
-
|
|
359
|
-
|
|
351
|
+
enum:
|
|
352
|
+
- push
|
|
353
|
+
title:
|
|
354
|
+
type: string
|
|
355
|
+
body:
|
|
356
|
+
type: string
|
|
360
357
|
|
|
361
358
|
Notification:
|
|
362
359
|
oneOf:
|
|
@@ -378,21 +375,30 @@ types:
|
|
|
378
375
|
- port
|
|
379
376
|
- database
|
|
380
377
|
properties:
|
|
381
|
-
host:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
378
|
+
host:
|
|
379
|
+
type: string
|
|
380
|
+
port:
|
|
381
|
+
type: number
|
|
382
|
+
database:
|
|
383
|
+
type: string
|
|
384
|
+
username:
|
|
385
|
+
type: string
|
|
386
|
+
password:
|
|
387
|
+
type: string
|
|
388
|
+
ssl:
|
|
389
|
+
type: boolean
|
|
387
390
|
|
|
388
391
|
CacheConfig:
|
|
389
392
|
type: object
|
|
390
393
|
required:
|
|
391
394
|
- enabled
|
|
392
395
|
properties:
|
|
393
|
-
enabled:
|
|
394
|
-
|
|
395
|
-
|
|
396
|
+
enabled:
|
|
397
|
+
type: boolean
|
|
398
|
+
ttl:
|
|
399
|
+
type: number
|
|
400
|
+
maxSize:
|
|
401
|
+
type: number
|
|
396
402
|
|
|
397
403
|
AppConfig:
|
|
398
404
|
type: object
|
|
@@ -402,7 +408,10 @@ types:
|
|
|
402
408
|
properties:
|
|
403
409
|
environment:
|
|
404
410
|
type: string
|
|
405
|
-
enum:
|
|
411
|
+
enum:
|
|
412
|
+
- development
|
|
413
|
+
- staging
|
|
414
|
+
- production
|
|
406
415
|
database:
|
|
407
416
|
$ref: '#/types/DatabaseConfig'
|
|
408
417
|
cache:
|
|
@@ -446,18 +455,24 @@ groupedTypes:
|
|
|
446
455
|
UserTypes:
|
|
447
456
|
User:
|
|
448
457
|
type: object
|
|
449
|
-
required:
|
|
458
|
+
required:
|
|
459
|
+
- id
|
|
460
|
+
- email
|
|
450
461
|
properties:
|
|
451
|
-
id:
|
|
452
|
-
|
|
462
|
+
id:
|
|
463
|
+
type: string
|
|
464
|
+
email:
|
|
465
|
+
type: string
|
|
453
466
|
profile:
|
|
454
467
|
$ref: '#/groupedTypes/UserTypes/UserProfile'
|
|
455
468
|
|
|
456
469
|
UserProfile:
|
|
457
470
|
type: object
|
|
458
471
|
properties:
|
|
459
|
-
name:
|
|
460
|
-
|
|
472
|
+
name:
|
|
473
|
+
type: string
|
|
474
|
+
avatar:
|
|
475
|
+
type: string
|
|
461
476
|
```
|
|
462
477
|
|
|
463
478
|
---
|
|
@@ -466,7 +481,6 @@ groupedTypes:
|
|
|
466
481
|
|
|
467
482
|
```yaml
|
|
468
483
|
types:
|
|
469
|
-
# String to string map
|
|
470
484
|
Headers:
|
|
471
485
|
type: object
|
|
472
486
|
additionalProperties:
|
|
@@ -474,12 +488,10 @@ types:
|
|
|
474
488
|
valueType:
|
|
475
489
|
type: string
|
|
476
490
|
|
|
477
|
-
# String to any map
|
|
478
491
|
Metadata:
|
|
479
492
|
type: object
|
|
480
493
|
additionalProperties: true
|
|
481
494
|
|
|
482
|
-
# ID to entity map
|
|
483
495
|
UserCache:
|
|
484
496
|
type: object
|
|
485
497
|
additionalProperties:
|
|
@@ -487,13 +499,13 @@ types:
|
|
|
487
499
|
valueType:
|
|
488
500
|
$ref: '#/types/User'
|
|
489
501
|
|
|
490
|
-
# Mixed: fixed properties + dynamic
|
|
491
502
|
Response:
|
|
492
503
|
type: object
|
|
493
504
|
required:
|
|
494
505
|
- status
|
|
495
506
|
properties:
|
|
496
|
-
status:
|
|
507
|
+
status:
|
|
508
|
+
type: number
|
|
497
509
|
additionalProperties:
|
|
498
510
|
keyType: string
|
|
499
511
|
valueType:
|
|
@@ -501,16 +513,9 @@ types:
|
|
|
501
513
|
|
|
502
514
|
User:
|
|
503
515
|
type: object
|
|
504
|
-
required:
|
|
516
|
+
required:
|
|
517
|
+
- id
|
|
505
518
|
properties:
|
|
506
|
-
id:
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
**TypeScript:**
|
|
510
|
-
|
|
511
|
-
```typescript
|
|
512
|
-
export type Headers = { [keys: string]: string };
|
|
513
|
-
export type Metadata = { [keys: string]: unknown };
|
|
514
|
-
export type UserCache = { [keys: string]: User };
|
|
515
|
-
export type Response = { status: number; [keys: string]: unknown };
|
|
519
|
+
id:
|
|
520
|
+
type: string
|
|
516
521
|
```
|