@scalar/oas-utils 0.2.107 → 0.2.109

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/entities/spec/collection.d.ts +157 -113
  3. package/dist/entities/spec/collection.d.ts.map +1 -1
  4. package/dist/entities/spec/collection.js +4 -1
  5. package/dist/entities/spec/index.js +1 -1
  6. package/dist/entities/spec/operation.d.ts +12 -6
  7. package/dist/entities/spec/operation.d.ts.map +1 -1
  8. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  9. package/dist/entities/spec/request-examples.js +14 -11
  10. package/dist/entities/spec/requests.d.ts +24 -12
  11. package/dist/entities/spec/requests.d.ts.map +1 -1
  12. package/dist/entities/spec/spec-objects.d.ts +145 -73
  13. package/dist/entities/spec/spec-objects.d.ts.map +1 -1
  14. package/dist/entities/spec/spec-objects.js +62 -42
  15. package/dist/helpers/fetchWithProxyFallback.d.ts.map +1 -1
  16. package/dist/helpers/findVariables.d.ts.map +1 -1
  17. package/dist/helpers/findVariables.js +1 -1
  18. package/dist/helpers/httpMethods.d.ts.map +1 -1
  19. package/dist/helpers/is-defined.d.ts.map +1 -1
  20. package/dist/helpers/iterateTitle.d.ts.map +1 -1
  21. package/dist/helpers/makeUrlAbsolute.d.ts.map +1 -1
  22. package/dist/helpers/makeUrlAbsolute.js +1 -4
  23. package/dist/helpers/merge-urls.d.ts.map +1 -1
  24. package/dist/helpers/normalizeMimeTypeObject.d.ts +1 -0
  25. package/dist/helpers/normalizeMimeTypeObject.d.ts.map +1 -1
  26. package/dist/helpers/object.d.ts.map +1 -1
  27. package/dist/helpers/parse.d.ts.map +1 -1
  28. package/dist/helpers/prettyPrintJson.d.ts.map +1 -1
  29. package/dist/helpers/replaceVariables.d.ts.map +1 -1
  30. package/dist/helpers/replaceVariables.js +1 -3
  31. package/dist/helpers/ssrState.d.ts.map +1 -1
  32. package/dist/helpers/ssrState.js +1 -3
  33. package/dist/migrations/local-storage.d.ts.map +1 -1
  34. package/dist/migrations/semver.d.ts.map +1 -1
  35. package/dist/migrations/semver.js +1 -3
  36. package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -1
  37. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
  38. package/dist/migrations/v-2.1.0/migration.js +1 -4
  39. package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -1
  40. package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
  41. package/dist/migrations/v-2.2.0/migration.js +2 -4
  42. package/dist/migrations/v-2.2.0/types.generated.d.ts.map +1 -1
  43. package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
  44. package/dist/migrations/v-2.3.0/migration.js +3 -8
  45. package/dist/migrations/v-2.3.0/types.generated.d.ts.map +1 -1
  46. package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
  47. package/dist/migrations/v-2.4.0/types.generated.d.ts.map +1 -1
  48. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  49. package/dist/migrations/v-2.5.0/migration.js +4 -0
  50. package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
  51. package/dist/spec-getters/getExampleFromSchema.js +8 -22
  52. package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
  53. package/dist/spec-getters/getParametersFromOperation.js +1 -4
  54. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  55. package/dist/spec-getters/getRequestBodyFromOperation.js +4 -9
  56. package/dist/spec-getters/getServerVariableExamples.js +3 -1
  57. package/dist/transforms/import-spec.d.ts +1 -0
  58. package/dist/transforms/import-spec.d.ts.map +1 -1
  59. package/dist/transforms/import-spec.js +11 -3
  60. package/dist/transforms/index.d.ts +0 -1
  61. package/dist/transforms/index.d.ts.map +1 -1
  62. package/dist/transforms/index.js +0 -1
  63. package/package.json +7 -7
  64. package/dist/transforms/export-spec.d.ts +0 -17
  65. package/dist/transforms/export-spec.d.ts.map +0 -1
  66. package/dist/transforms/export-spec.js +0 -73
@@ -70,8 +70,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
70
70
  // But if `emptyString` is set, we do want to see some values.
71
71
  const makeUpRandomData = !!options?.emptyString;
72
72
  // Check if the property is read-only/write-only
