Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java, improves schema generics #332

Merged
merged 111 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
675cf8a
Changes JsonSchema to be parameterized on 3 generics
spacether Dec 12, 2023
584e94a
Updates UnsetAnyTypeJsonSchema
spacether Dec 12, 2023
379408a
Updates AnyType and NotAnyType schemas
spacether Dec 12, 2023
573377f
Updates AnyType and NotAnyType schema imports
spacether Dec 12, 2023
482a633
Fixes JsonSchema imports
spacether Dec 12, 2023
0f5520b
Fixes BooleanJsonSchema
spacether Dec 12, 2023
57ee603
Updates DateJsonSchema
spacether Dec 12, 2023
109e61b
Updates DateTimeJsonSchema
spacether Dec 12, 2023
6125bd1
Updates StringJsonSchema
spacether Dec 12, 2023
fcd224c
Fixes UuidJsonSchema
spacether Dec 12, 2023
c6de749
Updates NullJsonSchema
spacether Dec 12, 2023
7031799
Updates DecimalJsonSchema
spacether Dec 12, 2023
d0fc9a1
Updates NumberJsonSchema
spacether Dec 12, 2023
3b917a9
Fixes JsonSchemaTest
spacether Dec 12, 2023
c233ca9
Adds validate methods to AnyType
spacether Dec 12, 2023
54bb0aa
Adds more validate methods to NumberSchema
spacether Dec 12, 2023
54e7fb1
Updates number schema tests
spacether Dec 12, 2023
ec64ed0
Fixes float and double validate methods
spacether Dec 12, 2023
7dc5b7a
Updates IntJsonSchema
spacether Dec 12, 2023
bf3b6a5
Updates Int32JsonSchema
spacether Dec 12, 2023
ce4f5e4
Updates Int64 and JsonSchema
spacether Dec 12, 2023
b78b9e5
Gets validator interface working for anytypejsonschema
spacether Dec 13, 2023
ede5dd3
Adds SchemaX validators and uses them in unsetanytypeschema
spacether Dec 13, 2023
ce99b38
Updates AnyType and NotAnyType schemas
spacether Dec 13, 2023
48591f1
Fixes anytype and notanytype imports
spacether Dec 13, 2023
b6df2cc
Updates BooleanJsonSchema
spacether Dec 13, 2023
d021e34
Updates DateJsonSchema
spacether Dec 13, 2023
93e6bdd
Updates DateTimejson schema
spacether Dec 13, 2023
b669371
Updates DecimalJsonSchema
spacether Dec 13, 2023
7c9fef0
Updates StringJsonSchema
spacether Dec 13, 2023
cb049d8
Updates UuidJsonSchema
spacether Dec 13, 2023
c2be70b
Updates NullJsonSchema
spacether Dec 13, 2023
193b69e
Updates NumberJsonSchema
spacether Dec 13, 2023
7b771cc
Updates DoubleJsonSchema
spacether Dec 13, 2023
86cdf1d
Updates FloatJsonSchema
spacether Dec 13, 2023
2dfb9dc
Updates Int32
spacether Dec 13, 2023
df17b7f
Updates Int64JsonSchema
spacether Dec 13, 2023
979463e
Updates IntJsonSchema
spacether Dec 13, 2023
cb8b5ad
Updates ListJsonSchema
spacether Dec 13, 2023
41d447e
Updates MapJsonSchema
spacether Dec 13, 2023
a5e1caf
Fixes validators and not any type schema import
spacether Dec 13, 2023
1bbb3cd
Updates ArrayTypeSchemaTest
spacether Dec 13, 2023
d33e1ba
Fixes JsonSchemaTest
spacether Dec 13, 2023
ea4aaa3
Updates ObjectTypeSchemaTest
spacether Dec 13, 2023
d7462ef
Fixes NullSchemaTest
spacether Dec 13, 2023
7e9bd8a
Fixes BoolSchemaTest
spacether Dec 13, 2023
bbfb94b
Fixes RefBooleanSchemaTest
spacether Dec 13, 2023
23e42b0
Fixes MapSchemaTest
spacether Dec 13, 2023
c35a8e0
Updates ListSchemaTest
spacether Dec 13, 2023
4aaef21
Fixes AnyTypeSchemaTest
spacether Dec 13, 2023
ad7cbda
Fixes AdditionalPropertiesValidatorTest
spacether Dec 13, 2023
d959154
Adds ItemsValidatorTest
spacether Dec 13, 2023
1044b8b
Fixes PropertiesValidatorTest
spacether Dec 13, 2023
04cb503
Fixes RequiredValidatorTest
spacether Dec 13, 2023
4bcde30
Fixes number tests
spacether Dec 13, 2023
a78232b
Updates gen schema implements for one of types
spacether Dec 13, 2023
978a498
String schemas updated
spacether Dec 13, 2023
8f8b01d
Updates FrozenMap classes to only pass in one generic
spacether Dec 13, 2023
85b313b
Adds missing JsonSchemaFactory import
spacether Dec 13, 2023
a04955c
Adds number schema validation, fixes class closing braces
spacether Dec 13, 2023
d9598dc
Fixes validate method for integer types
spacether Dec 13, 2023
17157ee
Updates null schema validate
spacether Dec 13, 2023
763f63a
Updates boolean validation
spacether Dec 13, 2023
f8fff42
Updates list validate method
spacether Dec 13, 2023
2799edd
Adds castToAllowedTypesfor list schemas
spacether Dec 13, 2023
2602e57
Updates list schema methods
spacether Dec 13, 2023
4434eaa
Adds missing imports in anytype
spacether Dec 13, 2023
7ed35ae
Adds getNewinstance as required JsonSchema method
spacether Dec 13, 2023
c762904
Updates anytype schemas to have object getNewInstance
spacether Dec 13, 2023
4096dbd
Adds getNewInstance to all except list and map schema classes
spacether Dec 13, 2023
398bbeb
Updates array test to use the new object method getNewInstance in lis…
spacether Dec 13, 2023
90dbe35
Adds missing getNewInstance method to list schemas
spacether Dec 13, 2023
d046d30
Adds missing methods to boolean, null, number, and string schemas
spacether Dec 13, 2023
d624ca5
Adds castToAllowedTypes
spacether Dec 13, 2023
6d233d3
Adds getNewInstance
spacether Dec 13, 2023
ac427dd
Adds object getNewInstance for map types
spacether Dec 13, 2023
848bf60
Adds validate method for maps
spacether Dec 13, 2023
45a5bd8
Fixes map output types input to generic
spacether Dec 13, 2023
6342fe1
Fixes some list casting issues
spacether Dec 13, 2023
a88e1ac
Makes array and map bulders static classes
spacether Dec 13, 2023
cd4d103
Updates any type validate methods
spacether Dec 13, 2023
6b56a02
Adds missing override annotations
spacether Dec 13, 2023
a6e7a7a
Improves validators used in multi type
spacether Dec 13, 2023
5740604
Adds list output type for anytype schemas
spacether Dec 13, 2023
1e99c9e
Adds map output type generic to map validator to anytype schemas
spacether Dec 13, 2023
bf41644
Adds private instance for singleton in all schema classes
spacether Dec 13, 2023
5c01898
Adds getInstance methods
spacether Dec 14, 2023
ec07c93
Has of method use getInstance
spacether Dec 14, 2023
1a5df4d
Fix map methods in anytype schemas
spacether Dec 14, 2023
9e4f3b1
Makes constructors protected so schemas can be extended
spacether Dec 14, 2023
4f60be4
Removes unused import
spacether Dec 14, 2023
e4b9b39
Removes JsonSchemaFactory usages
spacether Dec 14, 2023
fbabc5b
Fixes some java tests
spacether Dec 14, 2023
a1c8bc9
Fixes object schema tests
spacether Dec 14, 2023
1b73ee9
Petstore regen
spacether Dec 14, 2023
7d41f0c
Samples regen
spacether Dec 14, 2023
13afcd9
Adds missing >
spacether Dec 14, 2023
8ff75ca
Fixes multitype array interface
spacether Dec 14, 2023
1a11d41
Fixes multitype map generics
spacether Dec 14, 2023
3fac037
Updates list schema template
spacether Dec 14, 2023
6f12bfd
Updates number schema validate implementation
spacether Dec 14, 2023
2186f0b
Updates map validate implementation
spacether Dec 14, 2023
66228db
Updates list validate implementation
spacether Dec 14, 2023
9dc6a8a
Adds missing null and boolean validator imports
spacether Dec 14, 2023
c06fac4
Fixes removes key type from frozenmap output types
spacether Dec 14, 2023
df9e7fc
Adds _castToAllowedTypesObject_implementor
spacether Dec 14, 2023
0fc0262
Writes getNewInstance in all schemas for Object input
spacether Dec 14, 2023
47be45c
Fixes indentation in getNewInstance
spacether Dec 14, 2023
a30d720
Adds missing imports for FrozenList and FrozenMap
spacether Dec 15, 2023
6a1dede
Samples regen
spacether Dec 15, 2023
866b5b7
Fixes cast type and java test
spacether Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion samples/client/3_0_3_unit_test/java/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,19 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/MinLengthVali
src/main/java/org/openapijsonschematools/client/schemas/validation/MinPropertiesValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/MinimumValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/MultipleOfValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/NonCollectionJsonSchema.java
src/main/java/org/openapijsonschematools/client/schemas/validation/NotValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/OneOfValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/PathToSchemasMap.java
src/main/java/org/openapijsonschematools/client/schemas/validation/PatternValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/PropertiesValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/PropertyEntry.java
src/main/java/org/openapijsonschematools/client/schemas/validation/RequiredValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaBooleanValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaListValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaMapValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaNullValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaNumberValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/SchemaStringValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.openapijsonschematools.client.components.schemas;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
import org.openapijsonschematools.client.exceptions.InvalidTypeException;
import org.openapijsonschematools.client.exceptions.ValidationException;
import org.openapijsonschematools.client.schemas.AnyTypeJsonSchema;
import org.openapijsonschematools.client.schemas.BooleanJsonSchema;
import org.openapijsonschematools.client.schemas.validation.AdditionalPropertiesValidator;
import org.openapijsonschematools.client.schemas.validation.FrozenList;
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
import org.openapijsonschematools.client.schemas.validation.JsonSchema;
import org.openapijsonschematools.client.schemas.validation.JsonSchemaFactory;
import org.openapijsonschematools.client.schemas.validation.KeywordEntry;
import org.openapijsonschematools.client.schemas.validation.KeywordValidator;
import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap;
import org.openapijsonschematools.client.schemas.validation.PropertiesValidator;
import org.openapijsonschematools.client.schemas.validation.PropertyEntry;
import org.openapijsonschematools.client.schemas.validation.SchemaMapValidator;
import org.openapijsonschematools.client.schemas.validation.TypeValidator;
import org.openapijsonschematools.client.schemas.validation.ValidationMetadata;

