Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions bin/generate_samples_configs/java_3_1_0_unit_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
generatorName: java
outputDir: samples/client/3_1_0_unit_test/java
inputSpec: src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec_nopaths.yaml
additionalProperties:
packageName: unit_test_api
7 changes: 4 additions & 3 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>this</li>
<li>throw</li>
<li>throws</li>
<li>tostring</li>
<li>transient</li>
<li>try</li>
<li>uuid</li>
Expand Down Expand Up @@ -275,9 +276,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✓|OAS2,OAS3
|AllOf|✓|OAS2,OAS3
|AnyOf|✓|OAS3
|Const||OAS3
|Const||OAS3
|Contains|✗|OAS3
|Default||OAS2,OAS3
|Default||OAS2,OAS3
|DependentRequired|✗|OAS3
|DependentSchemas|✗|OAS3
|Discriminator|✗|OAS2,OAS3
Expand Down Expand Up @@ -332,6 +333,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML||OAS2,OAS3
|XML||OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✗|OAS2,OAS3
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/BigDecimalVal
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanEnumValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanSchemaValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanValueMethod.java
src/main/java/org/openapijsonschematools/client/schemas/validation/ConstValidator.java
src/main/java/org/openapijsonschematools/client/schemas/validation/CustomIsoparser.java
src/main/java/org/openapijsonschematools/client/schemas/validation/DefaultValueMethod.java
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import java.util.AbstractMap;

static final SchemaConfiguration configuration = new SchemaConfiguration(JsonSchemaKeywordFlags.ofNone());

// long validation
long validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1.validate(
// int validation
int validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1.validate(
1L,
configuration
);
Expand All @@ -42,6 +42,7 @@ long validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.I
| Modifier and Type | Field and Description |
| ----------------- | ---------------------- |
| Set<Class<?>> | type = Set.of(<br/>&nbsp;&nbsp;&nbsp;&nbsp;Integer.class,<br/>&nbsp;&nbsp;&nbsp;&nbsp;Long.class,<br/>&nbsp;&nbsp;&nbsp;&nbsp;Float.class,<br/>&nbsp;&nbsp;&nbsp;&nbsp;Double.class<br/>)<br/> |
| String | type = "int"; |
| BigDecimal | multipleOf = new BigDecimal("0.123456789") |

### Method Summary
Expand Down
2 changes: 1 addition & 1 deletion samples/client/3_0_3_unit_test/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checker-version>3.35.0</checker-version>
<checker-version>3.42.0</checker-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.13.2</junit-version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1() {
Float.class,
Double.class
))
.format("int")
.multipleOf(new BigDecimal("0.123456789"))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,56 @@ public static JsonSchemaKeywordFlags ofNone() {
);
}

public static JsonSchemaKeywordFlags onlyFormat() {
return new JsonSchemaKeywordFlags(
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
);
}

public LinkedHashSet<String> getKeywords() {
LinkedHashSet<String> enabledKeywords = new LinkedHashSet<>();
if (additionalProperties) { enabledKeywords.add("additionalProperties"); }
if (allOf) { enabledKeywords.add("allOf"); }
if (anyOf) { enabledKeywords.add("anyOf"); }
if (const_) { enabledKeywords.add("const_"); }
if (const_) { enabledKeywords.add("const"); }
if (contains) { enabledKeywords.add("contains"); }
if (dependentRequired) { enabledKeywords.add("dependentRequired"); }
if (dependentSchemas) { enabledKeywords.add("dependentSchemas"); }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.openapijsonschematools.client.schemas.validation;

import org.openapijsonschematools.client.exceptions.ValidationException;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.math.BigDecimal;
import java.util.Objects;

public class ConstValidator extends BigDecimalValidator implements KeywordValidator {
public final @Nullable Object constValue;

public ConstValidator(@Nullable Object constValue) {
this.constValue = constValue;
}

@Override
public @Nullable PathToSchemasMap validate(JsonSchema schema, @Nullable Object arg, ValidationMetadata validationMetadata) {
if (arg instanceof Number) {
BigDecimal castArg = getBigDecimal((Number) arg);
if (Objects.equals(castArg, constValue)) {
return null;
}
if (constValue instanceof BigDecimal && ((BigDecimal) constValue).compareTo(castArg) == 0) {
return null;
}
} else {
if (Objects.equals(arg, constValue)) {
return null;
}
}
throw new ValidationException("Invalid value "+arg+" was not equal to const "+constValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public abstract class JsonSchema {
public final @Nullable Set<@Nullable Object> enumValues;
public final @Nullable Pattern pattern;
public final @Nullable Object defaultValue;
public final boolean defaultValueSet;
public final @Nullable Object constValue;
public final boolean constValueSet;
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;

protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
Expand Down Expand Up @@ -216,6 +219,15 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
);
}
this.defaultValue = jsonSchemaInfo.defaultValue;
this.defaultValueSet = jsonSchemaInfo.defaultValueSet;
this.constValue = jsonSchemaInfo.constValue;
this.constValueSet = jsonSchemaInfo.constValueSet;
if (this.constValueSet) {
keywordToValidator.put(
"const",
new ConstValidator(this.constValue)
);
}
this.keywordToValidator = keywordToValidator;
}

Expand All @@ -233,7 +245,10 @@ public static PathToSchemasMap validate(
for (Map.Entry<String, KeywordValidator> entry: thisKeywordToValidator.entrySet()) {
String jsonKeyword = entry.getKey();
if (disabledKeywords.contains(jsonKeyword)) {
continue;
boolean typeIntegerUseCase = jsonKeyword.equals("format") && "int".equals(jsonSchema.format);
if (!typeIntegerUseCase) {
continue;
}
}
KeywordValidator validator = entry.getValue();
@Nullable PathToSchemasMap otherPathToSchemas = validator.validate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,17 @@ public JsonSchemaInfo pattern(Pattern pattern) {
return this;
}
public @Nullable Object defaultValue = null;
public boolean defaultValueSet = false;
public JsonSchemaInfo defaultValue(@Nullable Object defaultValue) {
this.defaultValue = defaultValue;
this.defaultValueSet = true;
return this;
}
public @Nullable Object constValue = null;
public boolean constValueSet = false;
public JsonSchemaInfo constValue(@Nullable Object constValue) {
this.constValue = constValue;
this.constValueSet = true;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testGetEnabledKeywords() {
expectedEnabledKeywords.add("additionalProperties");
expectedEnabledKeywords.add("allOf");
expectedEnabledKeywords.add("anyOf");
expectedEnabledKeywords.add("const_");
expectedEnabledKeywords.add("const");
expectedEnabledKeywords.add("contains");
expectedEnabledKeywords.add("dependentRequired");
expectedEnabledKeywords.add("dependentSchemas");
Expand Down
23 changes: 23 additions & 0 deletions samples/client/3_1_0_unit_test/java/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapi-json-schema-tools/openapi-json-schema-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Loading