73
- if ((options?.mode === 'write' && schema.readOnly) ||
74
- (options?.mode === 'read' && schema.writeOnly)) {
73
+ if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {
75
74
  return undefined;
76
75
  }
77
76
  // Use given variables as values
@@ -124,9 +123,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
124
123
  for (const propertyName in schema.properties) {
125
124
  if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
126
125
  const property = schema.properties[propertyName];
127
- const propertyXmlTagName = options?.xml
128
- ? property.xml?.name
129
- : undefined;
126
+ const propertyXmlTagName = options?.xml ? property.xml?.name : undefined;
130
127
  response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName);
131
128
  if (typeof response[propertyXmlTagName ?? propertyName] === 'undefined') {
132
129
  delete response[propertyXmlTagName ?? propertyName];
@@ -151,8 +148,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
151
148
  // true
152
149
  schema.additionalProperties === true ||
153
150
  // or an empty object {}
154
- (typeof schema.additionalProperties === 'object' &&
155
- !Object.keys(schema.additionalProperties).length);
151
+ (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length);
156
152
  if (anyTypeIsValid) {
157
153
  response['ANY_ADDITIONAL_PROPERTY'] = 'anything';
158
154
  }
@@ -187,18 +183,14 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
187
183
  // If the first item is an object type, merge all schemas
188
184
  if (schema.items.allOf[0].type === 'object') {
189
185
  const mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema);
190
- return cache(schema, wrapItems
191
- ? [{ [itemsXmlTagName]: mergedExample }]
192
- : [mergedExample]);
186
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
193
187
  }
194
188
  else {
195
189
  // For non-objects (like strings), collect all examples
196
190
  const examples = schema.items.allOf
197
191
  .map((item) => getExampleFromSchema(item, options, level + 1, schema))
198
192
  .filter((item) => item !== undefined);
199
- return cache(schema, wrapItems
200
- ? examples.map((example) => ({ [itemsXmlTagName]: example }))
201
- : examples);
193
+ return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
202
194
  }
203
195
  }
204
196
  // Handle other rules (anyOf, oneOf)
@@ -211,23 +203,17 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
211
203
  const exampleFromRule = schemas
212
204
  .map((item) => getExampleFromSchema(item, options, level + 1, schema))
213
205
  .filter((item) => item !== undefined);
214
- return cache(schema, wrapItems
215
- ? [{ [itemsXmlTagName]: exampleFromRule }]
216
- : exampleFromRule);
206
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
217
207
  }
218
208
  }
219
209
  if (schema.items?.type) {
220
210
  const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
221
- return wrapItems
222
- ? [{ [itemsXmlTagName]: exampleFromSchema }]
223
- : [exampleFromSchema];
211
+ return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
224
212
  }
225
213
  return [];
226
214
  }
227
215
  const exampleValues = {
228
- string: makeUpRandomData
229
- ? guessFromFormat(schema, options?.emptyString)
230
- : '',
216
+ string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',
231
217
  boolean: true,
232
218
  integer: schema.min ?? 1,
233
219
  number: schema.min ?? 1,
@@ -1 +1 @@
1
- {"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,CAkCjB"}
1
+ {"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,CA6BjB"}
@@ -9,10 +9,7 @@ import { getExampleFromSchema } from './getExampleFromSchema.js';
9
9
  * - Swagger 2.0: Possible values are "query", "header", "path", "formData" or "body".
10
10
  */
11
11
  function getParametersFromOperation(operation, where, requiredOnly = true) {
12
- const parameters = [
13
- ...(operation.pathParameters || []),
14
- ...(operation.information?.parameters || []),
15
- ];
12
+ const parameters = [...(operation.pathParameters || []), ...(operation.information?.parameters || [])];
16
13
  const params = parameters
17
14
  // query, path, header, cookie?
18
15
  .filter((parameter) => parameter.in === where)
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestBodyFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestBodyFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAgC7E,QAAA,MAAM,SAAS,wJAOL,CAAA;AAEV;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,EAAE,CAAA;CACJ,GAAG,IAAI,CAkLP"}
1
+ {"version":3,"file":"getRequestBodyFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestBodyFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAgC7E,QAAA,MAAM,SAAS,wJAOL,CAAA;AAEV;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,EAAE,CAAA;CACJ,GAAG,IAAI,CAgKP"}
@@ -93,9 +93,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
93
93
  *
94
94
  * JSON.stringify is a TEMPORARY fix
95
95
  */
96
- value: typeof parameter.value === 'string'
97
- ? parameter.value
98
- : JSON.stringify(parameter.value),
96
+ value: typeof parameter.value === 'string' ? parameter.value : JSON.stringify(parameter.value),
99
97
  })),
100
98
  };
101
99
  }
@@ -106,9 +104,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
106
104
  // Get the request body object for the mime type
107
105
  const requestBodyObject = content?.[mimeType];
108
106
  // Get example from operation
109
- const example = requestBodyObject?.example
110
- ? requestBodyObject?.example
111
- : undefined;
107
+ const example = requestBodyObject?.example ? requestBodyObject?.example : undefined;
112
108
  // JSON
