@hasagi/schema 0.6.2 → 0.6.3
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.
|
@@ -50,7 +50,7 @@ function getType(input) {
|
|
|
50
50
|
case "object":
|
|
51
51
|
return { type: "object", additionalProperties: true };
|
|
52
52
|
case "":
|
|
53
|
-
return
|
|
53
|
+
return undefined; //
|
|
54
54
|
default:
|
|
55
55
|
return { $ref: `#/components/schemas/${type}` };
|
|
56
56
|
}
|
|
@@ -191,7 +191,8 @@ function endpointToOperation(endpoint, schema) {
|
|
|
191
191
|
}
|
|
192
192
|
else if (endpoint.method === "GET" || endpoint.method === "DELETE" || endpoint.method === "HEAD" || endpoint.method === "OPTIONS" || endpoint.method === "TRACE") {
|
|
193
193
|
const params = endpoint.arguments.slice(parameters.length).flatMap(arg => {
|
|
194
|
-
|
|
194
|
+
console.log(arg);
|
|
195
|
+
const type = getType(arg) ?? { type: "object", additionalProperties: true };
|
|
195
196
|
if ("$ref" in type) {
|
|
196
197
|
const schemaObject = schema.components.schemas[type.$ref.split("/").at(-1)];
|
|
197
198
|
if (schemaObject.properties)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatFieldName, formatForArrayLabel } from "../util.js";
|
|
1
|
+
import { formatFieldName, formatForArrayLabel, sanitizeTypeScriptName } from "../util.js";
|
|
2
2
|
const DEFAULT_TYPES = `export type LCUEndpoint<Method extends HttpMethod, Path extends EndpointsWithMethod<Method>> = (...args: [...(Path extends keyof LCUEndpoints ? Method extends keyof LCUEndpoints[Path] ? "path" extends keyof LCUEndpoints[Path][Method] ? LCUEndpoints[Path][Method]["path"] extends never ? [] : LCUEndpoints[Path][Method]["path"] : [] : [] : []), ...(LCUEndpointBodyType<Method, Path> extends never ? (LCUEndpointParams<Method, Path> extends never ? [] : {} extends LCUEndpointParams<Method, Path> ? [data?: LCUEndpointParams<Method, Path>] : [data: LCUEndpointParams<Method, Path>]) : [data: LCUEndpointBodyType<Method, Path>])]) => Promise<LCUEndpointResponseType<Method, Path>>
|
|
3
3
|
export type LCUEndpointResponseType<Method extends string, Path extends string> = Path extends keyof LCUEndpoints ? Method extends keyof LCUEndpoints[Path] ? "response" extends keyof LCUEndpoints[Path][Method] ? LCUEndpoints[Path][Method]["response"] : unknown : unknown : unknown;
|
|
4
4
|
export type LCUEndpointBodyType<Method extends string, Path extends string> = Path extends keyof LCUEndpoints ? Method extends keyof LCUEndpoints[Path] ? "body" extends keyof LCUEndpoints[Path][Method] ? LCUEndpoints[Path][Method]["body"] : unknown : unknown : unknown;
|
|
@@ -31,6 +31,7 @@ export default class OpenAPISchema {
|
|
|
31
31
|
if (this.components?.schemas === undefined)
|
|
32
32
|
return [];
|
|
33
33
|
return Object.entries(this.components.schemas).map(([name, schema]) => {
|
|
34
|
+
name = sanitizeTypeScriptName(name);
|
|
34
35
|
if (TYPE_OVERRIDES[name] && TYPE_OVERRIDES[name].definition)
|
|
35
36
|
return `export ${TYPE_OVERRIDES[TYPE_OVERRIDES[name].rename ?? name].definition}`.replaceAll("{{namespace}}", namespace !== undefined ? `${namespace}.` : "");
|
|
36
37
|
if ("$ref" in schema) {
|
|
@@ -111,7 +112,7 @@ function getTypeBySchemaObject(schema, namespace) {
|
|
|
111
112
|
case "object":
|
|
112
113
|
return getObjectTypeBySchemaObject(schema, namespace).split("\n").join("\n\t");
|
|
113
114
|
default:
|
|
114
|
-
return `${namespace}.${TYPE_OVERRIDES[schema.type].rename ? TYPE_OVERRIDES[schema.type].rename : schema.type}
|
|
115
|
+
return `${namespace}.${TYPE_OVERRIDES[schema.type].rename ? TYPE_OVERRIDES[schema.type].rename : schema.type}`;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
function getArrayTypeBySchemaObject(schema, namespace) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasagi/schema",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"hasagi"
|
|
6
6
|
],
|
|
7
7
|
"author": "dysolix",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@hasagi/core": "^0.
|
|
10
|
+
"@hasagi/core": "^0.6.0",
|
|
11
11
|
"axios": "^1.7.9"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|