Skip to content

Commit 5b068f7

Browse files
committed
Support oneOf spec definitions in modelTest
1 parent a08a675 commit 5b068f7

13 files changed

Lines changed: 245 additions & 17 deletions

File tree

snapshotTests/snapshot/example/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class RedirectedError extends HttpError {
174174

175175
export interface SecurityScheme {
176176
headers(): Record<string, string>;
177-
}
177+
}

snapshotTests/snapshot/example/test/modelTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export class TestSampleData {
112112
return this.random.pickOne(options);
113113
}
114114

115+
pickOneString<T extends string>(options: Array<T>): T {
116+
return this.random.pickOne(options);
117+
}
118+
115119
pickSome<T>(options: Array<T>): T[] {
116120
return this.random.pickSome(options);
117121
}
@@ -200,6 +204,10 @@ export class TestSampleData {
200204
return Array.from({ length: length || this.arrayLength() }).map(() => this.sampleString());
201205
}
202206

207+
sampleArrayArray<T>(length?: number): Array<Array<T>> {
208+
return [];
209+
}
210+
203211
sampleArraynumber(length?: number): Array<number> {
204212
return Array.from({ length: length || this.arrayLength() }).map(() => this.samplenumber());
205213
}

snapshotTests/snapshot/infectionTracker/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class RedirectedError extends HttpError {
174174

175175
export interface SecurityScheme {
176176
headers(): Record<string, string>;
177-
}
177+
}

snapshotTests/snapshot/infectionTracker/test/modelTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ export class TestSampleData {
123123
return this.random.pickOne(options);
124124
}
125125

126+
pickOneString<T extends string>(options: Array<T>): T {
127+
return this.random.pickOne(options);
128+
}
129+
126130
pickSome<T>(options: Array<T>): T[] {
127131
return this.random.pickSome(options);
128132
}
@@ -211,6 +215,10 @@ export class TestSampleData {
211215
return Array.from({ length: length || this.arrayLength() }).map(() => this.sampleString());
212216
}
213217

218+
sampleArrayArray<T>(length?: number): Array<Array<T>> {
219+
return [];
220+
}
221+
214222
sampleArraynumber(length?: number): Array<number> {
215223
return Array.from({ length: length || this.arrayLength() }).map(() => this.samplenumber());
216224
}

snapshotTests/snapshot/petstore/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class RedirectedError extends HttpError {
174174

175175
export interface SecurityScheme {
176176
headers(): Record<string, string>;
177-
}
177+
}

snapshotTests/snapshot/petstore/test/modelTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export class TestSampleData {
124124
return this.random.pickOne(options);
125125
}
126126

127+
pickOneString<T extends string>(options: Array<T>): T {
128+
return this.random.pickOne(options);
129+
}
130+
127131
pickSome<T>(options: Array<T>): T[] {
128132
return this.random.pickSome(options);
129133
}
@@ -212,6 +216,10 @@ export class TestSampleData {
212216
return Array.from({ length: length || this.arrayLength() }).map(() => this.sampleString());
213217
}
214218

219+
sampleArrayArray<T>(length?: number): Array<Array<T>> {
220+
return [];
221+
}
222+
215223
sampleArraynumber(length?: number): Array<number> {
216224
return Array.from({ length: length || this.arrayLength() }).map(() => this.samplenumber());
217225
}

snapshotTests/snapshot/poly/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class RedirectedError extends HttpError {
174174

175175
export interface SecurityScheme {
176176
headers(): Record<string, string>;
177-
}
177+
}

snapshotTests/snapshot/poly/test/modelTest.ts

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export class TestSampleData {
128128
return this.random.pickOne(options);
129129
}
130130

131+
pickOneString<T extends string>(options: Array<T>): T {
132+
return this.random.pickOne(options);
133+
}
134+
131135
pickSome<T>(options: Array<T>): T[] {
132136
return this.random.pickSome(options);
133137
}
@@ -216,6 +220,10 @@ export class TestSampleData {
216220
return Array.from({ length: length || this.arrayLength() }).map(() => this.sampleString());
217221
}
218222

