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 Int64JsonSchema {
20- public sealed interface Int64JsonSchema1Boxed permits Int64JsonSchema1BoxedNumber {
21- @Nullable Object getData();
12+ class Int64JsonSchema {
13+ sealed interface Int64JsonSchema1Boxed {
14+ fun getData (): Any?
2215 }
23- public record Int64JsonSchema1BoxedNumber ( Number data) implements Int64JsonSchema1Boxed {
24- @Override
25- public @Nullable Object getData() {
26- return data;
16+
17+ data class Int64JsonSchema1BoxedNumber ( val data : Number ) : Int64JsonSchema1Boxed {
18+ override fun getData (): Number {
19+ return data
2720 }
2821 }
2922
30- public static class Int64JsonSchema1 extends JsonSchema <Int64JsonSchema1Boxed > implements NumberSchemaValidator <Int64JsonSchema1BoxedNumber > {
31- private static @Nullable Int64JsonSchema1 instance = null ;
32-
33- protected Int64JsonSchema1 () {
34- super (new JsonSchemaInfo ()
35- .type(Set .of(
36- Integer .class ,
37- Long .class ,
38- Float .class ,
39- Double .class
40- ))
41- .format(" int64" )
42- );
23+ class Int64JsonSchema1 private constructor() : JsonSchema<Int64JsonSchema1Boxed>(
24+ JsonSchemaInfo ()
25+ .type(
26+ setOf(
27+ Int ::class.java,
28+ Long ::class.java,
29+ Float ::class.java,
30+ Double ::class.java
31+ )
32+ )
33+ .format("int64")
34+ ), NumberSchemaValidator<Int64JsonSchema1BoxedNumber> {
35+ @Throws(ValidationException ::class )
36+ override fun validate (arg : Number , configuration : SchemaConfiguration ? ): Number {
37+ val pathSet: MutableSet <List <Any >> = HashSet ()
38+ val pathToItem = listOf<Any >(" args[0" )
39+ val castArg: Number = castToAllowedTypes(arg, pathToItem, pathSet)
40+ val usedConfiguration = configuration ? : SchemaConfiguration (JsonSchemaKeywordFlags .Builder ().build())
41+ val validationMetadata =
42+ ValidationMetadata (pathToItem, usedConfiguration, PathToSchemasMap (), LinkedHashSet ())
43+ val pathToSchemasMap = getPathToSchemas(this , castArg, validationMetadata, pathSet)
44+ return getNewInstance(castArg, validationMetadata.pathToItem, pathToSchemasMap)
4345 }
4446
45- public static Int64JsonSchema1 getInstance() {
46- if (instance == null ) {
47- instance = new Int64JsonSchema1 ();
48- }
49- return instance;
47+ @Throws(ValidationException ::class )
48+ fun validate (arg : Int , configuration : SchemaConfiguration ? ): Int {
49+ return validate(arg as Number , configuration) as Int
5050 }
5151
52- @Override
53- public Number validate(Number arg, SchemaConfiguration configuration) throws ValidationException {
54- Set <List <Object >> pathSet = new HashSet <> ();
55- List <Object > pathToItem = List .of(" args[0" );
56- Number castArg = castToAllowedTypes(arg, pathToItem, pathSet);
57- SchemaConfiguration usedConfiguration = Objects .requireNonNullElseGet(configuration, () -> new SchemaConfiguration (new JsonSchemaKeywordFlags .Builder ().build()));
58- ValidationMetadata validationMetadata = new ValidationMetadata (pathToItem, usedConfiguration, new PathToSchemasMap (), new LinkedHashSet <> ());
59- PathToSchemasMap pathToSchemasMap = getPathToSchemas(this , castArg, validationMetadata, pathSet);
60- return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap);
52+ @Throws(ValidationException ::class )
53+ fun validate (arg : Long , configuration : SchemaConfiguration ? ): Long {
54+ return validate(arg as Number , configuration) as Long
6155 }
6256
63- public int validate(int arg, SchemaConfiguration configuration) throws ValidationException {
64- return (int) validate((Number ) arg, configuration);
57+ @Throws(ValidationException ::class )
58+ fun validate (arg : Float , configuration : SchemaConfiguration ? ): Float {
59+ return validate(arg as Number , configuration) as Float
6560 }
6661
67- public long validate(long arg, SchemaConfiguration configuration) throws ValidationException {
68- return (long) validate((Number ) arg, configuration);
62+ @Throws(ValidationException ::class )
63+ fun validate (arg : Double , configuration : SchemaConfiguration ? ): Double {
64+ return validate(arg as Number , configuration) as Double
6965 }
7066
71- public float validate(float arg, SchemaConfiguration configuration) throws ValidationException {
72- return (float) validate((Number ) arg, configuration);
67+ override fun getNewInstance (arg : Any? , pathToItem : List <Any >, pathToSchemas : PathToSchemasMap ): Any? {
68+ if (arg is Number ) {
69+ return getNewInstance(arg as Number ? , pathToItem, pathToSchemas)
70+ }
71+ throw RuntimeException (" Invalid input type=$javaClass . It can't be instantiated by this schema" )
7372 }
7473
75- public double validate(double arg, SchemaConfiguration configuration) throws ValidationException {
76- return (double) validate((Number ) arg, configuration);
74+ @Throws(ValidationException ::class )
75+ override fun validate (arg : Any? , configuration : SchemaConfiguration ? ): Number {
76+ if (arg is Number ) {
77+ return validate(arg, configuration)
78+ }
79+ throw ValidationException (" Invalid input type=$javaClass . It can't be validated by this schema" )
7780 }
7881
79- @Override
80- public @Nullable Object getNewInstance(@Nullable Object arg, List <Object > pathToItem, PathToSchemasMap pathToSchemas) {
81- if (arg instanceof Number ) {
82- return getNewInstance((Number ) arg, pathToItem, pathToSchemas);
83- }
84- throw new RuntimeException (" Invalid input type=" + getClass(arg)+ " . It can't be instantiated by this schema" );
82+ @Throws(ValidationException ::class )
83+ override fun validateAndBox (arg : Number , configuration : SchemaConfiguration ? ): Int64JsonSchema1BoxedNumber {
84+ return Int64JsonSchema1BoxedNumber (validate(arg, configuration))
8585 }
8686
87- @Override
88- public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
89- if (arg instanceof Number ) {
90- return validate(( Number ) arg, configuration);
87+ @Throws( ValidationException :: class )
88+ override fun validateAndBox ( arg : Any? , configuration : SchemaConfiguration ? ): Int64JsonSchema1Boxed {
89+ if (arg is Number ) {
90+ return validateAndBox( arg, configuration)
9191 }
92- throw new ValidationException (" Invalid input type=" + getClass(arg) + " . It can't be validated by this schema" );
92+ throw ValidationException (" Invalid input type=$javaClass . It can't be validated by this schema" )
9393 }
9494
95- @Override
96- public Int64JsonSchema1BoxedNumber validateAndBox(Number arg, SchemaConfiguration configuration) throws ValidationException {
97- return new Int64JsonSchema1BoxedNumber (validate(arg, configuration));
98- }
95+ companion object {
96+ @Volatile
97+ private var instance: Int64JsonSchema1 ? = null
9998
100- @Override
101- public Int64JsonSchema1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
102- if (arg instanceof Number castArg) {
103- return validateAndBox(castArg, configuration);
104- }
105- throw new ValidationException (" Invalid input type=" + getClass(arg)+ " . It can't be validated by this schema" );
99+ fun getInstance () =
100+ instance ? : synchronized(this ) {
101+ instance ? : Int64JsonSchema1 ().also { instance = it }
102+ }
106103 }
107104 }
108105}
0 commit comments