Skip to content

Commit 9db570a

Browse files
Copilotstreamich
andcommitted
Fix test failures and formatting issues - all tests now passing
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
1 parent 2782cce commit 9db570a

15 files changed

Lines changed: 50 additions & 75 deletions

src/json-schema/converter.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {TupleType} from '../type/classes/TupleType';
1414
import type {TypeExportContext} from '../system/TypeExportContext';
1515
import type * as schema from '../schema';
1616
import type {
17-
JsonSchemaNode,
17+
JsonSchemaNode,
1818
JsonSchemaGenericKeywords,
1919
JsonSchemaAny,
2020
JsonSchemaArray,
@@ -25,7 +25,7 @@ import type {
2525
JsonSchemaObject,
2626
JsonSchemaRef,
2727
JsonSchemaOr,
28-
JsonSchemaNull
28+
JsonSchemaNull,
2929
} from './types';
3030

3131
/**
@@ -35,13 +35,13 @@ import type {
3535
function getBaseJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): JsonSchemaGenericKeywords {
3636
const typeSchema = type.getSchema();
3737
const jsonSchema: JsonSchemaGenericKeywords = {};
38-
38+
3939
if (typeSchema.title) jsonSchema.title = typeSchema.title;
4040
if (typeSchema.description) jsonSchema.description = typeSchema.description;
4141
if (typeSchema.examples) {
4242
jsonSchema.examples = typeSchema.examples.map((example: schema.TExample) => example.value);
4343
}
44-
44+
4545
return jsonSchema;
4646
}
4747

@@ -51,7 +51,7 @@ function getBaseJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): Js
5151
*/
5252
export function typeToJsonSchema(type: AbstractType<any>, ctx?: TypeExportContext): JsonSchemaNode {
5353
const typeName = type.getTypeName();
54-
54+
5555
switch (typeName) {
5656
case 'any':
5757
return anyToJsonSchema(type as AnyType, ctx);
@@ -90,10 +90,10 @@ function anyToJsonSchema(type: AnyType, ctx?: TypeExportContext): JsonSchemaAny
9090
const result: JsonSchemaAny = {
9191
type: ['string', 'number', 'boolean', 'null', 'array', 'object'] as const,
9292
};
93-
93+
9494
// Add base properties
9595
Object.assign(result, baseSchema);
96-
96+
9797
return result;
9898
}
9999

@@ -104,13 +104,13 @@ function arrayToJsonSchema(type: ArrayType<any>, ctx?: TypeExportContext): JsonS
104104
type: 'array',
105105
items: typeToJsonSchema((type as any).type, ctx),
106106
};
107-
107+
108108
// Add base properties
109109
Object.assign(result, baseSchema);
110-
110+
111111
if (schema.min !== undefined) result.minItems = schema.min;
112112
if (schema.max !== undefined) result.maxItems = schema.max;
113-
113+
114114
return result;
115115
}
116116

@@ -119,10 +119,10 @@ function binaryToJsonSchema(type: BinaryType<any>, ctx?: TypeExportContext): Jso
119119
const result: JsonSchemaBinary = {
120120
type: 'binary' as any,
121121
};
122-
122+
123123
// Add base properties
124124
Object.assign(result, baseSchema);
125-
125+
126126
return result;
127127
}
128128

@@ -131,18 +131,18 @@ function booleanToJsonSchema(type: BooleanType, ctx?: TypeExportContext): JsonSc
131131
const result: JsonSchemaBoolean = {
132132
type: 'boolean',
133133
};
134-
134+
135135
// Add base properties
136136
Object.assign(result, baseSchema);
137-
137+
138138
return result;
139139
}
140140