public class AdditionalpropertiesAllowsASchemaWhichShouldValidate {
// nest classes so all schemas and input/output classes can be public
Expand All @@ -30,8 +37,8 @@ public static class Foo extends AnyTypeJsonSchema {}
public static class Bar extends AnyTypeJsonSchema {}


public static class AdditionalpropertiesAllowsASchemaWhichShouldValidateMap extends FrozenMap<String, Object> {
AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(FrozenMap<String, Object> m) {
public static class AdditionalpropertiesAllowsASchemaWhichShouldValidateMap extends FrozenMap<Object> {
AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(FrozenMap<Object> m) {
super(m);
}
public static final Set<String> requiredKeys = Set.of();
Expand All @@ -40,7 +47,7 @@ public static class AdditionalpropertiesAllowsASchemaWhichShouldValidateMap exte
"bar"
);
public static AdditionalpropertiesAllowsASchemaWhichShouldValidateMap of(Map<String, Object> arg, SchemaConfiguration configuration) throws ValidationException {
return JsonSchemaFactory.getInstance(AdditionalpropertiesAllowsASchemaWhichShouldValidate1.class).validate(arg, configuration);
return AdditionalpropertiesAllowsASchemaWhichShouldValidate1.getInstance().validate(arg, configuration);
}

public Object foo() {
Expand All @@ -60,19 +67,20 @@ public boolean getAdditionalProperty(String name) {
return (boolean) get(name);
}
}
public class AdditionalpropertiesAllowsASchemaWhichShouldValidateMapInput {
public static class AdditionalpropertiesAllowsASchemaWhichShouldValidateMapInput {
// optionalProperties + additionalProperties
}


public static class AdditionalpropertiesAllowsASchemaWhichShouldValidate1 extends JsonSchema<Object, Object, AdditionalpropertiesAllowsASchemaWhichShouldValidateMap, Object, Object, FrozenList<Object>> {
public static class AdditionalpropertiesAllowsASchemaWhichShouldValidate1 extends JsonSchema implements SchemaMapValidator<Object, Object, AdditionalpropertiesAllowsASchemaWhichShouldValidateMap> {
/*
NOTE: This class is auto generated by OpenAPI JSON Schema Generator.
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator

Do not edit the class manually.
*/
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1() {
private static AdditionalpropertiesAllowsASchemaWhichShouldValidate1 instance;
protected AdditionalpropertiesAllowsASchemaWhichShouldValidate1() {
super(new LinkedHashMap<>(Map.ofEntries(
new KeywordEntry("type", new TypeValidator(Set.of(FrozenMap.class))),
new KeywordEntry("properties", new PropertiesValidator(Map.ofEntries(
Expand All @@ -82,13 +90,64 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidate1() {
new KeywordEntry("additionalProperties", new AdditionalPropertiesValidator(AdditionalProperties.class))
)));
}

public static AdditionalpropertiesAllowsASchemaWhichShouldValidate1 getInstance() {
if (instance == null) {
instance = new AdditionalpropertiesAllowsASchemaWhichShouldValidate1();
}
return instance;
}

@Override
protected AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getMapOutputInstance(FrozenMap<String, Object> arg) {
return new AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(arg);
public FrozenMap<Object> castToAllowedTypes(Map<String, Object> arg, List<Object> pathToItem, Set<List<Object>> pathSet) {
pathSet.add(pathToItem);
LinkedHashMap<String, Object> argFixed = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry: arg.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
List<Object> newPathToItem = new ArrayList<>(pathToItem);
newPathToItem.add(key);
Object fixedVal = (Object) castToAllowedObjectTypes(val, newPathToItem, pathSet);
argFixed.put(key, fixedVal);
}
return new FrozenMap<>(argFixed);
}

public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getNewInstance(FrozenMap<Object> arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) {
LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
for(Map.Entry<String, Object> entry: arg.entrySet()) {
String propertyName = entry.getKey();
List<Object> propertyPathToItem = new ArrayList<>(pathToItem);
propertyPathToItem.add(propertyName);
Object value = entry.getValue();
JsonSchema propertySchema = pathToSchemas.get(propertyPathToItem).entrySet().iterator().next().getKey();
Object castValue = (Object) propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas);
properties.put(propertyName, castValue);
}
FrozenMap<Object> castProperties = new FrozenMap<>(properties);
return new AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(castProperties);
}
public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap validate(Map<String, Object> arg, SchemaConfiguration configuration) throws ValidationException {
return validateMap(arg, configuration);

@Override
public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap validate(Map<String, Object> arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
Set<List<Object>> pathSet = new HashSet<>();
List<Object> pathToItem = List.of("args[0");
FrozenMap<Object> castArg = castToAllowedTypes(arg, pathToItem, pathSet);
SchemaConfiguration usedConfiguration = Objects.requireNonNullElseGet(configuration, () -> new SchemaConfiguration(JsonSchemaKeywordFlags.ofNone()));
ValidationMetadata validationMetadata = new ValidationMetadata(pathToItem, usedConfiguration, new PathToSchemasMap(), new LinkedHashSet<>());
PathToSchemasMap pathToSchemasMap = getPathToSchemas(this, castArg, validationMetadata, pathSet);
return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap);
}


@Override
public Object getNewInstance(Object arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) {
if (arg instanceof FrozenMap) {
@SuppressWarnings("unchecked") FrozenMap<Object> castArg = (FrozenMap<Object>) arg;
return getNewInstance(castArg, pathToItem, pathToSchemas);
}
throw new InvalidTypeException("Invalid input type="+arg.getClass()+". It can't be instantiated by this schema");
}
}

}
Loading