swagger-typescript-api 13.6.2 → 13.6.4
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/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-CxPRLeDh.cjs → src-NoDGo0Mg.cjs} +98 -29
- package/dist/src-NoDGo0Mg.cjs.map +1 -0
- package/dist/{src-BQOg3KNL.mjs → src-eiRlSfN6.mjs} +97 -28
- package/dist/src-eiRlSfN6.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/src-BQOg3KNL.mjs.map +0 -1
- package/dist/src-CxPRLeDh.cjs.map +0 -1
|
@@ -13,9 +13,9 @@ import * as nanoid from "nanoid";
|
|
|
13
13
|
import { typeGuard } from "yummies/type-guard";
|
|
14
14
|
import * as crypto from "node:crypto";
|
|
15
15
|
import * as swagger2openapi from "swagger2openapi";
|
|
16
|
-
import * as YAML from "yaml";
|
|
17
16
|
import * as fs from "node:fs";
|
|
18
17
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
18
|
+
import * as YAML from "yaml";
|
|
19
19
|
import * as url$1 from "node:url";
|
|
20
20
|
import url from "node:url";
|
|
21
21
|
import { Eta } from "eta";
|
|
@@ -174,7 +174,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region package.json
|
|
176
176
|
var name = "swagger-typescript-api";
|
|
177
|
-
var version = "13.6.
|
|
177
|
+
var version = "13.6.4";
|
|
178
178
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/constants.ts
|
|
@@ -1838,7 +1838,7 @@ var SchemaRoutes = class {
|
|
|
1838
1838
|
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType, resolvedSwaggerSchema }) => {
|
|
1839
1839
|
const result = [];
|
|
1840
1840
|
for (const [status, requestInfo] of Object.entries(requestInfos || {})) {
|
|
1841
|
-
const contentTypes = this.getContentTypes([requestInfo]
|
|
1841
|
+
const contentTypes = this.getContentTypes([requestInfo]);
|
|
1842
1842
|
const links = this.getRouteLinksFromResponse(resolvedSwaggerSchema, requestInfo, status);
|
|
1843
1843
|
result.push({
|
|
1844
1844
|
...requestInfo || {},
|
|
@@ -2043,11 +2043,53 @@ var SchemaRoutes = class {
|
|
|
2043
2043
|
});
|
|
2044
2044
|
const idx = responseBodyInfo.responses.indexOf(responseBodyInfo.success.schema);
|
|
2045
2045
|
const successResponse = responseBodyInfo.success;
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2046
|
+
const contentKind = successResponse.schema?.contentKind;
|
|
2047
|
+
const actualSchema = this.getSchemaFromRequestType(successResponse.schema);
|
|
2048
|
+
if (actualSchema && !actualSchema.$ref) {
|
|
2049
2049
|
successResponse.schema = this.schemaParserFabric.createParsedComponent({
|
|
2050
|
-
schema,
|
|
2050
|
+
schema: actualSchema,
|
|
2051
|
+
typeName,
|
|
2052
|
+
schemaPath: [routeInfo.operationId]
|
|
2053
|
+
});
|
|
2054
|
+
successResponse.schema.contentKind = contentKind;
|
|
2055
|
+
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
2056
|
+
successResponse.type = this.schemaParserFabric.getInlineParseContent({ $ref: successResponse.schema.$ref });
|
|
2057
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
2058
|
+
...successResponse.schema,
|
|
2059
|
+
type: successResponse.type
|
|
2060
|
+
});
|
|
2061
|
+
} else if (responseBodyInfo.success.isBinary) {
|
|
2062
|
+
successResponse.schema = this.schemaParserFabric.createParsedComponent({
|
|
2063
|
+
schema: {
|
|
2064
|
+
type: "string",
|
|
2065
|
+
format: "byte"
|
|
2066
|
+
},
|
|
2067
|
+
typeName,
|
|
2068
|
+
schemaPath: [routeInfo.operationId]
|
|
2069
|
+
});
|
|
2070
|
+
successResponse.schema.contentKind = contentKind;
|
|
2071
|
+
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
2072
|
+
successResponse.type = this.config.Ts.Keyword.Blob;
|
|
2073
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
2074
|
+
...successResponse.schema,
|
|
2075
|
+
type: successResponse.type
|
|
2076
|
+
});
|
|
2077
|
+
} else if (actualSchema?.$ref) {
|
|
2078
|
+
successResponse.schema = this.schemaParserFabric.createParsedComponent({
|
|
2079
|
+
schema: actualSchema,
|
|
2080
|
+
typeName,
|
|
2081
|
+
schemaPath: [routeInfo.operationId]
|
|
2082
|
+
});
|
|
2083
|
+
successResponse.schema.contentKind = contentKind;
|
|
2084
|
+
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
2085
|
+
successResponse.type = this.schemaParserFabric.getInlineParseContent({ $ref: successResponse.schema.$ref });
|
|
2086
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
2087
|
+
...successResponse.schema,
|
|
2088
|
+
type: successResponse.type
|
|
2089
|
+
});
|
|
2090
|
+
} else if (successResponse.schema && actualSchema === null && (responseBodyInfo.success.type === this.config.Ts.Keyword.Any || responseBodyInfo.success.type === this.config.defaultResponseType)) {
|
|
2091
|
+
successResponse.schema = this.schemaParserFabric.createParsedComponent({
|
|
2092
|
+
schema: {},
|
|
2051
2093
|
typeName,
|
|
2052
2094
|
schemaPath: [routeInfo.operationId]
|
|
2053
2095
|
});
|
|
@@ -2285,6 +2327,48 @@ var SchemaRoutes = class {
|
|
|
2285
2327
|
};
|
|
2286
2328
|
};
|
|
2287
2329
|
//#endregion
|
|
2330
|
+
//#region src/util/parse-schema-content.ts
|
|
2331
|
+
function normalizeYamlEscapedLineBreaks(content) {
|
|
2332
|
+
let normalized = "";
|
|
2333
|
+
let inDoubleQuotedScalar = false;
|
|
2334
|
+
let escaped = false;
|
|
2335
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
2336
|
+
const currentChar = content[index];
|
|
2337
|
+
if (!inDoubleQuotedScalar) {
|
|
2338
|
+
if (currentChar === "\"") inDoubleQuotedScalar = true;
|
|
2339
|
+
normalized += currentChar;
|
|
2340
|
+
continue;
|
|
2341
|
+
}
|
|
2342
|
+
if (escaped) {
|
|
2343
|
+
normalized += currentChar;
|
|
2344
|
+
escaped = false;
|
|
2345
|
+
continue;
|
|
2346
|
+
}
|
|
2347
|
+
if (currentChar === "\\") {
|
|
2348
|
+
const nextChar = content[index + 1];
|
|
2349
|
+
if (nextChar === "\n" || nextChar === "\r") {
|
|
2350
|
+
index += 1;
|
|
2351
|
+
if (nextChar === "\r" && content[index + 1] === "\n") index += 1;
|
|
2352
|
+
while (content[index + 1] === " " || content[index + 1] === " ") index += 1;
|
|
2353
|
+
continue;
|
|
2354
|
+
}
|
|
2355
|
+
normalized += currentChar;
|
|
2356
|
+
escaped = true;
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
if (currentChar === "\"") inDoubleQuotedScalar = false;
|
|
2360
|
+
normalized += currentChar;
|
|
2361
|
+
}
|
|
2362
|
+
return normalized;
|
|
2363
|
+
}
|
|
2364
|
+
function parseSchemaContent(content) {
|
|
2365
|
+
try {
|
|
2366
|
+
return JSON.parse(content);
|
|
2367
|
+
} catch {
|
|
2368
|
+
return YAML.parse(normalizeYamlEscapedLineBreaks(content));
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
//#endregion
|
|
2288
2372
|
//#region src/resolved-swagger-schema.ts
|
|
2289
2373
|
var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
2290
2374
|
parsedRefsCache = /* @__PURE__ */ new Map();
|
|
@@ -2350,11 +2434,10 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
|
2350
2434
|
if (!response.ok) return null;
|
|
2351
2435
|
const content = await response.text();
|
|
2352
2436
|
try {
|
|
2353
|
-
const parsed =
|
|
2437
|
+
const parsed = parseSchemaContent(content);
|
|
2354
2438
|
if (parsed && typeof parsed === "object") return parsed;
|
|
2355
2439
|
} catch {
|
|
2356
|
-
|
|
2357
|
-
if (parsed && typeof parsed === "object") return parsed;
|
|
2440
|
+
return null;
|
|
2358
2441
|
}
|
|
2359
2442
|
} catch (e) {
|
|
2360
2443
|
consola.debug(e);
|
|
@@ -2517,21 +2600,11 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
|
2517
2600
|
if (this.externalSchemaCache.has(filePath)) return this.externalSchemaCache.get(filePath) || null;
|
|
2518
2601
|
if (!fs.existsSync(filePath)) return null;
|
|
2519
2602
|
try {
|
|
2520
|
-
const
|
|
2521
|
-
const parsed = JSON.parse(content);
|
|
2603
|
+
const parsed = parseSchemaContent(fs.readFileSync(filePath, "utf8"));
|
|
2522
2604
|
this.externalSchemaCache.set(filePath, parsed);
|
|
2523
2605
|
return parsed;
|
|
2524
2606
|
} catch {
|
|
2525
|
-
|
|
2526
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
2527
|
-
const parsed = YAML.parse(content);
|
|
2528
|
-
if (parsed && typeof parsed === "object") {
|
|
2529
|
-
this.externalSchemaCache.set(filePath, parsed);
|
|
2530
|
-
return parsed;
|
|
2531
|
-
}
|
|
2532
|
-
} catch (e) {
|
|
2533
|
-
consola.debug(e);
|
|
2534
|
-
}
|
|
2607
|
+
consola.debug("Failed to parse external schema", filePath);
|
|
2535
2608
|
}
|
|
2536
2609
|
return null;
|
|
2537
2610
|
}
|
|
@@ -2728,11 +2801,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2728
2801
|
}
|
|
2729
2802
|
processSwaggerSchemaFile(file) {
|
|
2730
2803
|
if (typeof file !== "string") return file;
|
|
2731
|
-
|
|
2732
|
-
return JSON.parse(file);
|
|
2733
|
-
} catch {
|
|
2734
|
-
return YAML.parse(file);
|
|
2735
|
-
}
|
|
2804
|
+
return parseSchemaContent(file);
|
|
2736
2805
|
}
|
|
2737
2806
|
normalizeRefValue(ref) {
|
|
2738
2807
|
const refWithoutSlashBeforeHash = ref.split("/#/").join("#/");
|
|
@@ -3471,4 +3540,4 @@ async function generateApi(config) {
|
|
|
3471
3540
|
//#endregion
|
|
3472
3541
|
export { SCHEMA_TYPES as a, constants_exports as c, version as d, RequestContentKind as i, description as l, generateTemplates as n, CodeGenConfig as o, TemplatesGenConfig as r, HTTP_CLIENT as s, generateApi as t, name as u };
|
|
3473
3542
|
|
|
3474
|
-
//# sourceMappingURL=src-
|
|
3543
|
+
//# sourceMappingURL=src-eiRlSfN6.mjs.map
|