1- package org.openapijsonschematools.client.schemas ;
1+ package org.openapijsonschematools.client.schemas
22
3- import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
4- import org.openapijsonschematools.client.exceptions.ValidationException;
5- import org.openapijsonschematools.client.schemas.validation.JsonSchema;
6- import org.openapijsonschematools.client.schemas.validation.JsonSchemaInfo;
7- import org.openapijsonschematools.client.configurations.SchemaConfiguration;
8- import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap;
9- import org.openapijsonschematools.client.schemas.validation.NumberSchemaValidator;
10- import org.openapijsonschematools.client.schemas.validation.ValidationMetadata;
11- import org.checkerframework.checker.nullness.qual.Nullable;
3+ import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags
4+ import org.openapijsonschematools.client.configurations.SchemaConfiguration
5+ import org.openapijsonschematools.client.exceptions.ValidationException
6+ import org.openapijsonschematools.client.schemas.validation.JsonSchema
7+ import org.openapijsonschematools.client.schemas.validation.JsonSchemaInfo
8+ import org.openapijsonschematools.client.schemas.validation.NumberSchemaValidator
9+ import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap
10+ import org.openapijsonschematools.client.schemas.validation.ValidationMetadata
1211
13- import java.util.HashSet;
14- import java.util.LinkedHashSet;
15- import java.util.List;
16- import java.util.Objects;
17- import java.util.Set;
18-
19- public class Int32JsonSchema {
20- public sealed interface Int32JsonSchema1Boxed permits Int32JsonSchema1BoxedNumber {
21- @Nullable Object getData();
12+ class Int32JsonSchema {
13+ sealed interface Int32JsonSchema1Boxed {
14+ fun getData (): Any?
2215 }
23- public record Int32JsonSchema1BoxedNumber ( Number data) implements Int32JsonSchema1Boxed {
24- @Override
25- public @Nullable Object getData() {
26- return data;
16+
17+ data class Int32JsonSchema1BoxedNumber ( val data : Number ) : Int32JsonSchema1Boxed {
18+ override fun getData (): Number {
19+ return data
2720 }
2821 }
2922
30- public static class Int32JsonSchema1 extends JsonSchema <Int32JsonSchema1Boxed > implements NumberSchemaValidator <Int32JsonSchema1BoxedNumber > {
31- private static @Nullable Int32JsonSchema1 instance = null ;
32-
33- protected Int32JsonSchema1 () {
34- super (new JsonSchemaInfo ()
35- .type(Set .of(
36- Integer .class ,
37- Float .class
38- ))
39- .format(" int32" )
40- );
23+ class Int32JsonSchema1 private constructor() : JsonSchema<Int32JsonSchema1Boxed>(
24+ JsonSchemaInfo ()
25+ .type(
26+ setOf(
27+ Int ::class.java,
28+ Float ::class.java
29+ )
30+ )
31+ .format("int32")
32+ ), NumberSchemaValidator<Int32JsonSchema1BoxedNumber> {
33+ @Throws(ValidationException ::class )
34+ override fun validate (arg : Number , configuration : SchemaConfiguration ? ): Number {
35+ val pathSet: MutableSet <List <Any >> = HashSet ()
36+ val pathToItem = listOf<Any >(" args[0" )
37+ val castArg: Number = castToAllowedTypes(arg, pathToItem, pathSet)
38+ val usedConfiguration = configuration ? : SchemaConfiguration (JsonSchemaKeywordFlags .Builder ().build())
39+ val validationMetadata =
40+ ValidationMetadata (pathToItem, usedConfiguration, PathToSchemasMap (), LinkedHashSet ())
41+ val pathToSchemasMap = getPathToSchemas(this , castArg, validationMetadata, pathSet)
42+ return getNewInstance(castArg, validationMetadata.pathToItem, pathToSchemasMap)
4143 }
4244
43- public static Int32JsonSchema1 getInstance() {
44- if (instance == null ) {
45- instance = new Int32JsonSchema1 ();
46- }
47- return instance;
45+ @Throws(ValidationException ::class )
46+ fun validate (arg : Int , configuration : SchemaConfiguration ? ): Int {
47+ return validate(arg as Number , configuration) as Int
4848 }
4949
50- @Override
51- public Number validate(Number arg, SchemaConfiguration configuration) throws ValidationException {
52- Set <List <Object >> pathSet = new HashSet <> ();
53- List <Object > pathToItem = List .of(" args[0" );
54- Number castArg = castToAllowedTypes(arg, pathToItem, pathSet);
55- SchemaConfiguration usedConfiguration = Objects .requireNonNullElseGet(configuration, () -> new SchemaConfiguration (new JsonSchemaKeywordFlags .Builder ().build()));
56- ValidationMetadata validationMetadata = new ValidationMetadata (pathToItem, usedConfiguration, new PathToSchemasMap (), new LinkedHashSet <> ());
57- PathToSchemasMap pathToSchemasMap = getPathToSchemas(this , castArg, validationMetadata, pathSet);
58- return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap);
50+ @Throws(ValidationException ::class )
51+ fun validate (arg : Float , configuration : SchemaConfiguration ? ): Float {
52+ return validate(arg as Number , configuration) as Float
5953 }
6054
61- public int validate(int arg, SchemaConfiguration configuration) throws ValidationException {
62- return (int) validate((Number ) arg, configuration);
55+ override fun getNewInstance (arg : Any? , pathToItem : List <Any >, pathToSchemas : PathToSchemasMap ): Any? {
56+ if (arg is Number ) {
57+ return getNewInstance(arg as Number ? , pathToItem, pathToSchemas)
58+ }
59+ throw RuntimeException (" Invalid input type=$javaClass . It can't be instantiated by this schema" )
6360 }
6461
65- public float validate(float arg, SchemaConfiguration configuration) throws ValidationException {
66- return (float) validate((Number ) arg, configuration);
62+ @Throws(ValidationException ::class )
63+ override fun validate (arg : Any? , configuration : SchemaConfiguration ? ): Number {
64+ if (arg is Number ) {
65+ return validate(arg, configuration)
66+ }
67+ throw ValidationException (" Invalid input type=$javaClass . It can't be validated by this schema" )
6768 }
6869
69- @Override
70- public @Nullable Object getNewInstance(@Nullable Object arg, List <Object > pathToItem, PathToSchemasMap pathToSchemas) {
71- if (arg instanceof Number ) {
72- return getNewInstance((Number ) arg, pathToItem, pathToSchemas);
73- }
74- throw new RuntimeException (" Invalid input type=" + getClass(arg)+ " . It can't be instantiated by this schema" );
70+ @Throws(ValidationException ::class )
71+ override fun validateAndBox (arg : Number , configuration : SchemaConfiguration ? ): Int32JsonSchema1BoxedNumber {
72+ return Int32JsonSchema1BoxedNumber (validate(arg, configuration))
7573 }
7674
77- @Override
78- public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
79- if (arg instanceof Number ) {
80- return validate(( Number ) arg, configuration);
75+ @Throws( ValidationException :: class )
76+ override fun validateAndBox ( arg : Any? , configuration : SchemaConfiguration ? ): Int32JsonSchema1Boxed {
77+ if (arg is Number ) {
78+ return validateAndBox( arg, configuration)
8179 }
82- throw new ValidationException (" Invalid input type=" + getClass(arg) + " . It can't be validated by this schema" );
80+ throw ValidationException (" Invalid input type=$javaClass . It can't be validated by this schema" )
8381 }
8482
85- @Override
86- public Int32JsonSchema1BoxedNumber validateAndBox(Number arg, SchemaConfiguration configuration) throws ValidationException {
87- return new Int32JsonSchema1BoxedNumber (validate(arg, configuration));
88- }
83+ companion object {
84+ @Volatile
85+ private var instance: Int32JsonSchema1 ? = null
8986
90- @Override
91- public Int32JsonSchema1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
92- if (arg instanceof Number castArg) {
93- return validateAndBox(castArg, configuration);
94- }
95- throw new ValidationException (" Invalid input type=" + getClass(arg)+ " . It can't be validated by this schema" );
87+ fun getInstance () =
88+ instance ? : synchronized(this ) {
89+ instance ? : Int32JsonSchema1 ().also { instance = it }
90+ }
9691 }
9792 }
9893}
0 commit comments