Skip to content

Commit c130b98

Browse files
authored
Merge pull request #2079 from hey-api/fix/validator-comments
fix(validators): generate JSDoc comments for validator schemas
2 parents e514a13 + d478d8a commit c130b98

File tree

117 files changed

+3800
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3800
-24
lines changed

.changeset/light-carrots-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix(validators): generate JSDoc comments for validator schemas

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export const vBar = v.object({
1212
foo: v.pipe(v.number(), v.integer())
1313
});
1414

15+
/**
16+
* OK
17+
*/
1518
export const vPostFooResponse = vFoo;

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export const zBar = z.object({
1212
foo: z.number().int()
1313
});
1414

15+
/**
16+
* OK
17+
*/
1518
export const zPostFooResponse = zFoo;

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,86 @@
22

33
import * as v from 'valibot';
44

5+
/**
6+
* Testing multiline comments in string: First line
7+
* Second line
8+
*
9+
* Fourth line
10+
*/
511
export const vCommentWithBreaks = v.pipe(v.number(), v.integer());
612

13+
/**
14+
* Testing backticks in string: `backticks` and ```multiple backticks``` should work
15+
*/
716
export const vCommentWithBackticks = v.pipe(v.number(), v.integer());
817

18+
/**
19+
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
20+
*/
921
export const vCommentWithBackticksAndQuotes = v.pipe(v.number(), v.integer());
1022

23+
/**
24+
* Testing slashes in string: \backwards\\\ and /forwards/// should work
25+
*/
1126
export const vCommentWithSlashes = v.pipe(v.number(), v.integer());
1227

28+
/**
29+
* Testing expression placeholders in string: ${expression} should work
30+
*/
1331
export const vCommentWithExpressionPlaceholders = v.pipe(v.number(), v.integer());
1432

33+
/**
34+
* Testing quotes in string: 'single quote''' and "double quotes""" should work
35+
*/
1536
export const vCommentWithQuotes = v.pipe(v.number(), v.integer());
1637

38+
/**
39+
* Testing reserved characters in string: * inline * and ** inline ** should work
40+
*/
1741
export const vCommentWithReservedCharacters = v.pipe(v.number(), v.integer());
1842

43+
/**
44+
* This is a simple number
45+
*/
1946
export const vSimpleInteger = v.pipe(v.number(), v.integer());
2047

48+
/**
49+
* This is a simple boolean
50+
*/
2151
export const vSimpleBoolean = v.boolean();
2252

53+
/**
54+
* This is a simple string
55+
*/
2356
export const vSimpleString = v.string();
2457

58+
/**
59+
* A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串)
60+
*/
2561
export const vNonAsciiStringæøåÆøÅöôêÊ字符串 = v.string();
2662

63+
/**
64+
* This is a simple file
65+
*/
2766
export const vSimpleFile = v.string();
2867

68+
/**
69+
* This is a model with one string property
70+
*/
2971
export const vModelWithString = v.object({
3072
prop: v.optional(v.string())
3173
});
3274

3375
export const vSimpleReference = vModelWithString;
3476

77+
/**
78+
* This is a simple string
79+
*/
3580
export const vSimpleStringWithPattern = v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/));
3681

