@chargebee/code-sample-generator 0.3.5 → 0.4.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.
- package/dist/browser.js +11 -11
- package/dist/code-sample-generator.css +42 -23
- package/dist/components/Carousel.d.ts.map +1 -1
- package/dist/core/expander.d.ts.map +1 -1
- package/dist/core/ir-builder.d.ts.map +1 -1
- package/dist/core/minimal-types.d.ts +2 -0
- package/dist/core/minimal-types.d.ts.map +1 -1
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/{generate-from-sample-rMSyyork.js → generate-from-sample-DhbfCFUp.js} +1404 -659
- package/dist/{generate-from-sample-rMSyyork.js.map → generate-from-sample-DhbfCFUp.js.map} +1 -1
- package/dist/generated/ops/v2-pcv1/create_a_usage_event.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/create_an_offer_event.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/create_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/get_uploaded_file_processing_status.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/get_usages_file_upload_url.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/ingest_usages_in_batch.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/list_personalized_offers.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/retrieve_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv1/update_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/create_a_usage_event.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/create_an_offer_event.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/create_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/get_uploaded_file_processing_status.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/get_usages_file_upload_url.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/ingest_usages_in_batch.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/list_personalized_offers.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/retrieve_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generated/ops/v2-pcv2/update_an_offer_fulfillment.d.ts.map +1 -1
- package/dist/generators/dotnet.d.ts.map +1 -1
- package/dist/generators/go.d.ts.map +1 -1
- package/dist/generators/java/utils.d.ts.map +1 -1
- package/dist/generators/java/v3.d.ts.map +1 -1
- package/dist/generators/java/v4.d.ts.map +1 -1
- package/dist/generators/nodejs.d.ts.map +1 -1
- package/dist/generators/php.d.ts.map +1 -1
- package/dist/generators/ruby.d.ts.map +1 -1
- package/dist/generators/utils.d.ts +5 -0
- package/dist/generators/utils.d.ts.map +1 -1
- package/dist/index.js +155 -322
- package/dist/index.js.map +1 -1
- package/dist/samples/repo.d.ts.map +1 -1
- package/dist/templates/utils.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/generate-code-sample.d.ts +9 -0
- package/dist/utils/generate-code-sample.d.ts.map +1 -1
- package/dist/utils/generate-from-sample.d.ts.map +1 -1
- package/package.json +14 -15
package/dist/index.js
CHANGED
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
import { g as generateFromSample, a as getGenerator, L as LanguageNotSupportedError, b as getSupportedLanguages, c as getOperation, O as OperationNotFoundError, e as expandDescriptor, d as buildIR, C as CodeGenerationError, p as pluralize } from "./generate-from-sample-
|
|
2
|
-
import {
|
|
3
|
-
import { OpenAPIExtensions } from "@cb-docs-platform/openapi-utils";
|
|
4
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { g as generateFromSample, a as getGenerator, L as LanguageNotSupportedError, b as getSupportedLanguages, c as getOperation, O as OperationNotFoundError, e as expandDescriptor, d as assertValid, f as buildIR, C as CodeGenerationError, p as pluralize } from "./generate-from-sample-DhbfCFUp.js";
|
|
2
|
+
import { n, A, i, j, k, h, D, o, G, q, l, T, V, w, x, r, t, s, v, y, u, m, z } from "./generate-from-sample-DhbfCFUp.js";
|
|
5
3
|
import { join } from "node:path";
|
|
4
|
+
import "node:url";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
6
|
+
const OpenAPIExtensions = Object.freeze({
|
|
7
|
+
// Resource Extensions
|
|
8
|
+
RESOURCE_ID: "x-cb-resource-id",
|
|
9
|
+
RESOURCE_NAME: "x-cb-resource-title",
|
|
10
|
+
IS_THIRD_PARTY_RESOURCE: "x-cb-is-third-party-resource",
|
|
11
|
+
HIDDEN_FROM_CLIENT_SDK: "x-cb-hidden-from-client-sdk",
|
|
12
|
+
// Operation Extensions
|
|
13
|
+
OPERATION_METHOD_NAME: "x-cb-operation-method-name",
|
|
14
|
+
METHOD_SYNTAX: "x-cb-method-syntax",
|
|
15
|
+
// SDK method call example
|
|
16
|
+
SDK_METHOD_NAME: "x-cb-sdk-method-name",
|
|
17
|
+
// SDK-specific method name (e.g., "retrieveStoreSubscriptions" for Java v4)
|
|
18
|
+
IS_LIST_OPERATION: "x-cb-operation-is-list",
|
|
19
|
+
IS_JSON_INPUT: "x-cb-is-operation-needs-json-input",
|
|
20
|
+
SUB_DOMAIN_NAME: "x-cb-operation-sub-domain-name",
|
|
21
|
+
IS_RESTRICTED: "x-cb-restricted",
|
|
22
|
+
MODULE: "x-cb-module",
|
|
23
|
+
API_CRITICALITY: "x-cb-api-criticality",
|
|
24
|
+
IS_IDEMPOTENT: "x-cb-operation-is-idempotent",
|
|
25
|
+
IS_OPERATION_NEEDS_INPUT_OBJECT: "x-cb-is-operation-needs-input-object",
|
|
26
|
+
IS_BATCH: "x-cb-operation-is-batch",
|
|
27
|
+
IS_COMPOSITE_ARRAY_REQUEST_BODY: "x-cb-is-composite-array-request-body",
|
|
28
|
+
// Parameter Extensions
|
|
29
|
+
IS_FILTER_PARAMETER: "x-cb-is-filter-parameter",
|
|
30
|
+
SDK_FILTER_NAME: "x-cb-sdk-filter-name",
|
|
31
|
+
IS_GLOBAL_ENUM: "x-cb-is-global-enum",
|
|
32
|
+
GLOBAL_ENUM_REFERENCE: "x-cb-global-enum-reference",
|
|
33
|
+
IS_EXTERNAL_ENUM: "x-cb-is-external-enum",
|
|
34
|
+
IS_SDK_GEN_SEPARATE: "x-cb-is-sdk-gen-separate",
|
|
35
|
+
IS_GEN_SEPARATE: "x-cb-is-gen-separate",
|
|
36
|
+
SDK_ENUM_API_NAME: "x-cb-sdk-enum-api-name",
|
|
37
|
+
IS_MONEY_COLUMN: "x-cb-is-money-column",
|
|
38
|
+
IS_LONG_MONEY_COLUMN: "x-cb-is-long-money-column",
|
|
39
|
+
IS_SUB_RESOURCE: "x-cb-is-sub-resource",
|
|
40
|
+
META_MODEL_NAME: "x-cb-meta-model-name"
|
|
41
|
+
// Additional extensions as needed
|
|
42
|
+
});
|
|
6
43
|
function addCopyButton(options = {}) {
|
|
7
44
|
const { toggleDelay = 2e3 } = options;
|
|
8
45
|
return {
|
|
@@ -32,240 +69,6 @@ const LANGUAGES = [
|
|
|
32
69
|
"go",
|
|
33
70
|
"dotnet"
|
|
34
71
|
];
|
|
35
|
-
class ValidationError extends Error {
|
|
36
|
-
constructor(operation, issues) {
|
|
37
|
-
const summary = issues.map((i2) => `${i2.path}: ${i2.message}`).join("; ");
|
|
38
|
-
super(`Validation failed for ${operation}: ${summary}`);
|
|
39
|
-
this.operation = operation;
|
|
40
|
-
this.issues = issues;
|
|
41
|
-
if (Error.captureStackTrace) {
|
|
42
|
-
Error.captureStackTrace(this, ValidationError);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
name = "ValidationError";
|
|
46
|
-
}
|
|
47
|
-
function validateParams(schema, params, options = {}) {
|
|
48
|
-
const opts = {
|
|
49
|
-
allowUnknown: options.allowUnknown ?? true,
|
|
50
|
-
// LENIENT by default
|
|
51
|
-
validateEnums: options.validateEnums ?? true,
|
|
52
|
-
validateTypes: options.validateTypes ?? true,
|
|
53
|
-
validateRequired: options.validateRequired ?? true
|
|
54
|
-
};
|
|
55
|
-
const issues = [];
|
|
56
|
-
validateObject(schema, params, "", issues, opts);
|
|
57
|
-
return issues;
|
|
58
|
-
}
|
|
59
|
-
function validateObject(schema, obj, basePath, issues, opts) {
|
|
60
|
-
if (opts.validateRequired) {
|
|
61
|
-
for (const requiredField of schema.required ?? []) {
|
|
62
|
-
const value = obj[requiredField];
|
|
63
|
-
if (value === void 0 || value === null) {
|
|
64
|
-
const path = joinPath(basePath, requiredField);
|
|
65
|
-
issues.push({
|
|
66
|
-
path,
|
|
67
|
-
message: `Required field "${requiredField}" is missing`,
|
|
68
|
-
code: "required"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
74
|
-
if (value === void 0) continue;
|
|
75
|
-
const fieldPath = joinPath(basePath, key);
|
|
76
|
-
const propSchema = schema.properties?.[key];
|
|
77
|
-
if (!propSchema) {
|
|
78
|
-
if (!opts.allowUnknown) {
|
|
79
|
-
issues.push({
|
|
80
|
-
path: fieldPath,
|
|
81
|
-
message: `Unknown field "${key}"`,
|
|
82
|
-
code: "unknown_field"
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (value === null) continue;
|
|
88
|
-
if (opts.validateTypes) {
|
|
89
|
-
const typeIssue = validateType(fieldPath, value, propSchema);
|
|
90
|
-
if (typeIssue) {
|
|
91
|
-
issues.push(typeIssue);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (opts.validateEnums && propSchema.enum) {
|
|
96
|
-
const stringValue = String(value);
|
|
97
|
-
if (!propSchema.enum.includes(stringValue)) {
|
|
98
|
-
issues.push({
|
|
99
|
-
path: fieldPath,
|
|
100
|
-
message: `Invalid value "${stringValue}". Valid values: ${propSchema.enum.join(", ")}`,
|
|
101
|
-
code: "enum"
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (propSchema.type === "object" && propSchema.properties && typeof value === "object" && !Array.isArray(value)) {
|
|
106
|
-
validateObject(
|
|
107
|
-
propSchema,
|
|
108
|
-
value,
|
|
109
|
-
fieldPath,
|
|
110
|
-
issues,
|
|
111
|
-
opts
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
if (propSchema.type === "array" && Array.isArray(value)) {
|
|
115
|
-
validateArray(propSchema, value, fieldPath, issues, opts);
|
|
116
|
-
}
|
|
117
|
-
if (propSchema.isFilter && typeof value === "object" && !Array.isArray(value)) {
|
|
118
|
-
validateFilterParam(
|
|
119
|
-
propSchema,
|
|
120
|
-
value,
|
|
121
|
-
fieldPath,
|
|
122
|
-
issues,
|
|
123
|
-
opts
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function validateArray(schema, arr, basePath, issues, opts) {
|
|
129
|
-
const itemSchema = schema.items;
|
|
130
|
-
if (!itemSchema) return;
|
|
131
|
-
arr.forEach((item, index) => {
|
|
132
|
-
const itemPath = `${basePath}[${index}]`;
|
|
133
|
-
if (item === null || item === void 0) return;
|
|
134
|
-
if (opts.validateTypes) {
|
|
135
|
-
const typeIssue = validateType(itemPath, item, itemSchema);
|
|
136
|
-
if (typeIssue) {
|
|
137
|
-
issues.push(typeIssue);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (itemSchema.type === "object" && itemSchema.properties && typeof item === "object" && !Array.isArray(item)) {
|
|
142
|
-
validateObject(
|
|
143
|
-
itemSchema,
|
|
144
|
-
item,
|
|
145
|
-
itemPath,
|
|
146
|
-
issues,
|
|
147
|
-
opts
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
function validateFilterParam(schema, filterValue, basePath, issues, opts) {
|
|
153
|
-
const validOperators = /* @__PURE__ */ new Set([
|
|
154
|
-
"is",
|
|
155
|
-
"is_not",
|
|
156
|
-
"in",
|
|
157
|
-
"not_in",
|
|
158
|
-
"gt",
|
|
159
|
-
"gte",
|
|
160
|
-
"lt",
|
|
161
|
-
"lte",
|
|
162
|
-
"between",
|
|
163
|
-
"on",
|
|
164
|
-
"before",
|
|
165
|
-
"after",
|
|
166
|
-
"starts_with",
|
|
167
|
-
"is_present",
|
|
168
|
-
"is_not_present"
|
|
169
|
-
]);
|
|
170
|
-
for (const [operator, value] of Object.entries(filterValue)) {
|
|
171
|
-
if (!validOperators.has(operator) && !opts.allowUnknown) {
|
|
172
|
-
issues.push({
|
|
173
|
-
path: `${basePath}[${operator}]`,
|
|
174
|
-
message: `Unknown filter operator "${operator}"`,
|
|
175
|
-
code: "unknown_field"
|
|
176
|
-
});
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (opts.validateEnums && schema.enum && schema.filterType === "enum") {
|
|
180
|
-
const values = Array.isArray(value) ? value : [value];
|
|
181
|
-
for (const v2 of values) {
|
|
182
|
-
if (!schema.enum.includes(String(v2))) {
|
|
183
|
-
issues.push({
|
|
184
|
-
path: `${basePath}[${operator}]`,
|
|
185
|
-
message: `Invalid enum value "${v2}". Valid values: ${schema.enum.join(", ")}`,
|
|
186
|
-
code: "enum"
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function validateType(path, value, schema) {
|
|
194
|
-
const actualType = getValueType(value);
|
|
195
|
-
switch (schema.type) {
|
|
196
|
-
case "string":
|
|
197
|
-
if (actualType !== "string") {
|
|
198
|
-
return {
|
|
199
|
-
path,
|
|
200
|
-
message: `Expected string, got ${actualType}`,
|
|
201
|
-
code: "type"
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
case "integer":
|
|
206
|
-
case "number":
|
|
207
|
-
if (actualType !== "number") {
|
|
208
|
-
return {
|
|
209
|
-
path,
|
|
210
|
-
message: `Expected number, got ${actualType}`,
|
|
211
|
-
code: "type"
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
if (schema.type === "integer" && !Number.isInteger(value)) {
|
|
215
|
-
return {
|
|
216
|
-
path,
|
|
217
|
-
message: `Expected integer, got decimal number`,
|
|
218
|
-
code: "type"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
case "boolean":
|
|
223
|
-
if (actualType !== "boolean") {
|
|
224
|
-
return {
|
|
225
|
-
path,
|
|
226
|
-
message: `Expected boolean, got ${actualType}`,
|
|
227
|
-
code: "type"
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
break;
|
|
231
|
-
case "array":
|
|
232
|
-
if (actualType !== "array") {
|
|
233
|
-
return {
|
|
234
|
-
path,
|
|
235
|
-
message: `Expected array, got ${actualType}`,
|
|
236
|
-
code: "type"
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
break;
|
|
240
|
-
case "object":
|
|
241
|
-
if (actualType !== "object") {
|
|
242
|
-
return {
|
|
243
|
-
path,
|
|
244
|
-
message: `Expected object, got ${actualType}`,
|
|
245
|
-
code: "type"
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
function getValueType(value) {
|
|
253
|
-
if (value === null) return "null";
|
|
254
|
-
if (Array.isArray(value)) return "array";
|
|
255
|
-
return typeof value;
|
|
256
|
-
}
|
|
257
|
-
function joinPath(base, field) {
|
|
258
|
-
return base ? `${base}.${field}` : field;
|
|
259
|
-
}
|
|
260
|
-
function assertValid(operationId, schema, params, options) {
|
|
261
|
-
const issues = validateParams(schema, params, options);
|
|
262
|
-
if (issues.length > 0) {
|
|
263
|
-
throw new ValidationError(operationId, issues);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function isValid(schema, params, options) {
|
|
267
|
-
return validateParams(schema, params, options).length === 0;
|
|
268
|
-
}
|
|
269
72
|
function toPascalCase(str) {
|
|
270
73
|
return str.split(/[-_]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
271
74
|
}
|
|
@@ -483,6 +286,16 @@ async function generateCodeSample(options) {
|
|
|
483
286
|
params = reqParams.map ? reqParams.map : reqParams;
|
|
484
287
|
note = sampleRequest.note;
|
|
485
288
|
}
|
|
289
|
+
const shouldValidate = options.validate ?? true;
|
|
290
|
+
if (shouldValidate) {
|
|
291
|
+
const validationOpts = typeof shouldValidate === "object" ? shouldValidate : { allowUnknown: false };
|
|
292
|
+
const bodyParams = stripPathParams(
|
|
293
|
+
params,
|
|
294
|
+
descriptor.http.path,
|
|
295
|
+
descriptor.params
|
|
296
|
+
);
|
|
297
|
+
assertValid(operation, descriptor.params, bodyParams, validationOpts);
|
|
298
|
+
}
|
|
486
299
|
const ir = buildIR(descriptor, params, {
|
|
487
300
|
site: site || "{site}",
|
|
488
301
|
apiKey: apiKey || "{site_api_key}",
|
|
@@ -540,6 +353,27 @@ function getCombinedVersion(apiVersion, pcVersion) {
|
|
|
540
353
|
}
|
|
541
354
|
return "v2-pcv2";
|
|
542
355
|
}
|
|
356
|
+
function stripPathParams(params, pathTemplate, bodySchema) {
|
|
357
|
+
const pathParamKeys = /* @__PURE__ */ new Set();
|
|
358
|
+
const placeholderRegex = /\{([^}]+)\}/g;
|
|
359
|
+
let match = placeholderRegex.exec(pathTemplate);
|
|
360
|
+
while (match !== null) {
|
|
361
|
+
const name = match[1];
|
|
362
|
+
pathParamKeys.add(name);
|
|
363
|
+
pathParamKeys.add(name.replace(/-/g, "_"));
|
|
364
|
+
if (name.endsWith("-id") || name.endsWith("_id")) {
|
|
365
|
+
pathParamKeys.add("id");
|
|
366
|
+
}
|
|
367
|
+
match = placeholderRegex.exec(pathTemplate);
|
|
368
|
+
}
|
|
369
|
+
const result = {};
|
|
370
|
+
for (const [key, value] of Object.entries(params)) {
|
|
371
|
+
if (bodySchema.properties?.[key] !== void 0 || !pathParamKeys.has(key)) {
|
|
372
|
+
result[key] = value;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
543
377
|
const SAMPLES_BASE_DIR = "samples/cb-app";
|
|
544
378
|
const REQUEST_SUBDIR = "request";
|
|
545
379
|
const RESPONSE_SUBDIR = "response";
|
|
@@ -789,78 +623,77 @@ function fetchAllRequestSamples(resource, operation, apiVersion, pcVersion) {
|
|
|
789
623
|
normalizedOpId
|
|
790
624
|
);
|
|
791
625
|
}
|
|
792
|
-
if (!existsSync(operationDir)) {
|
|
793
|
-
return [];
|
|
794
|
-
}
|
|
795
|
-
const requestDir = join(operationDir, REQUEST_SUBDIR);
|
|
796
626
|
const samples = [];
|
|
797
|
-
if (existsSync(
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
627
|
+
if (existsSync(operationDir)) {
|
|
628
|
+
const requestDir = join(operationDir, REQUEST_SUBDIR);
|
|
629
|
+
if (existsSync(requestDir)) {
|
|
630
|
+
const files = readdirSync(requestDir).filter(
|
|
631
|
+
(file) => file.endsWith(JSON_EXTENSION)
|
|
632
|
+
);
|
|
633
|
+
for (const filename of files) {
|
|
634
|
+
try {
|
|
635
|
+
const filePath = join(requestDir, filename);
|
|
636
|
+
const content = readFileSync(filePath, "utf-8");
|
|
637
|
+
const data = JSON.parse(content);
|
|
638
|
+
const name = filename.replace(JSON_EXTENSION, "").replace(/_/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
639
|
+
const sampleData = Array.isArray(data) ? data[0] : data;
|
|
640
|
+
samples.push({
|
|
641
|
+
filename,
|
|
642
|
+
name,
|
|
643
|
+
sample: sampleData
|
|
644
|
+
});
|
|
645
|
+
} catch (error) {
|
|
646
|
+
console.warn(`Failed to load ${filename}:`, error);
|
|
647
|
+
}
|
|
815
648
|
}
|
|
816
649
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
uri = `/${request.url.path.join("/")}`;
|
|
835
|
-
}
|
|
836
|
-
const params = {};
|
|
837
|
-
if (request.body?.mode === "urlencoded" && request.body.urlencoded) {
|
|
838
|
-
for (const param of request.body.urlencoded) {
|
|
839
|
-
params[param.key] = param.value;
|
|
650
|
+
if (existsSync(operationDir)) {
|
|
651
|
+
const collectionFiles = readdirSync(operationDir).filter(
|
|
652
|
+
(file) => file.endsWith(POSTMAN_COLLECTION_EXTENSION)
|
|
653
|
+
);
|
|
654
|
+
for (const collectionFile of collectionFiles) {
|
|
655
|
+
try {
|
|
656
|
+
const collectionPath = join(operationDir, collectionFile);
|
|
657
|
+
const content = readFileSync(collectionPath, "utf-8");
|
|
658
|
+
const collection = JSON.parse(content);
|
|
659
|
+
if (collection.item && collection.item.length > 0) {
|
|
660
|
+
const item = collection.item[0];
|
|
661
|
+
const request = item.request;
|
|
662
|
+
let uri = "";
|
|
663
|
+
if (typeof request.url === "string") {
|
|
664
|
+
uri = request.url;
|
|
665
|
+
} else if (request.url?.path) {
|
|
666
|
+
uri = `/${request.url.path.join("/")}`;
|
|
840
667
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const cleanName = collectionFile.replace(POSTMAN_COLLECTION_EXTENSION, "").split("-")[0].replace(/_/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
847
|
-
samples.push({
|
|
848
|
-
filename: collectionFile,
|
|
849
|
-
name: cleanName,
|
|
850
|
-
sample: {
|
|
851
|
-
uri,
|
|
852
|
-
method: request.method || "POST",
|
|
853
|
-
params,
|
|
854
|
-
desc: description,
|
|
855
|
-
description: cleanName
|
|
668
|
+
const params = {};
|
|
669
|
+
if (request.body?.mode === "urlencoded" && request.body.urlencoded) {
|
|
670
|
+
for (const param of request.body.urlencoded) {
|
|
671
|
+
params[param.key] = param.value;
|
|
672
|
+
}
|
|
856
673
|
}
|
|
857
|
-
|
|
674
|
+
let description = item.name;
|
|
675
|
+
if (item.response && item.response.length > 0 && item.response[0].originalRequest?.description?.content) {
|
|
676
|
+
description = item.response[0].originalRequest.description.content;
|
|
677
|
+
}
|
|
678
|
+
const cleanName = collectionFile.replace(POSTMAN_COLLECTION_EXTENSION, "").split("-")[0].replace(/_/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
679
|
+
samples.push({
|
|
680
|
+
filename: collectionFile,
|
|
681
|
+
name: cleanName,
|
|
682
|
+
sample: {
|
|
683
|
+
uri,
|
|
684
|
+
method: request.method || "POST",
|
|
685
|
+
params,
|
|
686
|
+
desc: description,
|
|
687
|
+
description: cleanName
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
} catch (error) {
|
|
692
|
+
console.warn(
|
|
693
|
+
`Failed to load Postman collection ${collectionFile}:`,
|
|
694
|
+
error
|
|
695
|
+
);
|
|
858
696
|
}
|
|
859
|
-
} catch (error) {
|
|
860
|
-
console.warn(
|
|
861
|
-
`Failed to load Postman collection ${collectionFile}:`,
|
|
862
|
-
error
|
|
863
|
-
);
|
|
864
697
|
}
|
|
865
698
|
}
|
|
866
699
|
}
|
|
@@ -912,28 +745,28 @@ function fetchAllRequestSamples(resource, operation, apiVersion, pcVersion) {
|
|
|
912
745
|
}
|
|
913
746
|
}
|
|
914
747
|
export {
|
|
915
|
-
|
|
748
|
+
n as AVAILABLE_LANGUAGES,
|
|
916
749
|
A as AVAILABLE_LANGUAGE_IDS,
|
|
917
|
-
|
|
918
|
-
|
|
750
|
+
i as Carousel,
|
|
751
|
+
j as CodeBlock,
|
|
919
752
|
CodeGenerationError,
|
|
920
|
-
|
|
921
|
-
|
|
753
|
+
k as CodeSampleHeader,
|
|
754
|
+
h as CodeSamples,
|
|
922
755
|
D as DEFAULT_LANGUAGE,
|
|
923
|
-
|
|
756
|
+
o as DEFAULT_THEME,
|
|
924
757
|
G as GoToApiExplorer,
|
|
925
758
|
LANGUAGES,
|
|
926
|
-
|
|
759
|
+
q as LANGUAGE_DISPLAY_NAMES,
|
|
927
760
|
LanguageNotSupportedError,
|
|
928
|
-
|
|
761
|
+
l as LanguageSwitcher,
|
|
929
762
|
OpenAPIExtensions,
|
|
930
763
|
OperationNotFoundError,
|
|
931
764
|
T as TryInApiExplorer,
|
|
932
|
-
ValidationError,
|
|
765
|
+
V as ValidationError,
|
|
933
766
|
addCopyButton,
|
|
934
767
|
assertValid,
|
|
935
768
|
buildIR,
|
|
936
|
-
|
|
769
|
+
w as compressDescriptor,
|
|
937
770
|
enrichDescriptorWithOpenAPI,
|
|
938
771
|
enrichDescriptorsWithOpenAPI,
|
|
939
772
|
expandDescriptor,
|
|
@@ -941,7 +774,7 @@ export {
|
|
|
941
774
|
extractReturnsFromOpenAPI,
|
|
942
775
|
fetchAllRequestSamples,
|
|
943
776
|
findOperationById,
|
|
944
|
-
|
|
777
|
+
x as formatValue,
|
|
945
778
|
generateCodeSample,
|
|
946
779
|
generateCodeSamples,
|
|
947
780
|
generateCodeSamplesBatch,
|
|
@@ -950,14 +783,14 @@ export {
|
|
|
950
783
|
getFirstAvailableOperationResponse,
|
|
951
784
|
getGenerator,
|
|
952
785
|
getOperation,
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
786
|
+
r as getOperationIds,
|
|
787
|
+
t as getOperationIdsForVersion,
|
|
788
|
+
s as getOperations,
|
|
956
789
|
getSupportedLanguages,
|
|
957
|
-
|
|
958
|
-
isValid,
|
|
790
|
+
v as hasGenerator,
|
|
791
|
+
y as isValid,
|
|
959
792
|
u as useLanguageSelection,
|
|
960
|
-
|
|
961
|
-
validateParams
|
|
793
|
+
m as useSampleLoader,
|
|
794
|
+
z as validateParams
|
|
962
795
|
};
|
|
963
796
|
//# sourceMappingURL=index.js.map
|