@sdk-it/spec 0.43.0 → 0.45.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/lib/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,KAAK,GAAG,GAAG,iBAAiB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG;IAClE,EAAE,EAAE,GAAG,CAAC;IACR,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,EAAE,EACR,QAAQ,EAAE,yBAAyB,EAAE,EACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CAAC,EACvE,QAAQ,CAAC,EAAE,GAAG,kBA8Cf;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,kBA4BhC"}
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/lib/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,KAAK,GAAG,GAAG,iBAAiB,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG;IAClE,EAAE,EAAE,GAAG,CAAC;IACR,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,EAAE,EACR,QAAQ,EAAE,yBAAyB,EAAE,EACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CAAC,EACvE,QAAQ,CAAC,EAAE,GAAG,kBAkDf;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,kBAiChC"}
@@ -1,7 +1,7 @@
1
1
  import { methods } from "@sdk-it/core/paths.js";
2
2
  import { resolveRef } from "@sdk-it/core/ref.js";
3
3
  function securityToOptions(spec, security2, securitySchemes, staticIn) {
4
- const parameters = [];
4
+ const parameters = /* @__PURE__ */ new Map();
5
5
  for (const it of security2) {
6
6
  const [name] = Object.keys(it);
7
7
  if (!name) {
@@ -12,7 +12,7 @@ function securityToOptions(spec, security2, securitySchemes, staticIn) {
12
12
  securitySchemes[name]
13
13
  );
14
14
  if (schema.type === "http") {
15
- parameters.push({
15
+ parameters.set(`${staticIn ?? "header"}:authorization`, {
16
16
  in: staticIn ?? "header",
17
17
  name: "authorization",
18
18
  required: false,
@@ -29,8 +29,9 @@ function securityToOptions(spec, security2, securitySchemes, staticIn) {
29
29
  if (!schema.name) {
30
30
  throw new Error(`apiKey security schema must have a "name" field`);
31
31
  }
32
- parameters.push({
33
- in: staticIn ?? schema.in,
32
+ const paramIn = staticIn ?? schema.in;
33
+ parameters.set(`${paramIn}:${schema.name}`, {
34
+ in: paramIn,
34
35
  name: schema.name,
35
36
  required: false,
36
37
  schema: { type: "string" },
@@ -39,34 +40,36 @@ function securityToOptions(spec, security2, securitySchemes, staticIn) {
39
40
  continue;
40
41
  }
41
42
  }
42
- return parameters;
43
+ return [...parameters.values()];
43
44
  }
44
45
  function security(spec) {
45
46
  const security2 = spec.security || [];
46
47
  const paths = Object.values(spec.paths ?? {});
47
- const options = securityToOptions(
48
+ const options = /* @__PURE__ */ new Map();
49
+ for (const option of securityToOptions(
48
50
  spec,
49
51
  security2,
50
52
  spec.components.securitySchemes
51
- );
53
+ )) {
54
+ options.set(`${option.in}:${option.name}`, option);
55
+ }
52
56
  for (const it of paths) {
53
57
  for (const method of methods) {
54
58
  const operation = it[method];
55
59
  if (!operation) {
56
60
  continue;
57
61
  }
58
- Object.assign(
59
- options,
60
- securityToOptions(
61
- spec,
62
- operation.security || [],
63
- spec.components.securitySchemes,
64
- "input"
65
- )
66
- );
62
+ for (const option of securityToOptions(
63
+ spec,
64
+ operation.security || [],
65
+ spec.components.securitySchemes,
66
+ "input"
67
+ )) {
68
+ options.set(`${option.in}:${option.name}`, option);
69
+ }
67
70
  }
68
71
  }
69
- return options;
72
+ return [...options.values()];
70
73
  }
71
74
  export {
72
75
  security,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/security.ts"],
4
- "sourcesContent": ["import type {\n ParameterLocation,\n ParameterObject,\n ReferenceObject,\n SchemaObject,\n SecurityRequirementObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { resolveRef } from '@sdk-it/core/ref.js';\n\nimport type { IR } from './types.js';\n\ntype OIn = ParameterLocation | 'input';\n\nexport type OurParameter = Omit<ParameterObject, 'in' | 'schema'> & {\n in: OIn;\n 'x-optionName'?: string;\n schema: SchemaObject;\n};\n\nexport function securityToOptions(\n spec: IR,\n security: SecurityRequirementObject[],\n securitySchemes: Record<string, SecuritySchemeObject | ReferenceObject>,\n staticIn?: OIn,\n) {\n const parameters: OurParameter[] = [];\n for (const it of security) {\n const [name] = Object.keys(it);\n if (!name) {\n // this means the operation doesn't necessarily require security\n continue;\n }\n\n const schema = resolveRef<SecuritySchemeObject>(\n spec,\n securitySchemes[name],\n );\n if (schema.type === 'http') {\n parameters.push({\n in: staticIn ?? 'header',\n name: 'authorization',\n required: false,\n schema: { type: 'string', 'x-prefix': 'Bearer ' },\n 'x-optionName': 'token',\n example:\n schema.scheme === 'bearer'\n ? '\"<token>\"'\n : `<${schema.scheme}> <token>`,\n });\n continue;\n }\n if (schema.type === 'apiKey') {\n if (!schema.in) {\n throw new Error(`apiKey security schema must have an \"in\" field`);\n }\n if (!schema.name) {\n throw new Error(`apiKey security schema must have a \"name\" field`);\n }\n parameters.push({\n in: staticIn ?? (schema.in as ParameterLocation),\n name: schema.name,\n required: false,\n schema: { type: 'string' },\n example: `\"proj-${crypto.randomUUID().slice(0, 12)}\"`,\n });\n continue;\n }\n }\n return parameters;\n}\n\nexport function security(spec: IR) {\n const security = spec.security || [];\n const paths = Object.values(spec.paths ?? {});\n\n const options = securityToOptions(\n spec,\n security,\n spec.components.securitySchemes,\n );\n\n for (const it of paths) {\n for (const method of methods) {\n const operation = it[method];\n if (!operation) {\n continue;\n }\n Object.assign(\n options,\n securityToOptions(\n spec,\n operation.security || [],\n spec.components.securitySchemes,\n 'input',\n ),\n );\n }\n }\n return options;\n}\n"],
5
- "mappings": "AASA,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAYpB,SAAS,kBACd,MACAA,WACA,iBACA,UACA;AACA,QAAM,aAA6B,CAAC;AACpC,aAAW,MAAMA,WAAU;AACzB,UAAM,CAAC,IAAI,IAAI,OAAO,KAAK,EAAE;AAC7B,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAEA,UAAM,SAAS;AAAA,MACb;AAAA,MACA,gBAAgB,IAAI;AAAA,IACtB;AACA,QAAI,OAAO,SAAS,QAAQ;AAC1B,iBAAW,KAAK;AAAA,QACd,IAAI,YAAY;AAAA,QAChB,MAAM;AAAA,QACN,UAAU;AAAA,QACV,QAAQ,EAAE,MAAM,UAAU,YAAY,UAAU;AAAA,QAChD,gBAAgB;AAAA,QAChB,SACE,OAAO,WAAW,WACd,cACA,IAAI,OAAO,MAAM;AAAA,MACzB,CAAC;AACD;AAAA,IACF;AACA,QAAI,OAAO,SAAS,UAAU;AAC5B,UAAI,CAAC,OAAO,IAAI;AACd,cAAM,IAAI,MAAM,gDAAgD;AAAA,MAClE;AACA,UAAI,CAAC,OAAO,MAAM;AAChB,cAAM,IAAI,MAAM,iDAAiD;AAAA,MACnE;AACA,iBAAW,KAAK;AAAA,QACd,IAAI,YAAa,OAAO;AAAA,QACxB,MAAM,OAAO;AAAA,QACb,UAAU;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,SAAS,OAAO,WAAW,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,MACpD,CAAC;AACD;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,SAAS,MAAU;AACjC,QAAMA,YAAW,KAAK,YAAY,CAAC;AACnC,QAAM,QAAQ,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC;AAE5C,QAAM,UAAU;AAAA,IACd;AAAA,IACAA;AAAA,IACA,KAAK,WAAW;AAAA,EAClB;AAEA,aAAW,MAAM,OAAO;AACtB,eAAW,UAAU,SAAS;AAC5B,YAAM,YAAY,GAAG,MAAM;AAC3B,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE;AAAA,UACA,UAAU,YAAY,CAAC;AAAA,UACvB,KAAK,WAAW;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import type {\n ParameterLocation,\n ParameterObject,\n ReferenceObject,\n SchemaObject,\n SecurityRequirementObject,\n SecuritySchemeObject,\n} from 'openapi3-ts/oas31';\n\nimport { methods } from '@sdk-it/core/paths.js';\nimport { resolveRef } from '@sdk-it/core/ref.js';\n\nimport type { IR } from './types.js';\n\ntype OIn = ParameterLocation | 'input';\n\nexport type OurParameter = Omit<ParameterObject, 'in' | 'schema'> & {\n in: OIn;\n 'x-optionName'?: string;\n schema: SchemaObject;\n};\n\nexport function securityToOptions(\n spec: IR,\n security: SecurityRequirementObject[],\n securitySchemes: Record<string, SecuritySchemeObject | ReferenceObject>,\n staticIn?: OIn,\n) {\n // Distinct schemes can resolve to the same parameter (e.g. Figma's\n // PersonalAccessToken and PlanAccessToken both use the X-Figma-Token\n // header), so key by location + name to avoid duplicate options.\n const parameters = new Map<string, OurParameter>();\n for (const it of security) {\n const [name] = Object.keys(it);\n if (!name) {\n // this means the operation doesn't necessarily require security\n continue;\n }\n\n const schema = resolveRef<SecuritySchemeObject>(\n spec,\n securitySchemes[name],\n );\n if (schema.type === 'http') {\n parameters.set(`${staticIn ?? 'header'}:authorization`, {\n in: staticIn ?? 'header',\n name: 'authorization',\n required: false,\n schema: { type: 'string', 'x-prefix': 'Bearer ' },\n 'x-optionName': 'token',\n example:\n schema.scheme === 'bearer'\n ? '\"<token>\"'\n : `<${schema.scheme}> <token>`,\n });\n continue;\n }\n if (schema.type === 'apiKey') {\n if (!schema.in) {\n throw new Error(`apiKey security schema must have an \"in\" field`);\n }\n if (!schema.name) {\n throw new Error(`apiKey security schema must have a \"name\" field`);\n }\n const paramIn = staticIn ?? (schema.in as ParameterLocation);\n parameters.set(`${paramIn}:${schema.name}`, {\n in: paramIn,\n name: schema.name,\n required: false,\n schema: { type: 'string' },\n example: `\"proj-${crypto.randomUUID().slice(0, 12)}\"`,\n });\n continue;\n }\n }\n return [...parameters.values()];\n}\n\nexport function security(spec: IR) {\n const security = spec.security || [];\n const paths = Object.values(spec.paths ?? {});\n\n // Same keying as securityToOptions: two parameters may share a name but\n // differ in location (e.g. header vs query api keys), so name alone drops\n // credentials.\n const options = new Map<string, OurParameter>();\n for (const option of securityToOptions(\n spec,\n security,\n spec.components.securitySchemes,\n )) {\n options.set(`${option.in}:${option.name}`, option);\n }\n\n for (const it of paths) {\n for (const method of methods) {\n const operation = it[method];\n if (!operation) {\n continue;\n }\n for (const option of securityToOptions(\n spec,\n operation.security || [],\n spec.components.securitySchemes,\n 'input',\n )) {\n options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ACnC,QAAM,QAAQ,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC;AAK5C,QAAM,UAAU,oBAAI,IAA0B;AAC9C,aAAW,UAAU;AAAA,IACnB;AAAA,IACAA;AAAA,IACA,KAAK,WAAW;AAAA,EAClB,GAAG;AACD,YAAQ,IAAI,GAAG,OAAO,EAAE,IAAI,OAAO,IAAI,IAAI,MAAM;AAAA,EACnD;AAEA,aAAW,MAAM,OAAO;AACtB,eAAW,UAAU,SAAS;AAC5B,YAAM,YAAY,GAAG,MAAM;AAC3B,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AACA,iBAAW,UAAU;AAAA,QACnB;AAAA,QACA,UAAU,YAAY,CAAC;AAAA,QACvB,KAAK,WAAW;AAAA,QAChB;AAAA,MACF,GAAG;AACD,gBAAQ,IAAI,GAAG,OAAO,EAAE,IAAI,OAAO,IAAI,IAAI,MAAM;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;AAC7B;",
6
6
  "names": ["security"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdk-it/spec",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "!**/*.test.*"
28
28
  ],
29
29
  "dependencies": {
30
- "@sdk-it/core": "0.43.0",
30
+ "@sdk-it/core": "0.45.0",
31
31
  "openapi3-ts": "4.5.0",
32
32
  "pluralize": "^8.0.0",
33
33
  "stringcase": "^4.3.1",