@voxgig/apidef 8.25.2 → 8.25.4

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.
@@ -183,7 +183,7 @@ function resolveSummary(def: any): string | undefined {
183
183
  return firstSentence(explicit)
184
184
  }
185
185
 
186
- const desc = 'string' === typeof info.description ? info.description : ''
186
+ const desc = 'string' === typeof info.description ? htmlText(info.description) : ''
187
187
  if ('' === desc.trim() || !hasLetters(desc)) {
188
188
  return undefined
189
189
  }
@@ -208,6 +208,46 @@ function resolveSummary(def: any): string | undefined {
208
208
  }
209
209
 
210
210
 
211
+ const HTML_BLOCK = 'address|article|aside|blockquote|br|dd|div|dl|dt|figcaption|figure|footer|' +
212
+ 'header|hr|li|main|nav|ol|p|pre|section|table|tbody|td|tfoot|th|thead|tr|ul'
213
+ const HTML_INLINE = 'a|abbr|b|big|cite|code|em|font|i|img|kbd|mark|q|s|samp|small|span|' +
214
+ 'strong|sub|sup|tt|u|var'
215
+ const HTML_COMMENT_RE = /<!--[\s\S]*?(-->|$)/g
216
+ const HTML_HEADING_RE = /<h([1-6])([ \t\n\r\f][^<>]*)?>([\s\S]*?)<\/h[1-6][ \t\n\r\f]*>/gi
217
+ const HTML_BLOCK_RE =
218
+ new RegExp('<\\/?(' + HTML_BLOCK + '|h[1-6])([ \\t\\n\\r\\f][^<>]*)?\\/?>', 'gi')
219
+ const HTML_INLINE_RE =
220
+ new RegExp('<\\/?(' + HTML_INLINE + ')([ \\t\\n\\r\\f][^<>]*)?\\/?>', 'gi')
221
+ const HTML_ENTITY_RE = /&(#x[0-9a-f]{1,6}|#[0-9]{1,7}|amp|lt|gt|quot|apos|nbsp);/gi
222
+ const HTML_ENTITIES: Record<string, string> = {
223
+ amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: '\u00a0',
224
+ }
225
+
226
+
227
+ // HTML as the text the summary reads: a heading on a line of its own as a
228
+ // markdown heading, a block element as a paragraph break, other markup gone.
229
+ // Only HTML tag names count, so a generic such as List<String> is kept.
230
+ function htmlText(text: string): string {
231
+ return text
232
+ .replace(HTML_COMMENT_RE, '')
233
+ .replace(HTML_HEADING_RE, (_m, level, _attrs, inner) =>
234
+ '\n\n' + '#'.repeat(Number(level)) + ' ' +
235
+ inner.replace(HTML_BLOCK_RE, ' ').replace(HTML_INLINE_RE, '').replace(/\s+/g, ' ').trim() +
236
+ '\n\n')
237
+ .replace(HTML_BLOCK_RE, '\n\n')
238
+ .replace(HTML_INLINE_RE, '')
239
+ .replace(HTML_ENTITY_RE, (entity, name) => {
240
+ const key = name.toLowerCase()
241
+ if ('#' !== key[0]) {
242
+ return HTML_ENTITIES[key]
243
+ }
244
+ const code = 'x' === key[1] ? parseInt(key.slice(2), 16) : parseInt(key.slice(1), 10)
245
+ return 0 < code && code <= 0x10ffff && (code < 0xd800 || 0xdfff < code) ?
246
+ String.fromCodePoint(code) : entity
247
+ })
248
+ }
249
+
250
+
211
251
  // A server variable that opens the URL stands for its origin, or for its
212
252
  // scheme when `://` follows, so its value carries the scheme.
213
253
  const LEADING_VARIABLE_RE = /^\{([^{}]+)\}($|[/?#]|:\/\/)/
package/src/utility.ts CHANGED
@@ -959,6 +959,7 @@ function renderJSONIC(
959
959
 
960
960
  const VALID_CANON: Record<string, string> = Object.assign(Object.create(null), {
961
961
  'string': '`$STRING`',
962
+ 'file': '`$STRING`',
962
963
  'number': '`$NUMBER`',
963
964
  'integer': '`$INTEGER`',
964
965
  'boolean': '`$BOOLEAN`',
@@ -970,12 +971,23 @@ const VALID_CANON: Record<string, string> = Object.assign(Object.create(null), {
970
971
 
971
972
  const CANON_ONE = '`$ONE`'
972
973
 
974
+ const CANON_NULL = '`$NULL`'
975
+
976
+
977
+ function declaredType(type: string): string {
978
+ return type.toLowerCase().trim()
979
+ }
980
+
981
+
982
+ // Swagger 2's file, a binary string in OpenAPI 3.
983
+ function isFileType(type: unknown): boolean {
984
+ return 'string' === typeof type && 'file' === declaredType(type)
985
+ }
986
+
973
987
 
974
988
  function validator(torig: undefined | string | string[]): any {
975
989
  if ('string' === typeof torig) {
976
- const tstr = torig.toLowerCase().trim()
977
- const canon = VALID_CANON[tstr] ?? 'Any'
978
- return canon
990
+ return VALID_CANON[declaredType(torig)] ?? '`$ANY`'
979
991
  }
980
992
  else if (Array.isArray(torig)) {
981
993
  return [CANON_ONE, torig.map((t: string) => validator(t))]
@@ -985,6 +997,19 @@ function validator(torig: undefined | string | string[]): any {
985
997
  }
986
998
  }
987
999
 
1000
+ // The type a field holds when it is not null: the type itself, or the one
1001
+ // member of a union beside `$NULL`. Any other union has none.
1002
+ function nonNullType(type: any): string | undefined {
1003
+ if ('string' === typeof type) {
1004
+ return type
1005
+ }
1006
+ if (!Array.isArray(type) || CANON_ONE !== type[0] || !Array.isArray(type[1])) {
1007
+ return undefined
1008
+ }
1009
+ const members = type[1].filter((member: any) => CANON_NULL !== member)
1010
+ return 1 === members.length && 'string' === typeof members[0] ? members[0] : undefined
1011
+ }
1012
+
988
1013
  const FILE_EXT_RE =
989
1014
  /\.(php|json|txt|png|jpg|jpeg|gif|svg|xml|html|csv|yml|yaml|md)$/i
990
1015
 
@@ -1415,8 +1440,11 @@ function cleanComponentName(
1415
1440
  if (vI >= 0) {
1416
1441
  const after = parts.slice(vI + 1).join('_')
1417
1442
  const before = parts.slice(0, vI).join('_')
1443
+ // The namespace is the collection (CallRoutes), the record its item
1444
+ // (CallRouteAllowedCaller), so the namespace is tried singular too.
1418
1445
  const cands = after
1419
- ? [canonize(depluralize(after)), canonize(depluralize(before + '_' + after))]
1446
+ ? [canonize(depluralize(after)), canonize(depluralize(before + '_' + after)),
1447
+ canonize(depluralize(before) + '_' + depluralize(after))]
1420
1448
  : [canonize(depluralize(before))]
1421
1449
  for (const cand of cands) {
1422
1450
  if (cand.length >= 3 && knownWithVersion(cand, version)) {
@@ -2146,7 +2174,9 @@ function firstSentence(text: string): string {
2146
2174
  let out = m ? m[1] : collapsed
2147
2175
  const MAX = 240
2148
2176
  if (out.length > MAX) {
2149
- out = out.slice(0, MAX - 1).trimEnd() + '\u2026'
2177
+ const cut = out.slice(0, MAX - 1)
2178
+ const space = cut.lastIndexOf(' ')
2179
+ out = (0 < space ? cut.slice(0, space) : cut).trimEnd() + '\u2026'
2150
2180
  }
2151
2181
  return out
2152
2182
  }
@@ -2168,6 +2198,8 @@ export {
2168
2198
  makeWarner,
2169
2199
  formatJSONIC,
2170
2200
  validator,
2201
+ isFileType,
2202
+ nonNullType,
2171
2203
  VALID_CANON,
2172
2204
  CANON_ONE,
2173
2205
  canonize,