141141
function constToJsonSchema(type: ConstType<any>, ctx?: TypeExportContext): JsonSchemaNode {
142142
const schema = type.getSchema();
143143
const baseSchema = getBaseJsonSchema(type, ctx);
144144
const value = schema.value;
145-
145+
146146
if (typeof value === 'string') {
147147
const result: JsonSchemaString = {
148148
type: 'string',
@@ -195,7 +195,7 @@ function constToJsonSchema(type: ConstType<any>, ctx?: TypeExportContext): JsonS
195195
Object.assign(result, baseSchema);
196196
return result;
197197
}
198-
198+
199199
return baseSchema;
200200
}
201201

@@ -207,10 +207,10 @@ function mapToJsonSchema(type: MapType<any>, ctx?: TypeExportContext): JsonSchem
207207
'.*': typeToJsonSchema((type as any).type, ctx),
208208
},
209209
};
210-
210+
211211
// Add base properties
212212
Object.assign(result, baseSchema);
213-
213+
214214
return result;
215215
}
216216

@@ -220,21 +220,21 @@ function numberToJsonSchema(type: NumberType, ctx?: TypeExportContext): JsonSche
220220
const result: JsonSchemaNumber = {
221221
type: 'number',
222222
};
223-
224-
// Check if it's an integer format
223+
224+
// Check if it's an integer format
225225
const ints = new Set(['i8', 'i16', 'i32', 'u8', 'u16', 'u32']);
226226
if (schema.format && ints.has(schema.format)) {
227227
result.type = 'integer';
228228
}
229-
229+
230230
// Add base properties
231231
Object.assign(result, baseSchema);
232-
232+
233233
if (schema.gt !== undefined) result.exclusiveMinimum = schema.gt;
234234
if (schema.gte !== undefined) result.minimum = schema.gte;
235235
if (schema.lt !== undefined) result.exclusiveMaximum = schema.lt;
236236
if (schema.lte !== undefined) result.maximum = schema.lte;
237-
237+
238238
return result;
239239
}
240240

@@ -245,22 +245,22 @@ function objectToJsonSchema(type: ObjectType<any>, ctx?: TypeExportContext): Jso
245245
type: 'object',
246246
properties: {},
247247
};
248-
248+
249249
const required = [];
250250
const fields = (type as any).fields;
251251
for (const field of fields) {
252252
result.properties![field.key] = typeToJsonSchema(field.value, ctx);
253-
if (!(field.constructor.name.includes('Optional'))) {
253+
if (!field.constructor.name.includes('Optional')) {
254254
required.push(field.key);
255255
}
256256
}
257-
257+
258258
if (required.length) result.required = required;
259259
if (schema.unknownFields === false) result.additionalProperties = false;
260-
260+
261261
// Add base properties
262262
Object.assign(result, baseSchema);
263-
263+
264264
return result;
265265
}
266266

@@ -270,27 +270,27 @@ function orToJsonSchema(type: OrType<any>, ctx?: TypeExportContext): JsonSchemaO
270270
const result: JsonSchemaOr = {
271271
anyOf: types.map((t: any) => typeToJsonSchema(t, ctx)),
272272
};
273-
273+
274274
// Add base properties
275275
Object.assign(result, baseSchema);
276-
276+
277277
return result;
278278
}
279279

280280
function refToJsonSchema(type: RefType<any>, ctx?: TypeExportContext): JsonSchemaRef {
281281
const schema = type.getSchema();
282282
const baseSchema = getBaseJsonSchema(type, ctx);
283283
const ref = schema.ref;
284-
284+
285285
if (ctx) ctx.mentionRef(ref);
286-
286+
287287
const result: JsonSchemaRef = {
288288
$ref: `#/$defs/${ref}`,
289289
};
290-
290+
291291
// Add base properties
292292
Object.assign(result, baseSchema);
293-
293+
294294
return result;
295295
}
296296

@@ -300,10 +300,10 @@ function stringToJsonSchema(type: StringType, ctx?: TypeExportContext): JsonSche
300300
const result: JsonSchemaString = {
301301
type: 'string',
302302
};
303-
303+
304304
if (schema.min !== undefined) result.minLength = schema.min;
305305
if (schema.max !== undefined) result.maxLength = schema.max;
306-
306+
307307
// Add format to JSON Schema if specified
308308
if (schema.format) {
309309
if (schema.format === 'ascii') {
@@ -316,10 +316,10 @@ function stringToJsonSchema(type: StringType, ctx?: TypeExportContext): JsonSche
316316
// Backward compatibility: if ascii=true, add pattern
317317
result.pattern = '^[\\x00-\\x7F]*$';
318318
}
319-
319+
320320
// Add base properties
321321
Object.assign(result, baseSchema);
322-
322+
323323
return result;
324324
}
325325

