typed-openapi 0.8.0 → 0.10.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/{chunk-LQ2C2J6D.js → chunk-WT2PCM73.js} +10 -3
- package/dist/cli.cjs +11 -4
- package/dist/cli.js +2 -2
- package/dist/index.cjs +10 -3
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/generator.ts +5 -1
- package/src/map-openapi-endpoints.ts +15 -1
|
@@ -312,8 +312,8 @@ var generateFile = (options) => {
|
|
|
312
312
|
const transformer = runtimeValidationGenerator[ctx.runtime];
|
|
313
313
|
const generated = ctx.runtime === "typebox" ? Codegen.TypeScriptToTypeBox.Generate(file2) : transformer(model);
|
|
314
314
|
let converted = "";
|
|
315
|
-
const
|
|
316
|
-
const content =
|
|
315
|
+
const match3 = generated.match(/(const __ENDPOINTS_START__ =)([\s\S]*?)(export type __ENDPOINTS_END__)/);
|
|
316
|
+
const content = match3?.[2];
|
|
317
317
|
if (content && ctx.runtime in replacerByRuntime) {
|
|
318
318
|
const before = generated.slice(0, generated.indexOf("export type __ENDPOINTS_START"));
|
|
319
319
|
converted = before + replacerByRuntime[ctx.runtime](
|
|
@@ -369,6 +369,7 @@ var generateEndpointSchemaList = (ctx) => {
|
|
|
369
369
|
file += `export type ${endpoint.meta.alias} = {
|
|
370
370
|
method: "${endpoint.method.toUpperCase()}",
|
|
371
371
|
path: "${endpoint.path}",
|
|
372
|
+
requestFormat: "${endpoint.requestFormat}",
|
|
372
373
|
${endpoint.meta.hasParameters ? `parameters: {
|
|
373
374
|
${parameters.query ? `query: ${parameterObjectToString(parameters.query)},` : ""}
|
|
374
375
|
${parameters.path ? `path: ${parameterObjectToString(parameters.path)},` : ""}
|
|
@@ -437,7 +438,9 @@ export type EndpointParameters = {
|
|
|
437
438
|
};
|
|
438
439
|
|
|
439
440
|
export type MutationMethod = "post" | "put" | "patch" | "delete";
|
|
440
|
-
export type Method = "get" | "head" | MutationMethod;
|
|
441
|
+
export type Method = "get" | "head" | "options" | MutationMethod;
|
|
442
|
+
|
|
443
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
441
444
|
|
|
442
445
|
export type DefaultEndpoint = {
|
|
443
446
|
parameters?: EndpointParameters | undefined;
|
|
@@ -448,6 +451,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
448
451
|
operationId: string;
|
|
449
452
|
method: Method;
|
|
450
453
|
path: string;
|
|
454
|
+
requestFormat: RequestFormat;
|
|
451
455
|
parameters?: TConfig["parameters"];
|
|
452
456
|
meta: {
|
|
453
457
|
alias: string;
|
|
@@ -709,6 +713,7 @@ var tsFactory = createFactory({
|
|
|
709
713
|
|
|
710
714
|
// src/map-openapi-endpoints.ts
|
|
711
715
|
import { capitalize as capitalize3, pick } from "pastable/server";
|
|
716
|
+
import { match as match2, P } from "ts-pattern";
|
|
712
717
|
var factory = tsFactory;
|
|
713
718
|
var mapOpenApiEndpoints = (doc) => {
|
|
714
719
|
const refs = createRefResolver(doc, factory);
|
|
@@ -723,6 +728,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
723
728
|
operation,
|
|
724
729
|
method,
|
|
725
730
|
path,
|
|
731
|
+
requestFormat: "json",
|
|
726
732
|
response: openApiSchemaToTs({ schema: {}, ctx }),
|
|
727
733
|
meta: {
|
|
728
734
|
alias: getAlias({ path, method, operation }),
|
|
@@ -771,6 +777,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
771
777
|
ctx
|
|
772
778
|
});
|
|
773
779
|
}
|
|
780
|
+
endpoint.requestFormat = match2(matchingMediaType).with("application/octet-stream", () => "binary").with("multipart/form-data", () => "form-data").with("application/x-www-form-urlencoded", () => "form-url").with(P.string.includes("json"), () => "json").otherwise(() => "text");
|
|
774
781
|
}
|
|
775
782
|
if (params) {
|
|
776
783
|
const t = createBoxFactory({}, ctx);
|
package/dist/cli.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var import_promises = require("fs/promises");
|
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
33
|
var name = "typed-openapi";
|
|
34
|
-
var version = "0.
|
|
34
|
+
var version = "0.10.0";
|
|
35
35
|
|
|
36
36
|
// src/generator.ts
|
|
37
37
|
var import_server2 = require("pastable/server");
|
|
@@ -347,8 +347,8 @@ var generateFile = (options) => {
|
|
|
347
347
|
const transformer = runtimeValidationGenerator[ctx.runtime];
|
|
348
348
|
const generated = ctx.runtime === "typebox" ? Codegen.TypeScriptToTypeBox.Generate(file2) : transformer(model);
|
|
349
349
|
let converted = "";
|
|
350
|
-
const
|
|
351
|
-
const content =
|
|
350
|
+
const match3 = generated.match(/(const __ENDPOINTS_START__ =)([\s\S]*?)(export type __ENDPOINTS_END__)/);
|
|
351
|
+
const content = match3?.[2];
|
|
352
352
|
if (content && ctx.runtime in replacerByRuntime) {
|
|
353
353
|
const before = generated.slice(0, generated.indexOf("export type __ENDPOINTS_START"));
|
|
354
354
|
converted = before + replacerByRuntime[ctx.runtime](
|
|
@@ -404,6 +404,7 @@ var generateEndpointSchemaList = (ctx) => {
|
|
|
404
404
|
file += `export type ${endpoint.meta.alias} = {
|
|
405
405
|
method: "${endpoint.method.toUpperCase()}",
|
|
406
406
|
path: "${endpoint.path}",
|
|
407
|
+
requestFormat: "${endpoint.requestFormat}",
|
|
407
408
|
${endpoint.meta.hasParameters ? `parameters: {
|
|
408
409
|
${parameters.query ? `query: ${parameterObjectToString(parameters.query)},` : ""}
|
|
409
410
|
${parameters.path ? `path: ${parameterObjectToString(parameters.path)},` : ""}
|
|
@@ -472,7 +473,9 @@ export type EndpointParameters = {
|
|
|
472
473
|
};
|
|
473
474
|
|
|
474
475
|
export type MutationMethod = "post" | "put" | "patch" | "delete";
|
|
475
|
-
export type Method = "get" | "head" | MutationMethod;
|
|
476
|
+
export type Method = "get" | "head" | "options" | MutationMethod;
|
|
477
|
+
|
|
478
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
476
479
|
|
|
477
480
|
export type DefaultEndpoint = {
|
|
478
481
|
parameters?: EndpointParameters | undefined;
|
|
@@ -483,6 +486,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
483
486
|
operationId: string;
|
|
484
487
|
method: Method;
|
|
485
488
|
path: string;
|
|
489
|
+
requestFormat: RequestFormat;
|
|
486
490
|
parameters?: TConfig["parameters"];
|
|
487
491
|
meta: {
|
|
488
492
|
alias: string;
|
|
@@ -746,6 +750,7 @@ var tsFactory = createFactory({
|
|
|
746
750
|
});
|
|
747
751
|
|
|
748
752
|
// src/map-openapi-endpoints.ts
|
|
753
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
749
754
|
var factory = tsFactory;
|
|
750
755
|
var mapOpenApiEndpoints = (doc) => {
|
|
751
756
|
const refs = createRefResolver(doc, factory);
|
|
@@ -760,6 +765,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
760
765
|
operation,
|
|
761
766
|
method,
|
|
762
767
|
path,
|
|
768
|
+
requestFormat: "json",
|
|
763
769
|
response: openApiSchemaToTs({ schema: {}, ctx }),
|
|
764
770
|
meta: {
|
|
765
771
|
alias: getAlias({ path, method, operation }),
|
|
@@ -808,6 +814,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
808
814
|
ctx
|
|
809
815
|
});
|
|
810
816
|
}
|
|
817
|
+
endpoint.requestFormat = (0, import_ts_pattern2.match)(matchingMediaType).with("application/octet-stream", () => "binary").with("multipart/form-data", () => "form-data").with("application/x-www-form-urlencoded", () => "form-url").with(import_ts_pattern2.P.string.includes("json"), () => "json").otherwise(() => "text");
|
|
811
818
|
}
|
|
812
819
|
if (params) {
|
|
813
820
|
const t = createBoxFactory({}, ctx);
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
allowedRuntimes,
|
|
3
3
|
generateFile,
|
|
4
4
|
mapOpenApiEndpoints
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-WT2PCM73.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
@@ -13,7 +13,7 @@ import { writeFile } from "fs/promises";
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var name = "typed-openapi";
|
|
16
|
-
var version = "0.
|
|
16
|
+
var version = "0.10.0";
|
|
17
17
|
|
|
18
18
|
// src/cli.ts
|
|
19
19
|
var cwd = process.cwd();
|
package/dist/index.cjs
CHANGED
|
@@ -355,8 +355,8 @@ var generateFile = (options) => {
|
|
|
355
355
|
const transformer = runtimeValidationGenerator[ctx.runtime];
|
|
356
356
|
const generated = ctx.runtime === "typebox" ? Codegen.TypeScriptToTypeBox.Generate(file2) : transformer(model);
|
|
357
357
|
let converted = "";
|
|
358
|
-
const
|
|
359
|
-
const content =
|
|
358
|
+
const match3 = generated.match(/(const __ENDPOINTS_START__ =)([\s\S]*?)(export type __ENDPOINTS_END__)/);
|
|
359
|
+
const content = match3?.[2];
|
|
360
360
|
if (content && ctx.runtime in replacerByRuntime) {
|
|
361
361
|
const before = generated.slice(0, generated.indexOf("export type __ENDPOINTS_START"));
|
|
362
362
|
converted = before + replacerByRuntime[ctx.runtime](
|
|
@@ -412,6 +412,7 @@ var generateEndpointSchemaList = (ctx) => {
|
|
|
412
412
|
file += `export type ${endpoint.meta.alias} = {
|
|
413
413
|
method: "${endpoint.method.toUpperCase()}",
|
|
414
414
|
path: "${endpoint.path}",
|
|
415
|
+
requestFormat: "${endpoint.requestFormat}",
|
|
415
416
|
${endpoint.meta.hasParameters ? `parameters: {
|
|
416
417
|
${parameters.query ? `query: ${parameterObjectToString(parameters.query)},` : ""}
|
|
417
418
|
${parameters.path ? `path: ${parameterObjectToString(parameters.path)},` : ""}
|
|
@@ -480,7 +481,9 @@ export type EndpointParameters = {
|
|
|
480
481
|
};
|
|
481
482
|
|
|
482
483
|
export type MutationMethod = "post" | "put" | "patch" | "delete";
|
|
483
|
-
export type Method = "get" | "head" | MutationMethod;
|
|
484
|
+
export type Method = "get" | "head" | "options" | MutationMethod;
|
|
485
|
+
|
|
486
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
484
487
|
|
|
485
488
|
export type DefaultEndpoint = {
|
|
486
489
|
parameters?: EndpointParameters | undefined;
|
|
@@ -491,6 +494,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
491
494
|
operationId: string;
|
|
492
495
|
method: Method;
|
|
493
496
|
path: string;
|
|
497
|
+
requestFormat: RequestFormat;
|
|
494
498
|
parameters?: TConfig["parameters"];
|
|
495
499
|
meta: {
|
|
496
500
|
alias: string;
|
|
@@ -754,6 +758,7 @@ var tsFactory = createFactory({
|
|
|
754
758
|
});
|
|
755
759
|
|
|
756
760
|
// src/map-openapi-endpoints.ts
|
|
761
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
757
762
|
var factory = tsFactory;
|
|
758
763
|
var mapOpenApiEndpoints = (doc) => {
|
|
759
764
|
const refs = createRefResolver(doc, factory);
|
|
@@ -768,6 +773,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
768
773
|
operation,
|
|
769
774
|
method,
|
|
770
775
|
path,
|
|
776
|
+
requestFormat: "json",
|
|
771
777
|
response: openApiSchemaToTs({ schema: {}, ctx }),
|
|
772
778
|
meta: {
|
|
773
779
|
alias: getAlias({ path, method, operation }),
|
|
@@ -816,6 +822,7 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
816
822
|
ctx
|
|
817
823
|
});
|
|
818
824
|
}
|
|
825
|
+
endpoint.requestFormat = (0, import_ts_pattern2.match)(matchingMediaType).with("application/octet-stream", () => "binary").with("multipart/form-data", () => "form-data").with("application/x-www-form-urlencoded", () => "form-url").with(import_ts_pattern2.P.string.includes("json"), () => "json").otherwise(() => "text");
|
|
819
826
|
}
|
|
820
827
|
if (params) {
|
|
821
828
|
const t = createBoxFactory({}, ctx);
|
package/dist/index.d.cts
CHANGED
|
@@ -213,6 +213,7 @@ type EndpointParameters = {
|
|
|
213
213
|
header?: Box<BoxRef> | Record<string, AnyBox>;
|
|
214
214
|
path?: Box<BoxRef> | Record<string, AnyBox>;
|
|
215
215
|
};
|
|
216
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
216
217
|
type DefaultEndpoint = {
|
|
217
218
|
parameters?: EndpointParameters | undefined;
|
|
218
219
|
response: AnyBox;
|
|
@@ -222,6 +223,7 @@ type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
222
223
|
method: Method;
|
|
223
224
|
path: string;
|
|
224
225
|
parameters?: TConfig["parameters"];
|
|
226
|
+
requestFormat: RequestFormat;
|
|
225
227
|
meta: {
|
|
226
228
|
alias: string;
|
|
227
229
|
hasParameters: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -213,6 +213,7 @@ type EndpointParameters = {
|
|
|
213
213
|
header?: Box<BoxRef> | Record<string, AnyBox>;
|
|
214
214
|
path?: Box<BoxRef> | Record<string, AnyBox>;
|
|
215
215
|
};
|
|
216
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
216
217
|
type DefaultEndpoint = {
|
|
217
218
|
parameters?: EndpointParameters | undefined;
|
|
218
219
|
response: AnyBox;
|
|
@@ -222,6 +223,7 @@ type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
222
223
|
method: Method;
|
|
223
224
|
path: string;
|
|
224
225
|
parameters?: TConfig["parameters"];
|
|
226
|
+
requestFormat: RequestFormat;
|
|
225
227
|
meta: {
|
|
226
228
|
alias: string;
|
|
227
229
|
hasParameters: boolean;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typed-openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
17
17
|
"@changesets/cli": "^2.26.2",
|
|
18
|
-
"@sinclair/typebox-codegen": "^0.10.
|
|
18
|
+
"@sinclair/typebox-codegen": "^0.10.5",
|
|
19
19
|
"arktype": "1.0.18-alpha",
|
|
20
20
|
"cac": "^6.7.14",
|
|
21
21
|
"openapi3-ts": "^4.1.2",
|
package/src/generator.ts
CHANGED
|
@@ -137,6 +137,7 @@ const generateEndpointSchemaList = (ctx: GeneratorContext) => {
|
|
|
137
137
|
file += `export type ${endpoint.meta.alias} = {
|
|
138
138
|
method: "${endpoint.method.toUpperCase()}",
|
|
139
139
|
path: "${endpoint.path}",
|
|
140
|
+
requestFormat: "${endpoint.requestFormat}",
|
|
140
141
|
${
|
|
141
142
|
endpoint.meta.hasParameters
|
|
142
143
|
? `parameters: {
|
|
@@ -233,7 +234,9 @@ export type EndpointParameters = {
|
|
|
233
234
|
};
|
|
234
235
|
|
|
235
236
|
export type MutationMethod = "post" | "put" | "patch" | "delete";
|
|
236
|
-
export type Method = "get" | "head" | MutationMethod;
|
|
237
|
+
export type Method = "get" | "head" | "options" | MutationMethod;
|
|
238
|
+
|
|
239
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
237
240
|
|
|
238
241
|
export type DefaultEndpoint = {
|
|
239
242
|
parameters?: EndpointParameters | undefined;
|
|
@@ -244,6 +247,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
244
247
|
operationId: string;
|
|
245
248
|
method: Method;
|
|
246
249
|
path: string;
|
|
250
|
+
requestFormat: RequestFormat;
|
|
247
251
|
parameters?: TConfig["parameters"];
|
|
248
252
|
meta: {
|
|
249
253
|
alias: string;
|
|
@@ -8,6 +8,7 @@ import { createRefResolver } from "./ref-resolver";
|
|
|
8
8
|
import { tsFactory } from "./ts-factory";
|
|
9
9
|
import { AnyBox, BoxRef, OpenapiSchemaConvertContext } from "./types";
|
|
10
10
|
import { pathToVariableName } from "./string-utils";
|
|
11
|
+
import { match, P } from "ts-pattern";
|
|
11
12
|
|
|
12
13
|
const factory = tsFactory;
|
|
13
14
|
|
|
@@ -25,6 +26,7 @@ export const mapOpenApiEndpoints = (doc: OpenAPIObject) => {
|
|
|
25
26
|
operation,
|
|
26
27
|
method: method as Method,
|
|
27
28
|
path,
|
|
29
|
+
requestFormat: "json",
|
|
28
30
|
response: openApiSchemaToTs({ schema: {}, ctx }),
|
|
29
31
|
meta: {
|
|
30
32
|
alias: getAlias({ path, method, operation } as Endpoint),
|
|
@@ -83,12 +85,21 @@ export const mapOpenApiEndpoints = (doc: OpenAPIObject) => {
|
|
|
83
85
|
ctx,
|
|
84
86
|
});
|
|
85
87
|
}
|
|
88
|
+
|
|
89
|
+
endpoint.requestFormat = match(matchingMediaType)
|
|
90
|
+
.with("application/octet-stream", () => "binary" as const)
|
|
91
|
+
.with("multipart/form-data", () => "form-data" as const)
|
|
92
|
+
.with("application/x-www-form-urlencoded", () => "form-url" as const)
|
|
93
|
+
.with(P.string.includes("json"), () => "json" as const)
|
|
94
|
+
.otherwise(() => "text" as const);
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
// Make parameters optional if all or some of them are not required
|
|
89
98
|
if (params) {
|
|
90
99
|
const t = createBoxFactory({}, ctx);
|
|
91
|
-
const filtered_params = ["query", "path", "header"] as Array<
|
|
100
|
+
const filtered_params = ["query", "path", "header"] as Array<
|
|
101
|
+
keyof Pick<typeof params, "query" | "path" | "header">
|
|
102
|
+
>;
|
|
92
103
|
|
|
93
104
|
for (const k of filtered_params) {
|
|
94
105
|
if (params[k] && lists[k].length) {
|
|
@@ -165,6 +176,8 @@ export type EndpointParameters = {
|
|
|
165
176
|
path?: Box<BoxRef> | Record<string, AnyBox>;
|
|
166
177
|
};
|
|
167
178
|
|
|
179
|
+
type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
|
|
180
|
+
|
|
168
181
|
type DefaultEndpoint = {
|
|
169
182
|
parameters?: EndpointParameters | undefined;
|
|
170
183
|
response: AnyBox;
|
|
@@ -175,6 +188,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
|
|
|
175
188
|
method: Method;
|
|
176
189
|
path: string;
|
|
177
190
|
parameters?: TConfig["parameters"];
|
|
191
|
+
requestFormat: RequestFormat;
|
|
178
192
|
meta: {
|
|
179
193
|
alias: string;
|
|
180
194
|
hasParameters: boolean;
|