@hasagi/schema 0.6.2 → 0.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.
@@ -50,7 +50,7 @@ function getType(input) {
50
50
  case "object":
51
51
  return { type: "object", additionalProperties: true };
52
52
  case "":
53
- return { type: "object", additionalProperties: true };
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
- const type = getType(arg);
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, getTypeScriptName } 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 = getTypeScriptName(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}` ?? "unknown";
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/overrides.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Endpoint } from "./get-extended-help.js";
2
2
  export declare const EXTENDED_HELP_FUNCTION_OVERRIDES: Record<string, Partial<Endpoint>>;
3
+ export declare const TYPESCRIPT_TYPE_NAME_OVERRIDES: Record<string, string>;
package/overrides.js CHANGED
@@ -59,3 +59,8 @@ export const EXTENDED_HELP_FUNCTION_OVERRIDES = {
59
59
  tags: ["riotclient"]
60
60
  }
61
61
  };
62
+ export const TYPESCRIPT_TYPE_NAME_OVERRIDES = {
63
+ "LolMissionsCapMissionSeries": "LolMissionsCAPMissionSeries",
64
+ "LolObjectivesCapMissionSeries": "LolObjectivesCAPMissionSeries",
65
+ "LolTftEventCapMissionSeries": "LolTftEventCAPMissionSeries"
66
+ };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@hasagi/schema",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "keywords": [
5
5
  "hasagi"
6
6
  ],
7
7
  "author": "dysolix",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "@hasagi/core": "^0.5.12",
10
+ "@hasagi/core": "^0.6.3",
11
11
  "axios": "^1.7.9"
12
12
  },
13
13
  "exports": {
package/util.d.ts CHANGED
@@ -5,4 +5,4 @@ export declare function getType(t: {
5
5
  elementType: string;
6
6
  } | string, namespace?: string): string;
7
7
  export declare function formatForArrayLabel(str: string): string;
8
- export declare function sanitizeTypeScriptName(input: string): string;
8
+ export declare function getTypeScriptName(input: string): string;
package/util.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from "fs/promises";
2
+ import { TYPESCRIPT_TYPE_NAME_OVERRIDES } from "./overrides";
2
3
  function requiresQuotes(fieldName) {
3
4
  return fieldName.includes("-") || /\d/.test(fieldName);
4
5
  }
@@ -48,6 +49,9 @@ export function formatForArrayLabel(str) {
48
49
  function kebabCaseToCamelCase(str) {
49
50
  return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
50
51
  }
51
- export function sanitizeTypeScriptName(input) {
52
- return input.replaceAll("-", "_");
52
+ export function getTypeScriptName(input) {
53
+ input = input.replaceAll("-", "_");
54
+ if (TYPESCRIPT_TYPE_NAME_OVERRIDES[input])
55
+ input = TYPESCRIPT_TYPE_NAME_OVERRIDES[input];
56
+ return input;
53
57
  }