Skip to content

Commit ad1cc06

Browse files
committed
feat: improve jsdoc fields declaration
1 parent 5891b60 commit ad1cc06

File tree

36 files changed

+3720
-1570
lines changed

36 files changed

+3720
-1570
lines changed

templates/base/data-contract-jsdoc.ejs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const { data, utils } = it;
33
const { formatDescription, require, _ } = utils;
44
5+
const stringify = (value) => _.isObject(value) ? JSON.stringify(value) : _.isString(value) ? `"${value}"` : value
6+
57
const jsDocLines = _.compact([
68
data.title,
79
data.description && formatDescription(data.description),
@@ -13,9 +15,13 @@ const jsDocLines = _.compact([
1315
!_.isUndefined(data.maximum) && `@max ${data.maximum}`,
1416
!_.isUndefined(data.minLength) && `@minLength ${data.minLength}`,
1517
!_.isUndefined(data.maxLength) && `@maxLength ${data.maxLength}`,
16-
!_.isUndefined(data.exclusiveMax) && `@exclusiveMax ${data.exclusiveMax}`,
18+
!_.isUndefined(data.exclusiveMaximum) && `@exclusiveMax ${data.exclusiveMaximum}`,
19+
!_.isUndefined(data.maxItems) && `@maxItems ${data.maxItems}`,
20+
!_.isUndefined(data.minItems) && `@minItems ${data.minItems}`,
21+
!_.isUndefined(data.uniqueItems) && `@uniqueItems ${data.uniqueItems}`,
22+
!_.isUndefined(data.default) && `@default ${stringify(data.default)}`,
1723
!_.isUndefined(data.pattern) && `@pattern ${data.pattern}`,
18-
!_.isUndefined(data.example) && `@example ${_.isObject(data.example) ? JSON.stringify(data.example) : data.example}`
24+
!_.isUndefined(data.example) && `@example ${stringify(data.example)}`
1925
]).join('\n').split('\n');
2026
%>
2127
<% if (jsDocLines.every(_.isEmpty)) { %>

tests/generated/v2.0/adafruit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export interface Feed {
112112
unit_symbol?: string;
113113
unit_type?: string;
114114
updated_at?: string;
115+
/** @default "private" */
115116
visibility?: "private" | "public" | "in progress" | "out of access";
116117
}
117118

@@ -127,8 +128,10 @@ export interface Group {
127128
export interface Permission {
128129
created_at?: string;
129130
id?: number;
131+
/** @default "feed" */
130132
model?: "feed" | "group" | "dashboard";
131133
object_id?: number;
134+
/** @default "public" */
132135
scope?: "secret" | "public" | "user" | "organization";
133136
scope_value?: string;
134137
updated_at?: string;
@@ -2251,7 +2254,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
22512254
typeId: string,
22522255
id: string,
22532256
permission: {
2257+
/** @default "r" */
22542258
mode?: "r" | "w" | "rw";
2259+
/** @default "public" */
22552260
scope?: "secret" | "public" | "user" | "organization";
22562261
scope_value?: string;
22572262
},
@@ -2282,7 +2287,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
22822287
typeId: string,
22832288
id: string,
22842289
permission: {
2290+
/** @default "r" */
22852291
mode?: "r" | "w" | "rw";
2292+
/** @default "public" */
22862293
scope?: "secret" | "public" | "user" | "organization";
22872294
scope_value?: string;
22882295
},

tests/generated/v2.0/another-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type Currency = string;
5757
* @example {"petId":6,"quantity":1,"id":0,"shipDate":"2000-01-23T04:56:07.000+00:00","complete":false,"status":"placed"}
5858
*/
5959
export interface Order {
60+
/** @default false */
6061
complete?: boolean;
6162
/** @format int64 */
6263
id?: number;
@@ -80,7 +81,7 @@ export interface Pet {
8081
category?: Category;
8182
/** @format int64 */
8283
id?: number;
83-
/** @example doggie */
84+
/** @example "doggie" */
8485
name: string;
8586
photoUrls: string[];
8687
/** pet status in the store */

tests/generated/v2.0/giphy.ts

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
export interface Gif {
1313
/**
1414
* The unique bit.ly URL for this GIF
15-
* @example http://gph.is/1gsWDcL
15+
* @example "http://gph.is/1gsWDcL"
1616
*/
1717
bitly_url?: string;
1818
/** Currently unused */
1919
content_url?: string;
2020
/**
2121
* The date this GIF was added to the GIPHY database.
2222
* @format date-time
23-
* @example 2013-08-01 12:41:48
23+
* @example "2013-08-01 12:41:48"
2424
*/
2525
create_datetime?: string;
2626
/**
2727
* A URL used for embedding this GIF
28-
* @example http://giphy.com/embed/YsTs5ltWtEhnq
28+
* @example "http://giphy.com/embed/YsTs5ltWtEhnq"
2929
*/
3030
embded_url?: string;
3131
/** An array of featured tags for this GIF (Note: Not available when using the Public Beta Key) */
3232
featured_tags?: string[];
3333
/**
3434
* This GIF's unique ID
35-
* @example YsTs5ltWtEhnq
35+
* @example "YsTs5ltWtEhnq"
3636
*/
3737
id?: string;
3838
/** An object containing data for various available formats and sizes of this GIF. */
@@ -81,108 +81,111 @@ export interface Gif {
8181
/**
8282
* The creation or upload date from this GIF's source.
8383
* @format date-time
84-
* @example 2013-08-01 12:41:48
84+
* @example "2013-08-01 12:41:48"
8585
*/
8686
import_datetime?: string;
8787
/**
8888
* The MPAA-style rating for this content. Examples include Y, G, PG, PG-13 and R
89-
* @example g
89+
* @example "g"
9090
*/
9191
rating?: string;
9292
/**
9393
* The unique slug used in this GIF's URL
94-
* @example confused-flying-YsTs5ltWtEhnq
94+
* @example "confused-flying-YsTs5ltWtEhnq"
9595
*/
9696
slug?: string;
9797
/**
9898
* The page on which this GIF was found
99-
* @example http://www.reddit.com/r/reactiongifs/comments/1xpyaa/superman_goes_to_hollywood/
99+
* @example "http://www.reddit.com/r/reactiongifs/comments/1xpyaa/superman_goes_to_hollywood/"
100100
*/
101101
source?: string;
102102
/**
103103
* The URL of the webpage on which this GIF was found.
104-
* @example http://cheezburger.com/5282328320
104+
* @example "http://cheezburger.com/5282328320"
105105
*/
106106
source_post_url?: string;
107107
/**
108108
* The top level domain of the source URL.
109-
* @example cheezburger.com
109+
* @example "cheezburger.com"
110110
*/
111111
source_tld?: string;
112112
/** An array of tags for this GIF (Note: Not available when using the Public Beta Key) */
113113
tags?: string[];
114114
/**
115115
* The date on which this gif was marked trending, if applicable.
116116
* @format date-time
117-
* @example 2013-08-01 12:41:48
117+
* @example "2013-08-01 12:41:48"
118118
*/
119119
trending_datetime?: string;
120-
/** Type of the gif. By default, this is almost always gif */
120+
/**
121+
* Type of the gif. By default, this is almost always gif
122+
* @default "gif"
123+
*/
121124
type?: "gif";
122125
/**
123126
* The date on which this GIF was last updated.
124127
* @format date-time
125-
* @example 2013-08-01 12:41:48
128+
* @example "2013-08-01 12:41:48"
126129
*/
127130
update_datetime?: string;
128131
/**
129132
* The unique URL for this GIF
130-
* @example http://giphy.com/gifs/confused-flying-YsTs5ltWtEhnq
133+
* @example "http://giphy.com/gifs/confused-flying-YsTs5ltWtEhnq"
131134
*/
132135
url?: string;
133136
/** The User Object contains information about the user associated with a GIF and URLs to assets such as that user's avatar image, profile, and more. */
134137
user?: User;
135138
/**
136139
* The username this GIF is attached to, if applicable
137-
* @example JoeCool4000
140+
* @example "JoeCool4000"
138141
*/
139142
username?: string;
140143
}
141144

142145
export interface Image {
143146
/**
144147
* The URL for this GIF in .MP4 format.
145-
* @example https://media1.giphy.com/media/cZ7rmKfFYOvYI/giphy.mp4
148+
* @example "https://media1.giphy.com/media/cZ7rmKfFYOvYI/giphy.mp4"
146149
*/
147150
mp4?: string;
148151
/**
149152
* The size in bytes of the .MP4 file corresponding to this GIF.
150-
* @example 25123
153+
* @example "25123"
151154
*/
152155
mp4_size?: string;
153156
/**
154157
* The number of frames in this GIF.
155-
* @example 15
158+
* @example "15"
156159
*/
157160
frames?: string;
158161
/**
159162
* The height of this GIF in pixels.
160-
* @example 200
163+
* @example "200"
161164
*/
162165
height?: string;
163166
/**
164167
* The size of this GIF in bytes.
165-
* @example 32381
168+
* @example "32381"
166169
*/
167170
size?: string;
168171
/**
169172
* The publicly-accessible direct URL for this GIF.
170-
* @example https://media1.giphy.com/media/cZ7rmKfFYOvYI/200.gif
173+
* @example "https://media1.giphy.com/media/cZ7rmKfFYOvYI/200.gif"
171174
*/
172175
url?: string;
173176
/**
174177
* The URL for this GIF in .webp format.
175-
* @example https://media1.giphy.com/media/cZ7rmKfFYOvYI/giphy.webp
178+
* @example "https://media1.giphy.com/media/cZ7rmKfFYOvYI/giphy.webp"
176179
*/
177180
webp?: string;
178181
/**
179182
* The size in bytes of the .webp file corresponding to this GIF.
180-
* @example 12321
183+
* @example "12321"
181184
*/
182185
webp_size?: string;
183186
/**
184187
* The width of this GIF in pixels.
185-
* @example 320
188+
* @example "320"
186189
*/
187190
width?: string;
188191
}
@@ -191,12 +194,12 @@ export interface Image {
191194
export interface Meta {
192195
/**
193196
* HTTP Response Message
194-
* @example OK
197+
* @example "OK"
195198
*/
196199
msg?: string;
197200
/**
198201
* A unique ID paired with this response from the API.
199-
* @example 57eea03c72381f86e05c35d2
202+
* @example "57eea03c72381f86e05c35d2"
200203
*/
201204
response_id?: string;
202205
/**
@@ -233,32 +236,32 @@ export interface Pagination {
233236
export interface User {
234237
/**
235238
* The URL for this user's avatar image.
236-
* @example https://media1.giphy.com/avatars/election2016/XwYrZi5H87o6.gif
239+
* @example "https://media1.giphy.com/avatars/election2016/XwYrZi5H87o6.gif"
237240
*/
238241
avatar_url?: string;
239242
/**
240243
* The URL for the banner image that appears atop this user's profile page.
241-
* @example https://media4.giphy.com/avatars/cheezburger/XkuejOhoGLE6.jpg
244+
* @example "https://media4.giphy.com/avatars/cheezburger/XkuejOhoGLE6.jpg"
242245
*/
243246
banner_url?: string;
244247
/**
245248
* The display name associated with this user (contains formatting the base username might not).
246-
* @example JoeCool4000
249+
* @example "JoeCool4000"
247250
*/
248251
display_name?: string;
249252
/**
250253
* The URL for this user's profile.
251-
* @example https://giphy.com/cheezburger/
254+
* @example "https://giphy.com/cheezburger/"
252255
*/
253256
profile_url?: string;
254257
/**
255258
* The Twitter username associated with this user, if applicable.
256-
* @example @joecool4000
259+
* @example "@joecool4000"
257260
*/
258261
twitter?: string;
259262
/**
260263
* The username associated with this user.
261-
* @example joecool4000
264+
* @example "joecool4000"
262265
*/
263266
username?: string;
264267
}
@@ -567,11 +570,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
567570
/**
568571
* The maximum number of records to return.
569572
* @format int32
573+
* @default 25
570574
*/
571575
limit?: number;
572576
/**
573577
* An optional results offset.
574578
* @format int32
579+
* @default 0
575580
*/
576581
offset?: number;
577582
/** Filters results by specified rating. */
@@ -645,11 +650,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
645650
/**
646651
* The maximum number of records to return.
647652
* @format int32
653+
* @default 25
648654
*/
649655
limit?: number;
650656
/**
651657
* An optional results offset.
652658
* @format int32
659+
* @default 0
653660
*/
654661
offset?: number;
655662
/** Filters results by specified rating. */
@@ -751,11 +758,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
751758
/**
752759
* The maximum number of records to return.
753760
* @format int32
761+
* @default 25
754762
*/
755763
limit?: number;
756764
/**
757765
* An optional results offset.
758766
* @format int32
767+
* @default 0
759768
*/
760769
offset?: number;
761770
/** Filters results by specified rating. */
@@ -829,11 +838,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
829838
/**
830839
* The maximum number of records to return.
831840
* @format int32
841+
* @default 25
832842
*/
833843
limit?: number;
834844
/**
835845
* An optional results offset.
836846
* @format int32
847+
* @default 0
837848
*/
838849
offset?: number;
839850
/** Filters results by specified rating. */

0 commit comments

Comments
 (0)