@@ -331,9 +331,9 @@ function tupleToJsonSchema(type: TupleType<any>, ctx?: TypeExportContext): JsonS
331331
items: false,
332332
prefixItems: types.map((t: any) => typeToJsonSchema(t, ctx)),
333333
};
334-
334+
335335
// Add base properties
336336
Object.assign(result, baseSchema);
337-
337+
338338
return result;
339-
}
339+
}

src/type/classes/AbstractType.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ export abstract class AbstractType<S extends schema.Schema> implements BaseType<
8080
}
8181

8282
public toJsonSchema(ctx?: TypeExportContext): jsonSchema.JsonSchemaNode {
83-
const {typeToJsonSchema} = require('../../json-schema');
84-
return typeToJsonSchema(this, ctx);
83+
// Use dynamic import to avoid circular dependency
84+
const converter = require('../../json-schema/converter');
85+
return converter.typeToJsonSchema(this, ctx);
8586
}
8687

87-
88-
8988
public options(options: schema.Optional<S>): this {
9089
Object.assign(this.schema, options);
9190
return this;

src/type/classes/AnyType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export class AnyType extends AbstractType<schema.AnySchema> {
2323
super();
2424
}
2525

26-
27-
2826
public validateSchema(): void {
2927
validateTType(this.getSchema(), 'any');
3028
}

src/type/classes/ArrayType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ export class ArrayType<T extends Type> extends AbstractType<schema.ArraySchema<S
4242
};
4343
}
4444

45-
46-
4745
public getOptions(): schema.Optional<schema.ArraySchema<SchemaOf<T>>> {
4846
const {kind, type, ...options} = this.schema;
4947
return options as any;

src/type/classes/BinaryType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ export class BinaryType<T extends Type> extends AbstractType<schema.BinarySchema
5252
};
5353
}
5454

55-
56-
5755
public getOptions(): schema.Optional<schema.ArraySchema<SchemaOf<T>>> {
5856
const {kind, type, ...options} = this.schema;
5957
return options as any;

src/type/classes/BooleanType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ export class BooleanType extends AbstractType<schema.BooleanSchema> {
2626
super();
2727
}
2828

29-
30-
3129
public validateSchema(): void {
3230
validateTType(this.getSchema(), 'bool');
3331
}

src/type/classes/ConstType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export class ConstType<V = any> extends AbstractType<schema.ConstSchema<V>> {
3434
return this.schema.value;
3535
}
3636

37-
38-
3937
public getOptions(): schema.Optional<schema.ConstSchema<V>> {
4038
const {kind, value, ...options} = this.schema;
4139
return options as any;

src/type/classes/MapType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export class MapType<T extends Type> extends AbstractType<schema.MapSchema<Schem
4141
};
4242
}
4343

44-
45-
4644
public getOptions(): schema.Optional<schema.MapSchema<SchemaOf<T>>> {
4745
const {kind, type, ...options} = this.schema;
4846
return options as any;

src/type/classes/NumberType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ export class NumberType extends AbstractType<schema.NumberSchema> {
2626
super();
2727
}
2828

29-
30-
3129
public validateSchema(): void {
3230
const schema = this.getSchema();
3331
validateTType(schema, 'num');

src/type/classes/ObjectType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ export class ObjectType<F extends ObjectFieldType<any, any>[] = ObjectFieldType<
112112
};
113113
}
114114

115-
116-
117115
public getOptions(): schema.Optional<schema.ObjectSchema<SchemaOfObjectFields<F>>> {
118116
const {kind, fields, ...options} = this.schema;
119117
return options as any;

0 commit comments

Comments
 (0)