82+
/**
83+
* This is a simple enum with strings
84+
*/
3785
export const vEnumWithStrings = v.picklist([
3886
'Success',
3987
'Warning',
@@ -43,51 +91,108 @@ export const vEnumWithStrings = v.picklist([
4391
'Non-ascii: øæåôöØÆÅÔÖ字符串'
4492
]);
4593

94+
/**
95+
* This is a simple enum with numbers
96+
*/
4697
export const vEnumWithNumbers = v.unknown();
4798

99+
/**
100+
* Success=1,Warning=2,Error=3
101+
*/
48102
export const vEnumFromDescription = v.number();
49103

104+
/**
105+
* This is a simple enum with numbers
106+
*/
50107
export const vEnumWithExtensions = v.unknown();
51108

109+
/**
110+
* This is a simple array with numbers
111+
*/
52112
export const vArrayWithNumbers = v.array(v.pipe(v.number(), v.integer()));
53113

114+
/**
115+
* This is a simple array with booleans
116+
*/
54117
export const vArrayWithBooleans = v.array(v.boolean());
55118

119+
/**
120+
* This is a simple array with strings
121+
*/
56122
export const vArrayWithStrings = v.array(v.string());
57123

124+
/**
125+
* This is a simple array with references
126+
*/
58127
export const vArrayWithReferences = v.array(vModelWithString);
59128

129+
/**
130+
* This is a simple array containing an array
131+
*/
60132
export const vArrayWithArray = v.array(v.array(vModelWithString));
61133

134+
/**
135+
* This is a simple array with properties
136+
*/
62137
export const vArrayWithProperties = v.array(v.object({
63138
foo: v.optional(v.string()),
64139
bar: v.optional(v.string())
65140
}));
66141

142+
/**
143+
* This is a string dictionary
144+
*/
67145
export const vDictionaryWithString = v.object({});
68146

147+
/**
148+
* This is a string reference
149+
*/
69150
export const vDictionaryWithReference = v.object({});
70151

152+
/**
153+
* This is a complex dictionary
154+
*/
71155
export const vDictionaryWithArray = v.object({});
72156

157+
/**
158+
* This is a string dictionary
159+
*/
73160
export const vDictionaryWithDictionary = v.object({});
74161

162+
/**
163+
* This is a complex dictionary
164+
*/
75165
export const vDictionaryWithProperties = v.object({});
76166

167+
/**
168+
* This is a type-only model that defines Date as a string
169+
*/
77170
export const vDate = v.string();
78171

172+
/**
173+
* This is a model with one number property
174+
*/
79175
export const vModelWithInteger = v.object({
80176
prop: v.optional(v.pipe(v.number(), v.integer()))
81177
});
82178

179+
/**
180+
* This is a model with one boolean property
181+
*/
83182
export const vModelWithBoolean = v.object({
84183
prop: v.optional(v.boolean())
85184
});
86185

186+
/**
187+
* This is a model with one string property
188+
*/
87189
export const vModelWithStringError = v.object({
88190
prop: v.optional(v.string())
89191
});
90192

193+
/**
194+
* This is a model with one string property
195+
*/
91196
export const vModelWithNullableString = v.object({
92197
nullableProp: v.optional(v.union([
93198
v.string(),
@@ -99,6 +204,9 @@ export const vModelWithNullableString = v.object({
99204
])
100205
});
101206

207+
/**
208+
* This is a model with one enum
209+
*/
102210
export const vModelWithEnum = v.object({
103211
test: v.optional(v.picklist([
104212
'Success',
@@ -117,10 +225,16 @@ export const vModelWithEnum = v.object({
117225
bool: v.optional(v.unknown())
118226
});
119227

228+
/**
229+
* This is a model with one enum
230+
*/
120231
export const vModelWithEnumFromDescription = v.object({
121232
test: v.optional(v.pipe(v.number(), v.integer()))
122233
});
123234

235+
/**
236+
* This is a model with nested enums
237+
*/
124238
export const vModelWithNestedEnums = v.object({
125239
dictionaryWithEnum: v.optional(v.object({})),
126240
dictionaryWithEnumFromDescription: v.optional(v.object({})),
@@ -132,6 +246,9 @@ export const vModelWithNestedEnums = v.object({
132246
arrayWithDescription: v.optional(v.array(v.pipe(v.number(), v.integer())))
133247
});
134248

249+
/**
250+
* This is a model with one nested property
251+
*/
135252
export const vModelWithProperties = v.object({
136253
required: v.string(),
137254
requiredAndReadOnly: v.pipe(v.string(), v.readonly()),
@@ -146,26 +263,41 @@ export const vModelWithProperties = v.object({
146263
'@namespace.integer': v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly()))
147264
});
148265

266+
/**
267+
* This is a model with one property containing a reference
268+
*/
149269
export const vModelWithReference = v.object({
150270
prop: v.optional(vModelWithProperties)
151271
});
152272

273+
/**
274+
* This is a model with one property containing an array
275+
*/
153276
export const vModelWithArray = v.object({
154277
prop: v.optional(v.array(vModelWithString)),
155278
propWithFile: v.optional(v.array(v.string())),
156279
propWithNumber: v.optional(v.array(v.number()))
157280
});
158281

282+
/**
283+
* This is a model with one property containing a dictionary
284+
*/
159285
export const vModelWithDictionary = v.object({
160286
prop: v.optional(v.object({}))
161287
});
162288

289+
/**
290+
* This is a model with one property containing a circular reference
291+
*/
163292
export const vModelWithCircularReference: v.GenericSchema = v.object({
164293
prop: v.optional(v.lazy(() => {
165294
return vModelWithCircularReference;
166295
}))
167296
});
168297

298+
/**
299+
* This is a model with one nested property
300+
*/
169301
export const vModelWithNestedProperties = v.object({
170302
first: v.pipe(v.object({
171303
second: v.pipe(v.object({
@@ -174,22 +306,34 @@ export const vModelWithNestedProperties = v.object({
174306
}), v.readonly())
175307
});
176308

309+
/**
310+
* This is a model with duplicated properties
311+
*/
177312
export const vModelWithDuplicateProperties = v.object({
178313
prop: v.optional(vModelWithString)
179314
});
180315

316+
/**
317+
* This is a model with ordered properties
318+
*/
181319
export const vModelWithOrderedProperties = v.object({
182320
zebra: v.optional(v.string()),
183321
apple: v.optional(v.string()),
184322
hawaii: v.optional(v.string())
185323
});
186324

325+
/**
326+
* This is a model with duplicated imports
327+
*/
187328
export const vModelWithDuplicateImports = v.object({
188329
propA: v.optional(vModelWithString),
189330
propB: v.optional(vModelWithString),
190331
propC: v.optional(vModelWithString)
191332
});
192333

334+
/**
335+
* This is a model that extends another model
336+
*/
193337
export const vModelThatExtends = v.intersect([
194338
vModelWithString,
195339
v.object({
@@ -198,6 +342,9 @@ export const vModelThatExtends = v.intersect([
198342
})
199343
]);
200344

345+
/**
346+
* This is a model that extends another model
347+
*/
201348
export const vModelThatExtendsExtends = v.intersect([
202349
vModelWithString,
203350
vModelThatExtends,
@@ -211,6 +358,9 @@ export const vDefault = v.object({
211358
name: v.optional(v.string())
212359
});
213360

361+
/**
362+
* This is a model that contains a some patterns
363+
*/
214364
export const vModelWithPattern = v.object({
215365
key: v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)),
216366
name: v.pipe(v.string(), v.maxLength(255)),
@@ -250,8 +400,14 @@ export const vCallWithResponseAndNoContentResponseResponse = v.union([
250400
v.unknown()
251401
]);
252402

403+
/**
404+
* Message for default response
405+
*/
253406
export const vCallWithResponseResponse = vModelWithString;
254407

408+
/**
409+
* Message for 201 response
410+
*/
255411
export const vCallWithDuplicateResponsesResponse = vModelWithString;
256412

257413
export const vCallWithResponsesResponse = v.union([
@@ -271,8 +427,17 @@ export const vTypesResponse = v.union([
271427
v.object({})
272428
]);
273429

430+
/**
431+
* Successful response
432+
*/
274433
export const vComplexTypesResponse = v.array(vModelWithString);
275434

435+
/**
436+
* Successful response
437+
*/
276438
export const vNonAsciiæøåÆøÅöôêÊ字符串Response = vNonAsciiStringæøåÆøÅöôêÊ字符串;
277439

440+
/**
441+
* OK
442+
*/
278443
export const vPostApiVbyApiVersionBodyResponse = vResponsePostActivityResponse;

0 commit comments

Comments
 (0)