223+
sampleArrayArray<T>(length?: number): Array<Array<T>> {
224+
return [];
225+
}
226+
219227
sampleArraynumber(length?: number): Array<number> {
220228
return Array.from({ length: length || this.arrayLength() }).map(() => this.samplenumber());
221229
}
@@ -256,6 +264,14 @@ export class TestSampleData {
256264
// eslint-disable-next-line @typescript-eslint/no-explicit-any
257265
sample(modelName: string): any {
258266
switch (modelName) {
267+
case "AnyPartyDto":
268+
return this.sampleAnyPartyDto();
269+
case "Array<AnyPartyDto>":
270+
return this.sampleArrayAnyPartyDto();
271+
case "CreationErrorDto":
272+
return this.sampleCreationErrorDto();
273+
case "Array<CreationErrorDto>":
274+
return this.sampleArrayCreationErrorDto();
259275
case "DuplicateIdentifierErrorDto":
260276
return this.sampleDuplicateIdentifierErrorDto();
261277
case "Array<DuplicateIdentifierErrorDto>":
@@ -280,11 +296,84 @@ export class TestSampleData {
280296
return this.samplePersonDto();
281297
case "Array<PersonDto>":
282298
return this.sampleArrayPersonDto();
299+
case "UpdateErrorDto":
300+
return this.sampleUpdateErrorDto();
301+
case "Array<UpdateErrorDto>":
302+
return this.sampleArrayUpdateErrorDto();
283303
default:
284304
throw new Error("Unknown type " + modelName);
285305
}
286306
}
287307

308+
sampleAnyPartyDto(
309+
template?: Factory<OrganizationDto & PersonDto>
310+
): AnyPartyDto {
311+
const containerClass = "AnyPartyDto";
312+
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {
313+
return this.sampleModelProperties[containerClass](this);
314+
}
315+
const type = this.pickOneString(["organization", "person"])
316+
switch (type) {
317+
case "organization":
318+
return {
319+
...this.sampleOrganizationDto(template),
320+
type
321+
};
322+
case "person":
323+
return {
324+
...this.samplePersonDto(template),
325+
type
326+
};
327+
}
328+
}
329+
330+
sampleArrayAnyPartyDto(
331+
template: Factory<OrganizationDto & PersonDto> = {},
332+
length?: number
333+
): Array<AnyPartyDto> {
334+
return this.randomArray(
335+
() => this.sampleAnyPartyDto(template),
336+
length ?? this.arrayLength()
337+
);
338+
}
339+
340+
sampleCreationErrorDto(
341+
template?: Factory<IllegalEmailAddressErrorDto & DuplicateIdentifierErrorDto & GeneralErrorDto>
342+
): CreationErrorDto {
343+
const containerClass = "CreationErrorDto";
344+
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {
345+
return this.sampleModelProperties[containerClass](this);
346+
}
347+
const code = this.pickOneString(["IllegalEmailAddressError", "DuplicateIdentifierError", "GeneralError"])
348+
switch (code) {
349+
case "IllegalEmailAddressError":
350+
return {
351+
...this.sampleIllegalEmailAddressErrorDto(template),
352+
code
353+
};
354+
case "DuplicateIdentifierError":
355+
return {
356+
...this.sampleDuplicateIdentifierErrorDto(template),
357+
code
358+
};
359+
case "GeneralError":
360+
return {
361+
...this.sampleGeneralErrorDto(template),
362+
code
363+
};
364+
}
365+
}
366+
367+
sampleArrayCreationErrorDto(
368+
template: Factory<IllegalEmailAddressErrorDto & DuplicateIdentifierErrorDto & GeneralErrorDto> = {},
369+
length?: number
370+
): Array<CreationErrorDto> {
371+
return this.randomArray(
372+
() => this.sampleCreationErrorDto(template),
373+
length ?? this.arrayLength()
374+
);
375+
}
376+
288377
sampleDuplicateIdentifierErrorDto(template?: Factory<DuplicateIdentifierErrorDto>): DuplicateIdentifierErrorDto {
289378
const containerClass = "DuplicateIdentifierErrorDto";
290379
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {
@@ -528,4 +617,46 @@ export class TestSampleData {
528617
length ?? this.arrayLength()
529618
);
530619
}
620+
621+
sampleUpdateErrorDto(
622+
template?: Factory<IllegalEmailAddressErrorDto & DuplicateIdentifierErrorDto & GeneralErrorDto & NotFoundErrorDto>
623+
): UpdateErrorDto {
624+
const containerClass = "UpdateErrorDto";
625+
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {
626+
return this.sampleModelProperties[containerClass](this);
627+
}
628+
const code = this.pickOneString(["IllegalEmailAddressError", "DuplicateIdentifierError", "GeneralError", "NotFoundError"])
629+
switch (code) {
630+
case "IllegalEmailAddressError":
631+
return {
632+
...this.sampleIllegalEmailAddressErrorDto(template),
633+
code
634+
};
635+
case "DuplicateIdentifierError":
636+
return {
637+
...this.sampleDuplicateIdentifierErrorDto(template),
638+
code
639+
};
640+
case "GeneralError":
641+
return {
642+
...this.sampleGeneralErrorDto(template),
643+
code
644+
};
645+
case "NotFoundError":
646+
return {
647+
...this.sampleNotFoundErrorDto(template),
648+
code
649+
};
650+
}
651+
}
652+
653+
sampleArrayUpdateErrorDto(
654+
template: Factory<IllegalEmailAddressErrorDto & DuplicateIdentifierErrorDto & GeneralErrorDto & NotFoundErrorDto> = {},
655+
length?: number
656+
): Array<UpdateErrorDto> {
657+
return this.randomArray(
658+
() => this.sampleUpdateErrorDto(template),
659+
length ?? this.arrayLength()
660+
);
661+
}
531662
}

snapshotTests/snapshot/typeHierarchy/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class RedirectedError extends HttpError {
174174

175175
export interface SecurityScheme {
176176
headers(): Record<string, string>;
177-
}
177+
}

snapshotTests/snapshot/typeHierarchy/test/modelTest.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export class TestSampleData {
126126
return this.random.pickOne(options);
127127
}
128128

129+
pickOneString<T extends string>(options: Array<T>): T {
130+
return this.random.pickOne(options);
131+
}
132+
129133
pickSome<T>(options: Array<T>): T[] {
130134
return this.random.pickSome(options);
131135
}
@@ -214,6 +218,10 @@ export class TestSampleData {
214218
return Array.from({ length: length || this.arrayLength() }).map(() => this.sampleString());
215219
}
216220

221+
sampleArrayArray<T>(length?: number): Array<Array<T>> {
222+
return [];
223+
}
224+
217225
sampleArraynumber(length?: number): Array<number> {
218226
return Array.from({ length: length || this.arrayLength() }).map(() => this.samplenumber());
219227
}
@@ -254,6 +262,10 @@ export class TestSampleData {
254262
// eslint-disable-next-line @typescript-eslint/no-explicit-any
255263
sample(modelName: string): any {
256264
switch (modelName) {
265+
case "AnyPetDto":
266+
return this.sampleAnyPetDto();
267+
case "Array<AnyPetDto>":
268+
return this.sampleArrayAnyPetDto();
257269
case "CatAllOfDto":
258270
return this.sampleCatAllOfDto();
259271
case "Array<CatAllOfDto>":
@@ -279,6 +291,38 @@ export class TestSampleData {
279291
}
280292
}
281293

294+
sampleAnyPetDto(
295+
template?: Factory<CatDto & DogDto>
296+
): AnyPetDto {
297+
const containerClass = "AnyPetDto";
298+
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {
299+
return this.sampleModelProperties[containerClass](this);
300+
}
301+
const pet_type = this.pickOneString(["Cat", "Dog"])
302+
switch (pet_type) {
303+
case "Cat":
304+
return {
305+
...this.sampleCatDto(template),
306+
pet_type
307+
};
308+
case "Dog":
309+
return {
310+
...this.sampleDogDto(template),
311+
pet_type
312+
};
313+
}
314+
}
315+
316+
sampleArrayAnyPetDto(
317+
template: Factory<CatDto & DogDto> = {},
318+
length?: number
319+
): Array<AnyPetDto> {
320+
return this.randomArray(
321+
() => this.sampleAnyPetDto(template),
322+
length ?? this.arrayLength()
323+
);
324+
}
325+
282326
sampleCatAllOfDto(template?: Factory<CatAllOfDto>): CatAllOfDto {
283327
const containerClass = "CatAllOfDto";
284328
if (!template && typeof this.sampleModelProperties[containerClass] === "function") {

0 commit comments

Comments
 (0)