Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 8a7ed6d

Browse files
committed
Adds validateToBoxed to AnyTypeSchema
1 parent c6d357b commit 8a7ed6d

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/schemas/AnyTypeJsonSchema.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,60 @@ public String validate(UUID arg, SchemaConfiguration configuration) throws Valid
221221
}
222222
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
223223
}
224+
225+
public static abstract sealed class AnyTypeBoxed permits AnyTypeBoxedVoid, AnyTypeBoxedBoolean, AnyTypeBoxedNumber, AnyTypeBoxedString, AnyTypeBoxedList, AnyTypeBoxedMap {
226+
}
227+
public static final class AnyTypeBoxedVoid extends AnyTypeBoxed {
228+
public final Void data;
229+
private AnyTypeBoxedVoid(Void data) {
230+
this.data = data;
231+
}
232+
}
233+
public static final class AnyTypeBoxedBoolean extends AnyTypeBoxed {
234+
public final boolean data;
235+
private AnyTypeBoxedBoolean(boolean data) {
236+
this.data = data;
237+
}
238+
}
239+
public static final class AnyTypeBoxedNumber extends AnyTypeBoxed {
240+
public final Number data;
241+
private AnyTypeBoxedNumber(Number data) {
242+
this.data = data;
243+
}
244+
}
245+
public static final class AnyTypeBoxedString extends AnyTypeBoxed {
246+
public final String data;
247+
private AnyTypeBoxedString(String data) {
248+
this.data = data;
249+
}
250+
}
251+
public static final class AnyTypeBoxedList extends AnyTypeBoxed {
252+
public final FrozenList<@Nullable Object> data;
253+
private AnyTypeBoxedList(FrozenList<@Nullable Object> data) {
254+
this.data = data;
255+
}
256+
}
257+
public static final class AnyTypeBoxedMap extends AnyTypeBoxed {
258+
public final FrozenMap<@Nullable Object> data;
259+
private AnyTypeBoxedMap(FrozenMap<@Nullable Object> data) {
260+
this.data = data;
261+
}
262+
}
263+
public AnyTypeBoxed validateToBoxed(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
264+
if (arg == null) {
265+
return new AnyTypeBoxedVoid(validate((Void) null, configuration));
266+
} else if (arg instanceof Boolean) {
267+
boolean boolArg = (Boolean) arg;
268+
return new AnyTypeBoxedBoolean(validate(boolArg, configuration));
269+
} else if (arg instanceof Number) {
270+
return new AnyTypeBoxedNumber(validate((Number) arg, configuration));
271+
} else if (arg instanceof String) {
272+
return new AnyTypeBoxedString(validate((String) arg, configuration));
273+
} else if (arg instanceof List) {
274+
return new AnyTypeBoxedList(validate((List<?>) arg, configuration));
275+
} else if (arg instanceof Map) {
276+
return new AnyTypeBoxedMap(validate((Map<?, ?>) arg, configuration));
277+
}
278+
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
279+
}
224280
}

src/main/resources/java/src/main/java/packagename/schemas/AnyTypeJsonSchema.hbs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,60 @@ public class AnyTypeJsonSchema extends JsonSchema implements NullSchemaValidator
221221
}
222222
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
223223
}
224+
225+
public static abstract sealed class AnyTypeBoxed permits AnyTypeBoxedVoid, AnyTypeBoxedBoolean, AnyTypeBoxedNumber, AnyTypeBoxedString, AnyTypeBoxedList, AnyTypeBoxedMap {
226+
}
227+
public static final class AnyTypeBoxedVoid extends AnyTypeBoxed {
228+
public final Void data;
229+
private AnyTypeBoxedVoid(Void data) {
230+
this.data = data;
231+
}
232+
}
233+
public static final class AnyTypeBoxedBoolean extends AnyTypeBoxed {
234+
public final boolean data;
235+
private AnyTypeBoxedBoolean(boolean data) {
236+
this.data = data;
237+
}
238+
}
239+
public static final class AnyTypeBoxedNumber extends AnyTypeBoxed {
240+
public final Number data;
241+
private AnyTypeBoxedNumber(Number data) {
242+
this.data = data;
243+
}
244+
}
245+
public static final class AnyTypeBoxedString extends AnyTypeBoxed {
246+
public final String data;
247+
private AnyTypeBoxedString(String data) {
248+
this.data = data;
249+
}
250+
}
251+
public static final class AnyTypeBoxedList extends AnyTypeBoxed {
252+
public final FrozenList<@Nullable Object> data;
253+
private AnyTypeBoxedList(FrozenList<@Nullable Object> data) {
254+
this.data = data;
255+
}
256+
}
257+
public static final class AnyTypeBoxedMap extends AnyTypeBoxed {
258+
public final FrozenMap<@Nullable Object> data;
259+
private AnyTypeBoxedMap(FrozenMap<@Nullable Object> data) {
260+
this.data = data;
261+
}
262+
}
263+
public AnyTypeBoxed validateToBoxed(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
264+
if (arg == null) {
265+
return new AnyTypeBoxedVoid(validate((Void) null, configuration));
266+
} else if (arg instanceof Boolean) {
267+
boolean boolArg = (Boolean) arg;
268+
return new AnyTypeBoxedBoolean(validate(boolArg, configuration));
269+
} else if (arg instanceof Number) {
270+
return new AnyTypeBoxedNumber(validate((Number) arg, configuration));
271+
} else if (arg instanceof String) {
272+
return new AnyTypeBoxedString(validate((String) arg, configuration));
273+
} else if (arg instanceof List) {
274+
return new AnyTypeBoxedList(validate((List<?>) arg, configuration));
275+
} else if (arg instanceof Map) {
276+
return new AnyTypeBoxedMap(validate((Map<?, ?>) arg, configuration));
277+
}
278+
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
279+
}
224280
}

0 commit comments

Comments
 (0)