113
109
  if (mimeType === 'application/json') {
114
110
  const exampleFromSchema = requestBodyObject?.schema
@@ -120,7 +116,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
120
116
  const body = example ?? exampleFromSchema;
121
117
  return {
122
118
  mimeType,
123
- text: typeof body === 'string' ? body : JSON.stringify(body, null, 2),
119
+ text: body ? (typeof body === 'string' ? body : JSON.stringify(body, null, 2)) : undefined,
124
120
  };
125
121
  }
126
122
  // XML
@@ -157,8 +153,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
157
153
  };
158
154
  }
159
155
  // URL encoded data
160
- if (mimeType === 'multipart/form-data' ||
161
- mimeType === 'application/x-www-form-urlencoded') {
156
+ if (mimeType === 'multipart/form-data' || mimeType === 'application/x-www-form-urlencoded') {
162
157
  const exampleFromSchema = requestBodyObject?.schema
163
158
  ? getExampleFromSchema(requestBodyObject?.schema, {
164
159
  xml: true,
@@ -3,7 +3,9 @@ const getServerVariableExamples = (server) => {
3
3
  const examples = {};
4
4
  if (server.variables) {
5
5
  for (const [key, variable] of Object.entries(server.variables)) {
6
- examples[key] = variable.enum?.filter((v) => typeof v === 'string') ?? [variable.default];
6
+ examples[key] = variable.enum?.filter((v) => typeof v === 'string') ?? [
7
+ variable.default,
8
+ ];
7
9
  }
8
10
  }
9
11
  return examples;
@@ -48,6 +48,7 @@ export declare function importSpecToWorkspace(spec: string | UnknownObject, { au
48
48
  } | {
49
49
  error: true;
50
50
  importWarnings: string[];
51
+ collection: undefined;
51
52
  }>;
52
53
  /**
53
54
  * Retrieves a list of servers from an OpenAPI document and converts them to a list of Server entities.
@@ -1 +1 @@
1
- {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAMjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAgB,MAAM,GAAG,aAAa;;;IAkC1D;;;OAGG;YAC8C,WAAW,CAAC,QAAQ;;EAGxE,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,6BAA6B,yBAClB,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,0BACnB,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,iCAC1B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,KACvD,0BAWF,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,WAAW,CAAC,GAC1F,IAAI,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,eAAe,GAAG,SAAS,CAAC,GAAG;IAC7E,mFAAmF;IACnF,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,yCAAyC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,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C;IAAC,UAAU,EAAE,SAAS,CAAA;CAAE,CACnE,CA8TA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAM,GACpE,MAAM,EAAE,CAwCV"}
@@ -75,7 +75,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
75
75
  const { schema, errors } = await parseSchema(spec, { shouldLoad });
76
76
  const importWarnings = [...errors.map((e) => e.message)];
77
77
  if (!schema)
78
- return { importWarnings, error: true };
78
+ return { importWarnings, error: true, collection: undefined };
79
79
  // ---------------------------------------------------------------------------
80
80
  // Some entities will be broken out as individual lists for modification in the workspace
81
81
  const start = performance.now();
@@ -147,8 +147,16 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
147
147
  payload.username = authentication.http.basic.username ?? '';
148
148
  payload.password = authentication.http.basic.password ?? '';
149
149
  }
150
- else if (payload.scheme === 'bearer' && authentication.http?.bearer)
151
- payload.token = authentication.http.bearer.token ?? '';
150
+ // Bearer
151
+ else if (payload.scheme === 'bearer') {
152
+ if (authentication.http?.bearer?.token) {
153
+ payload.token = authentication.http.bearer.token ?? '';
154
+ }
155
+ // Temp multiple bearer
156
+ if (authentication.http?.bearer?.multiple?.[nameKey]) {
157
+ payload.token = authentication.http.bearer.multiple[nameKey];
158
+ }
159
+ }
152
160
  }
153
161
  }
154
162
  const scheme = schemaModel(payload, securitySchemeSchema, false);
@@ -1,3 +1,2 @@
1
1
  export * from './import-spec.js';
2
- export * from './export-spec.js';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -1,2 +1 @@
1
1
  export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
2
- export { exportSpecFromWorkspace } from './export-spec.js';
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.107",
19
+ "version": "0.2.109",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -126,19 +126,19 @@
126
126
  "nanoid": "^5.0.9",
127
127
  "yaml": "^2.4.5",
128
128
  "zod": "^3.23.8",
129
+ "@scalar/openapi-types": "0.1.9",
129
130
  "@scalar/object-utils": "1.1.13",
130
- "@scalar/openapi-types": "0.1.8",
131
- "@scalar/themes": "0.9.68",
132
- "@scalar/types": "0.0.34"
131
+ "@scalar/themes": "0.9.70",
132
+ "@scalar/types": "0.0.36"
133
133
  },
134
134
  "devDependencies": {
135
135
  "type-fest": "^4.20.0",
136
136
  "vite": "^5.4.10",
137
137
  "vitest": "^1.6.0",
138
138
  "zod-to-ts": "github:amritk/zod-to-ts#build",
139
- "@scalar/openapi-parser": "0.10.8",
140
- "@scalar/openapi-types": "0.1.8",
141
- "@scalar/build-tooling": "0.1.14"
139
+ "@scalar/build-tooling": "0.1.15",
140
+ "@scalar/openapi-types": "0.1.9",
141
+ "@scalar/openapi-parser": "0.10.9"
142
142
  },
143
143
  "scripts": {
144
144
  "build": "scalar-build-rollup",
@@ -1,17 +0,0 @@
1
- import { type Collection, type Request, type RequestExample, type SecurityScheme, type Tag } from '../entities/spec/index.js';
2
- import type { OpenAPIV3_1 } from '@scalar/types';
3
- type WithRequired<T, K extends keyof T> = T & {
4
- [P in K]-?: T[P];
5
- };
6
- /**
7
- * Convert a workspace collection into an OpenAPI document
8
- */
9
- export declare function exportSpecFromWorkspace({ collection, requests, requestExamples, tags, securitySchemes, }: {
10
- collection: Collection;
11
- requests: Record<string, Request>;
12
- requestExamples: Record<string, RequestExample>;
13
- tags: Record<string, Tag>;
14
- securitySchemes: Record<string, SecurityScheme>;
15
- }): WithRequired<OpenAPIV3_1.Document<{}>, "paths" | "components" | "tags">;
16
- export {};
17
- //# sourceMappingURL=export-spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"export-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/export-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAElE;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,eAAe,GAChB,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAC/C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CAChD,2EAyEA"}
@@ -1,73 +0,0 @@
1
- import { oasCollectionSchema } from '../entities/spec/collection.js';
2
- import { oasTagSchema } from '../entities/spec/spec-objects.js';
3
- import { oasRequestSchema } from '../entities/spec/requests.js';
4
- import { convertExampleToXScalar } from '../entities/spec/request-examples.js';
5
- import { oasSecuritySchemeSchema } from '../entities/spec/security.js';
6
-
7
- /**
8
- * Convert a workspace collection into an OpenAPI document
9
- */
10
- function exportSpecFromWorkspace({ collection, requests, requestExamples, tags, securitySchemes, }) {
11
- const parsedCollection = oasCollectionSchema.parse(collection);
12
- const spec = {
13
- ...parsedCollection,
14
- openapi: parsedCollection.openapi,
15
- tags: [],
16
- paths: {},
17
- webhooks: {},
18
- components: {
19
- securitySchemes: {},
20
- },
21
- };
22
- /** Add all of the tags into the collection */
23
- Object.values(tags).forEach((tag) => {
24
- const oasTag = oasTagSchema.parse(tag);
25
- if (!oasTag['x-scalar-children']?.length)
26
- delete oasTag['x-scalar-children'];
27
- spec.tags.push(oasTag);
28
- });
29
- /** Add all of the requests into the collection as operations */
30
- Object.values(requests).forEach((request) => {
31
- const oasRequest = oasRequestSchema.parse(request);
32
- // Currently the request has tags added by name. Should this move to UID association?
33
- oasRequest.tags = request.tags;
34
- // If the request has examples we add them all as extensions
35
- const exampleNames = new Set();
36
- /** Increment non-unique names */
37
- function checkName(name) {
38
- if (exampleNames.has(name)) {
39
- const base = name.split(' ');
40
- const end = Number.parseInt(base.at(-1) ?? 'NaN', 10);
41
- if (Number.isNaN(end)) {
42
- base.push('1');
43
- }
44
- else {
45
- base[base.length - 1] = `${end + 1}`;
46
- }
47
- return checkName(base.join(' '));
48
- }
49
- exampleNames.add(name);
50
- return name;
51
- }
52
- if (request.examples.length) {
53
- oasRequest['x-scalar-examples'] = {};
54
- request.examples.forEach((uid) => {
55
- const requestExample = requestExamples[uid];
56
- oasRequest['x-scalar-examples'][checkName(requestExample.name)] =
57
- convertExampleToXScalar(requestExample);
58
- });
59
- }
60
- /** Insert the request as an operation in the spec */
61
- if (!spec.paths[request.path])
62
- spec.paths[request.path] = {};
63
- spec.paths[request.path][request.method] = oasRequest;
64
- });
65
- /** Add all of the security schemes into the collection */
66
- Object.values(securitySchemes).forEach((securityScheme) => {
67
- const oasScheme = oasSecuritySchemeSchema.parse(securityScheme);
68
- spec.components.securitySchemes[securityScheme.nameKey] = oasScheme;
69
- });
70
- return spec;
71
- }
72
-
73
- export { exportSpecFromWorkspace };