@voxgig/apidef 8.33.2 → 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/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,