typed-openapi 0.4.1 → 0.6.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-XEXIEYXO.js → chunk-UHCVCAGY.js} +15 -12
- package/dist/cli.cjs +16 -13
- package/dist/cli.js +2 -2
- package/dist/index.cjs +15 -12
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/generator.ts +1 -1
- package/src/map-openapi-endpoints.ts +16 -11
|
@@ -291,7 +291,7 @@ var inferByRuntime = {
|
|
|
291
291
|
arktype: (input) => `${input}["infer"]`,
|
|
292
292
|
"io-ts": (input) => `t.TypeOf<${input}>`,
|
|
293
293
|
typebox: (input) => `Static<${input}>`,
|
|
294
|
-
valibot: (input) => `v.
|
|
294
|
+
valibot: (input) => `v.InferOutput<${input}>`,
|
|
295
295
|
yup: (input) => `y.InferType<${input}>`,
|
|
296
296
|
zod: (input) => `z.infer<${input}>`
|
|
297
297
|
};
|
|
@@ -774,16 +774,19 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
774
774
|
}
|
|
775
775
|
if (params) {
|
|
776
776
|
const t = createBoxFactory({}, ctx);
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
777
|
+
const filtered_params = ["query", "path", "header"];
|
|
778
|
+
for (const k of filtered_params) {
|
|
779
|
+
if (params[k] && lists[k].length) {
|
|
780
|
+
if (lists[k].every((param) => !param.required)) {
|
|
781
|
+
params[k] = t.reference("Partial", [t.object(params[k])]);
|
|
782
|
+
} else {
|
|
783
|
+
for (const p of lists[k]) {
|
|
784
|
+
if (!p.required) {
|
|
785
|
+
params[k][p.name] = t.optional(params[k][p.name]);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
787
790
|
}
|
|
788
791
|
endpoint.parameters = Object.keys(params).length ? params : void 0;
|
|
789
792
|
}
|
|
@@ -820,7 +823,7 @@ var allowedParamMediaTypes = [
|
|
|
820
823
|
];
|
|
821
824
|
var isAllowedParamMediaTypes = (mediaType) => mediaType.includes("application/") && mediaType.includes("json") || allowedParamMediaTypes.includes(mediaType) || mediaType.includes("text/");
|
|
822
825
|
var isResponseMediaType = (mediaType) => mediaType === "application/json";
|
|
823
|
-
var getAlias = ({ path, method, operation }) => method + "_" + capitalize3(operation.operationId ?? pathToVariableName(path));
|
|
826
|
+
var getAlias = ({ path, method, operation }) => (method + "_" + capitalize3(operation.operationId ?? pathToVariableName(path))).replace(/-/g, "__");
|
|
824
827
|
|
|
825
828
|
export {
|
|
826
829
|
unwrap,
|
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.6.0";
|
|
35
35
|
|
|
36
36
|
// src/generator.ts
|
|
37
37
|
var import_server2 = require("pastable/server");
|
|
@@ -326,7 +326,7 @@ var inferByRuntime = {
|
|
|
326
326
|
arktype: (input) => `${input}["infer"]`,
|
|
327
327
|
"io-ts": (input) => `t.TypeOf<${input}>`,
|
|
328
328
|
typebox: (input) => `Static<${input}>`,
|
|
329
|
-
valibot: (input) => `v.
|
|
329
|
+
valibot: (input) => `v.InferOutput<${input}>`,
|
|
330
330
|
yup: (input) => `y.InferType<${input}>`,
|
|
331
331
|
zod: (input) => `z.infer<${input}>`
|
|
332
332
|
};
|
|
@@ -811,16 +811,19 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
811
811
|
}
|
|
812
812
|
if (params) {
|
|
813
813
|
const t = createBoxFactory({}, ctx);
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
814
|
+
const filtered_params = ["query", "path", "header"];
|
|
815
|
+
for (const k of filtered_params) {
|
|
816
|
+
if (params[k] && lists[k].length) {
|
|
817
|
+
if (lists[k].every((param) => !param.required)) {
|
|
818
|
+
params[k] = t.reference("Partial", [t.object(params[k])]);
|
|
819
|
+
} else {
|
|
820
|
+
for (const p of lists[k]) {
|
|
821
|
+
if (!p.required) {
|
|
822
|
+
params[k][p.name] = t.optional(params[k][p.name]);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
824
827
|
}
|
|
825
828
|
endpoint.parameters = Object.keys(params).length ? params : void 0;
|
|
826
829
|
}
|
|
@@ -857,7 +860,7 @@ var allowedParamMediaTypes = [
|
|
|
857
860
|
];
|
|
858
861
|
var isAllowedParamMediaTypes = (mediaType) => mediaType.includes("application/") && mediaType.includes("json") || allowedParamMediaTypes.includes(mediaType) || mediaType.includes("text/");
|
|
859
862
|
var isResponseMediaType = (mediaType) => mediaType === "application/json";
|
|
860
|
-
var getAlias = ({ path, method, operation }) => method + "_" + (0, import_server4.capitalize)(operation.operationId ?? pathToVariableName(path));
|
|
863
|
+
var getAlias = ({ path, method, operation }) => (method + "_" + (0, import_server4.capitalize)(operation.operationId ?? pathToVariableName(path))).replace(/-/g, "__");
|
|
861
864
|
|
|
862
865
|
// src/cli.ts
|
|
863
866
|
var cwd = process.cwd();
|
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-UHCVCAGY.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.6.0";
|
|
17
17
|
|
|
18
18
|
// src/cli.ts
|
|
19
19
|
var cwd = process.cwd();
|
package/dist/index.cjs
CHANGED
|
@@ -334,7 +334,7 @@ var inferByRuntime = {
|
|
|
334
334
|
arktype: (input) => `${input}["infer"]`,
|
|
335
335
|
"io-ts": (input) => `t.TypeOf<${input}>`,
|
|
336
336
|
typebox: (input) => `Static<${input}>`,
|
|
337
|
-
valibot: (input) => `v.
|
|
337
|
+
valibot: (input) => `v.InferOutput<${input}>`,
|
|
338
338
|
yup: (input) => `y.InferType<${input}>`,
|
|
339
339
|
zod: (input) => `z.infer<${input}>`
|
|
340
340
|
};
|
|
@@ -819,16 +819,19 @@ var mapOpenApiEndpoints = (doc) => {
|
|
|
819
819
|
}
|
|
820
820
|
if (params) {
|
|
821
821
|
const t = createBoxFactory({}, ctx);
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
822
|
+
const filtered_params = ["query", "path", "header"];
|
|
823
|
+
for (const k of filtered_params) {
|
|
824
|
+
if (params[k] && lists[k].length) {
|
|
825
|
+
if (lists[k].every((param) => !param.required)) {
|
|
826
|
+
params[k] = t.reference("Partial", [t.object(params[k])]);
|
|
827
|
+
} else {
|
|
828
|
+
for (const p of lists[k]) {
|
|
829
|
+
if (!p.required) {
|
|
830
|
+
params[k][p.name] = t.optional(params[k][p.name]);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
832
835
|
}
|
|
833
836
|
endpoint.parameters = Object.keys(params).length ? params : void 0;
|
|
834
837
|
}
|
|
@@ -865,7 +868,7 @@ var allowedParamMediaTypes = [
|
|
|
865
868
|
];
|
|
866
869
|
var isAllowedParamMediaTypes = (mediaType) => mediaType.includes("application/") && mediaType.includes("json") || allowedParamMediaTypes.includes(mediaType) || mediaType.includes("text/");
|
|
867
870
|
var isResponseMediaType = (mediaType) => mediaType === "application/json";
|
|
868
|
-
var getAlias = ({ path, method, operation }) => method + "_" + (0, import_server4.capitalize)(operation.operationId ?? pathToVariableName(path));
|
|
871
|
+
var getAlias = ({ path, method, operation }) => (method + "_" + (0, import_server4.capitalize)(operation.operationId ?? pathToVariableName(path))).replace(/-/g, "__");
|
|
869
872
|
// Annotate the CommonJS export names for ESM import in node:
|
|
870
873
|
0 && (module.exports = {
|
|
871
874
|
createBoxFactory,
|
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.6.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.
|
|
18
|
+
"@sinclair/typebox-codegen": "^0.10.3",
|
|
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
|
@@ -33,7 +33,7 @@ const inferByRuntime = {
|
|
|
33
33
|
arktype: (input: string) => `${input}["infer"]`,
|
|
34
34
|
"io-ts": (input: string) => `t.TypeOf<${input}>`,
|
|
35
35
|
typebox: (input: string) => `Static<${input}>`,
|
|
36
|
-
valibot: (input: string) => `v.
|
|
36
|
+
valibot: (input: string) => `v.InferOutput<${input}>`,
|
|
37
37
|
yup: (input: string) => `y.InferType<${input}>`,
|
|
38
38
|
zod: (input: string) => `z.infer<${input}>`,
|
|
39
39
|
};
|
|
@@ -85,18 +85,23 @@ export const mapOpenApiEndpoints = (doc: OpenAPIObject) => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
// Make parameters optional if
|
|
88
|
+
// Make parameters optional if all or some of them are not required
|
|
89
89
|
if (params) {
|
|
90
90
|
const t = createBoxFactory({}, ctx);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
const filtered_params = ["query", "path", "header"] as Array<keyof Pick<typeof params, "query" | "path" | "header">>;
|
|
92
|
+
|
|
93
|
+
for (const k of filtered_params) {
|
|
94
|
+
if (params[k] && lists[k].length) {
|
|
95
|
+
if (lists[k].every((param) => !param.required)) {
|
|
96
|
+
params[k] = t.reference("Partial", [t.object(params[k]!)]) as any;
|
|
97
|
+
} else {
|
|
98
|
+
for (const p of lists[k]) {
|
|
99
|
+
if (!p.required) {
|
|
100
|
+
params[k]![p.name] = t.optional(params[k]![p.name] as any);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
// No need to pass empty objects, it's confusing
|
|
@@ -148,7 +153,7 @@ const isAllowedParamMediaTypes = (
|
|
|
148
153
|
|
|
149
154
|
const isResponseMediaType = (mediaType: string) => mediaType === "application/json";
|
|
150
155
|
const getAlias = ({ path, method, operation }: Endpoint) =>
|
|
151
|
-
method + "_" + capitalize(operation.operationId ?? pathToVariableName(path));
|
|
156
|
+
(method + "_" + capitalize(operation.operationId ?? pathToVariableName(path))).replace(/-/g, "__");
|
|
152
157
|
|
|
153
158
|
type MutationMethod = "post" | "put" | "patch" | "delete";
|
|
154
159
|
type Method = "get" | "head" | "options" | MutationMethod;
|