@hasagi/schema 0.6.5 → 0.6.6

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.
@@ -1,4 +1,5 @@
1
1
  import { HasagiClient as HasagiLiteClient } from "@hasagi/core";
2
+ import { getSwaggerTypeName } from "../util.js";
2
3
  function getRootType(input) {
3
4
  const isObject = input.fields.length > 0;
4
5
  const isEnum = input.values.length > 0;
@@ -52,7 +53,7 @@ function getType(input) {
52
53
  case "":
53
54
  return undefined; //
54
55
  default:
55
- return { $ref: `#/components/schemas/${type}` };
56
+ return { $ref: `#/components/schemas/${getSwaggerTypeName(type)}` };
56
57
  }
57
58
  }
58
59
  export async function generateOpenAPIv3(schema) {
@@ -184,7 +185,7 @@ function endpointToOperation(endpoint, schema) {
184
185
  parameters.push({
185
186
  in: "query",
186
187
  name: arg.name,
187
- schema: getType(arg),
188
+ schema: getType(arg) ?? { type: "string" },
188
189
  required: !arg.optional
189
190
  });
190
191
  });
@@ -214,7 +215,7 @@ function endpointToOperation(endpoint, schema) {
214
215
  in: "query",
215
216
  required: !arg.optional,
216
217
  name: arg.name,
217
- schema: getType(arg)
218
+ schema: getType(arg) ?? { type: "string" }
218
219
  };
219
220
  }
220
221
  });
@@ -233,6 +234,14 @@ function endpointToOperation(endpoint, schema) {
233
234
  }
234
235
  const returnType = getType({ type: endpoint.returns });
235
236
  response = returnType !== undefined ? { content: { "application/json": { schema: returnType } }, description: "Success response" } : { description: "Success response" };
237
+ // Ensure GET endpoints have "content" set to comply with Swagger schema rules
238
+ if (endpoint.method === "GET" && !response.content) {
239
+ response.content = {
240
+ "application/json": {
241
+ schema: {}
242
+ }
243
+ };
244
+ }
236
245
  const tags = [];
237
246
  if (endpoint.path?.startsWith("/lol-"))
238
247
  tags.push("Plugin " + endpoint.path.split("/")[1]);
@@ -112,7 +112,7 @@ function getTypeBySchemaObject(schema, namespace) {
112
112
  case "object":
113
113
  return getObjectTypeBySchemaObject(schema, namespace).split("\n").join("\n\t");
114
114
  default:
115
- 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}`;
116
116
  }
117
117
  }
118
118
  function getArrayTypeBySchemaObject(schema, namespace) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasagi/schema",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "keywords": [
5
5
  "hasagi"
6
6
  ],
package/util.d.ts CHANGED
@@ -6,3 +6,4 @@ export declare function getType(t: {
6
6
  } | string, namespace?: string): string;
7
7
  export declare function formatForArrayLabel(str: string): string;
8
8
  export declare function getTypeScriptName(input: string): string;
9
+ export declare function getSwaggerTypeName(input: string): string;
package/util.js CHANGED
@@ -55,3 +55,8 @@ export function getTypeScriptName(input) {
55
55
  input = TYPESCRIPT_TYPE_NAME_OVERRIDES[input];
56
56
  return input;
57
57
  }
58
+ export function getSwaggerTypeName(input) {
59
+ if (TYPESCRIPT_TYPE_NAME_OVERRIDES[input])
60
+ input = TYPESCRIPT_TYPE_NAME_OVERRIDES[input];
61
+ return input;
62
+ }