svelte-reflector 1.0.12 → 1.0.13

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/schema.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare class Schema {
6
6
  type: string;
7
7
  schema: string;
8
8
  enums: Set<string>;
9
+ objects: Map<string, string>;
9
10
  constructor(params: {
10
11
  properties: Record<string, SchemaObject | ReferenceObject>;
11
12
  name: string;
package/dist/schema.js CHANGED
@@ -5,12 +5,19 @@ export class Schema {
5
5
  type;
6
6
  schema;
7
7
  enums = new Set();
8
+ objects = new Map();
8
9
  constructor(params) {
9
10
  const { name, properties, requireds, isEmpty } = params;
10
11
  this.name = `${isEmpty ? "Empty" : ""}${name}`;
11
12
  for (const [key, value] of Object.entries(properties)) {
12
- if ("$ref" in value || !value?.type)
13
+ if ("$ref" in value || !value?.type) {
14
+ if ("$ref" in value) {
15
+ const teste = value.$ref;
16
+ const object = teste.split("/").at(-1);
17
+ this.objects.set(key, `${object}Schema`);
18
+ }
13
19
  continue;
20
+ }
14
21
  const required = requireds.includes(key);
15
22
  const teste = value.items;
16
23
  if (teste && !("$ref" in teste) && teste.enum) {
@@ -35,6 +42,10 @@ export class Schema {
35
42
  ${this.properties.map((p) => {
36
43
  return p.buildedProp;
37
44
  })}
45
+ ${this.properties.length > 0 ? "," : ""}
46
+ ${Array.from(this.objects).map(([k, v]) => {
47
+ return `${k}: z.object(${v})`;
48
+ })}
38
49
  });`;
39
50
  }
40
51
  getEnumConst(params) {
@@ -1,4 +1,4 @@
1
- import { sanitizeNumber, splitByUppercase, treatenEnum } from "./helpers/helpers.js";
1
+ import { sanitizeNumber, treatenEnum } from "./helpers/helpers.js";
2
2
  import { ReflectorInput } from "./helpers/input.js";
3
3
  import {} from "./types/open-api-spec.interface.js";
4
4
  import {} from "./types/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",