@voxgig/apidef 8.33.1 → 8.33.3
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/desc.d.ts +1 -0
- package/dist/guide/guide.js +2 -2
- package/dist/guide/guide.js.map +1 -1
- package/dist/guide/heuristic01.js +11 -7
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/parse.d.ts +2 -1
- package/dist/parse.js +41 -1
- package/dist/parse.js.map +1 -1
- package/dist/resolved.js +4 -2
- package/dist/resolved.js.map +1 -1
- package/dist/transform/args.js +1 -1
- package/dist/transform/args.js.map +1 -1
- package/dist/transform/entity.js +1 -1
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.js +3 -2
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/top.js +8 -0
- package/dist/transform/top.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +3 -1
- package/dist/utility.js +29 -0
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/src/desc.ts +1 -0
- package/src/guide/guide.ts +2 -2
- package/src/guide/heuristic01.ts +11 -7
- package/src/parse.ts +41 -1
- package/src/resolved.ts +5 -2
- package/src/transform/args.ts +2 -1
- package/src/transform/entity.ts +2 -2
- package/src/transform/field.ts +3 -2
- package/src/transform/top.ts +10 -1
- package/src/utility.ts +30 -0
package/src/transform/entity.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
|
|
25
25
|
import {
|
|
26
26
|
canonize, cmpRefName, depluralize, foldName, guideActive, guideParts, guidePath, isParam,
|
|
27
|
-
paramName, paramOf, READ_METHODS,
|
|
27
|
+
paramName, paramOf, READ_METHODS, routeParams,
|
|
28
28
|
} from '../utility'
|
|
29
29
|
|
|
30
30
|
import { byCodePoint } from '../refcount'
|
|
@@ -432,7 +432,7 @@ function separateSharedPoints(guide: any, def: any, log?: any): string[] {
|
|
|
432
432
|
// The names of the query, header and cookie arguments an operation requires.
|
|
433
433
|
function requiredArgs(def: any, pathStr: string, method: string): string[] {
|
|
434
434
|
const pathItem = def?.paths?.[pathStr] ?? {}
|
|
435
|
-
return
|
|
435
|
+
return routeParams(pathItem, pathItem[method])
|
|
436
436
|
.filter((param: any) => true === param?.required && 'path' !== param?.in &&
|
|
437
437
|
'body' !== param?.in && 'formData' !== param?.in && 'string' === typeof param?.name)
|
|
438
438
|
.map((param: any) => canonize(param.name))
|
package/src/transform/field.ts
CHANGED
|
@@ -731,7 +731,7 @@ function modelField(fielddef: SchemaDef): ModelField {
|
|
|
731
731
|
n: name,
|
|
732
732
|
h: humanTitle(name),
|
|
733
733
|
t: inferFieldType(name, validator(nullableType(fielddef))),
|
|
734
|
-
r:
|
|
734
|
+
r: true === (fielddef as any).required,
|
|
735
735
|
op: {},
|
|
736
736
|
}
|
|
737
737
|
const fdesc = (fielddef as any).description
|
|
@@ -1027,7 +1027,8 @@ function composedFields(schema: any): any[] {
|
|
|
1027
1027
|
return Object.keys(decls).map((name) => {
|
|
1028
1028
|
const property = 1 === decls[name].length ? decls[name][0] : mergeDeclarations(decls[name])
|
|
1029
1029
|
// A copy: parsed schemas are shared by every operation referencing them.
|
|
1030
|
-
|
|
1030
|
+
// An object property's own `required` lists ITS fields: only the parent's says it is required.
|
|
1031
|
+
return true !== property.required && required.has(name) ? { ...property, required: true } : property
|
|
1031
1032
|
})
|
|
1032
1033
|
}
|
|
1033
1034
|
|
package/src/transform/top.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '../utility'
|
|
9
9
|
|
|
10
10
|
import { METHODS } from '../resolved'
|
|
11
|
-
import { IGNORED_HEADERS_KEY } from '../parse'
|
|
11
|
+
import { DUPLICATE_PARAMS_KEY, IGNORED_HEADERS_KEY } from '../parse'
|
|
12
12
|
|
|
13
13
|
import type { TransformResult } from '../transform'
|
|
14
14
|
|
|
@@ -143,6 +143,15 @@ const topTransform = async function(
|
|
|
143
143
|
})
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
for (const repeat of def[DUPLICATE_PARAMS_KEY] ?? []) {
|
|
147
|
+
ctx.warn?.({
|
|
148
|
+
note: repeat.in + ' parameter `' + repeat.name + '` of ' +
|
|
149
|
+
(null == repeat.method ? '' : repeat.method + ' ') + repeat.path +
|
|
150
|
+
' is declared more than once: the first declaration is used (OpenAPI forbids' +
|
|
151
|
+
' a repeated parameter; fix the definition)',
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
const summary = resolveSummary(def)
|
|
147
156
|
if (null != summary) {
|
|
148
157
|
kit.info.summary = summary
|
package/src/utility.ts
CHANGED
|
@@ -2773,7 +2773,37 @@ function firstSentence(text: string): string {
|
|
|
2773
2773
|
}
|
|
2774
2774
|
|
|
2775
2775
|
|
|
2776
|
+
// The identity OpenAPI gives a parameter: its location and name.
|
|
2777
|
+
function paramKey(param: any): string | undefined {
|
|
2778
|
+
if (null == param || 'object' !== typeof param || 'string' !== typeof param.in || 'string' !== typeof param.name) return undefined
|
|
2779
|
+
return param.in + '\u0000' + ('header' === param.in ? param.name.toLowerCase() : param.name)
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
|
|
2783
|
+
// A route's parameters: the path item's, each replaced by the operation's own
|
|
2784
|
+
// declaration of the same location and name, then the operation's others.
|
|
2785
|
+
function routeParams(pathItem: any, op: any): any[] {
|
|
2786
|
+
const own: any[] = Array.isArray(op?.parameters) ? op.parameters : []
|
|
2787
|
+
const byKey = new Map<string, any>()
|
|
2788
|
+
for (const param of own) {
|
|
2789
|
+
const key = paramKey(param)
|
|
2790
|
+
if (null != key && !byKey.has(key)) byKey.set(key, param)
|
|
2791
|
+
}
|
|
2792
|
+
const used = new Set<any>()
|
|
2793
|
+
const shared = (Array.isArray(pathItem?.parameters) ? pathItem.parameters : []).map((param: any) => {
|
|
2794
|
+
const key = paramKey(param)
|
|
2795
|
+
const mine = null == key ? undefined : byKey.get(key)
|
|
2796
|
+
if (null == mine) return param
|
|
2797
|
+
used.add(mine)
|
|
2798
|
+
return mine
|
|
2799
|
+
})
|
|
2800
|
+
return [...shared, ...own.filter((param) => !used.has(param))]
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
|
|
2776
2804
|
export {
|
|
2805
|
+
paramKey,
|
|
2806
|
+
routeParams,
|
|
2777
2807
|
bodyRequestTransform,
|
|
2778
2808
|
nom,
|
|
2779
2809
|
getdlog,
|