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

Commit c5dd507

Browse files
authored
Java adds openapi v3.1.0 client + const (#357)
* Adds 310 spec for java * Updates templates to include const * Regen 310 * Removes paths from java 310 spec and client * Adds missing imports * Adds more missing imports, adds toString as reserved word * Removes prefixItems cases form java spec * Checker framework version updated * Adds back in explicit type for all SimpleEntries to fix type errors * Adjusts usage of list builder in schema tests * Excludes some schemas from the java 310 client * Removes if/then/else tests from 310 java client * Actually remove if/then/else cases * Removes more broken tests gotm java 310, updates java features * Docs regen * Fixes java docs when type is integer and it is stored as a format * Samples regen
1 parent 3048be6 commit c5dd507

File tree

794 files changed

+69521
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

794 files changed

+69521
-99
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
generatorName: java
2+
outputDir: samples/client/3_1_0_unit_test/java
3+
inputSpec: src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec_nopaths.yaml
4+
additionalProperties:
5+
packageName: unit_test_api

docs/generators/java.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
153153
<li>this</li>
154154
<li>throw</li>
155155
<li>throws</li>
156+
<li>tostring</li>
156157
<li>transient</li>
157158
<li>try</li>
158159
<li>uuid</li>
@@ -275,9 +276,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
275276
|AdditionalProperties|✓|OAS2,OAS3
276277
|AllOf|✓|OAS2,OAS3
277278
|AnyOf|✓|OAS3
278-
|Const||OAS3
279+
|Const||OAS3
279280
|Contains|✗|OAS3
280-
|Default||OAS2,OAS3
281+
|Default||OAS2,OAS3
281282
|DependentRequired|✗|OAS3
282283
|DependentSchemas|✗|OAS3
283284
|Discriminator|✗|OAS2,OAS3
@@ -332,6 +333,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
332333
| Name | Supported | Defined By |
333334
| ---- | --------- | ---------- |
334335
|JSON|✓|OAS2,OAS3
335-
|XML||OAS2,OAS3
336+
|XML||OAS2,OAS3
336337
|PROTOBUF|✗|ToolingExtension
337338
|Custom|✗|OAS2,OAS3

samples/client/3_0_3_unit_test/java/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/BigDecimalVal
209209
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanEnumValidator.java
210210
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanSchemaValidator.java
211211
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanValueMethod.java
212+
src/main/java/org/openapijsonschematools/client/schemas/validation/ConstValidator.java
212213
src/main/java/org/openapijsonschematools/client/schemas/validation/CustomIsoparser.java
213214
src/main/java/org/openapijsonschematools/client/schemas/validation/DefaultValueMethod.java
214215
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java

samples/client/3_0_3_unit_test/java/docs/components/schemas/InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import java.util.AbstractMap;
3131
3232
static final SchemaConfiguration configuration = new SchemaConfiguration(JsonSchemaKeywordFlags.ofNone());
3333
34-
// long validation
35-
long validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1.validate(
34+
// int validation
35+
int validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1.validate(
3636
1L,
3737
configuration
3838
);
@@ -42,6 +42,7 @@ long validatedPayload = InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.I
4242
| Modifier and Type | Field and Description |
4343
| ----------------- | ---------------------- |
4444
| 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/> |
45+
| String | type = "int"; |
4546
| BigDecimal | multipleOf = new BigDecimal("0.123456789") |
4647

4748
### Method Summary

samples/client/3_0_3_unit_test/java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
<properties>
227227
<maven.compiler.release>17</maven.compiler.release>
228228
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
229-
<checker-version>3.35.0</checker-version>
229+
<checker-version>3.42.0</checker-version>
230230
<maven-plugin-version>1.0.0</maven-plugin-version>
231231
<junit-version>4.13.2</junit-version>
232232
</properties>

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/components/schemas/InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf1() {
3737
Float.class,
3838
Double.class
3939
))
40+
.format("int")
4041
.multipleOf(new BigDecimal("0.123456789"))
4142
);
4243
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,56 @@ public static JsonSchemaKeywordFlags ofNone() {
8888
);
8989
}
9090

91+
public static JsonSchemaKeywordFlags onlyFormat() {
92+
return new JsonSchemaKeywordFlags(
93+
false,
94+
false,
95+
false,
96+
false,
97+
false,
98+
false,
99+
false,
100+
false,
101+
false,
102+
false,
103+
false,
104+
false,
105+
true,
106+
false,
107+
false,
108+
false,
109+
false,
110+
false,
111+
false,
112+
false,
113+
false,
114+
false,
115+
false,
116+
false,
117+
false,
118+
false,
119+
false,
120+
false,
121+
false,
122+
false,
123+
false,
124+
false,
125+
false,
126+
false,
127+
false,
128+
false,
129+
false,
130+
false,
131+
false
132+
);
133+
}
134+
91135
public LinkedHashSet<String> getKeywords() {
92136
LinkedHashSet<String> enabledKeywords = new LinkedHashSet<>();
93137
if (additionalProperties) { enabledKeywords.add("additionalProperties"); }
94138
if (allOf) { enabledKeywords.add("allOf"); }
95139
if (anyOf) { enabledKeywords.add("anyOf"); }
96-
if (const_) { enabledKeywords.add("const_"); }
140+
if (const_) { enabledKeywords.add("const"); }
97141
if (contains) { enabledKeywords.add("contains"); }
98142
if (dependentRequired) { enabledKeywords.add("dependentRequired"); }
99143
if (dependentSchemas) { enabledKeywords.add("dependentSchemas"); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.openapijsonschematools.client.schemas.validation;
2+
3+
import org.openapijsonschematools.client.exceptions.ValidationException;
4+
import org.checkerframework.checker.nullness.qual.Nullable;
5+
6+
import java.math.BigDecimal;
7+
import java.util.Objects;
8+
9+
public class ConstValidator extends BigDecimalValidator implements KeywordValidator {
10+
public final @Nullable Object constValue;
11+
12+
public ConstValidator(@Nullable Object constValue) {
13+
this.constValue = constValue;
14+
}
15+
16+
@Override
17+
public @Nullable PathToSchemasMap validate(JsonSchema schema, @Nullable Object arg, ValidationMetadata validationMetadata) {
18+
if (arg instanceof Number) {
19+
BigDecimal castArg = getBigDecimal((Number) arg);
20+
if (Objects.equals(castArg, constValue)) {
21+
return null;
22+
}
23+
if (constValue instanceof BigDecimal && ((BigDecimal) constValue).compareTo(castArg) == 0) {
24+
return null;
25+
}
26+
} else {
27+
if (Objects.equals(arg, constValue)) {
28+
return null;
29+
}
30+
}
31+
throw new ValidationException("Invalid value "+arg+" was not equal to const "+constValue);
32+
}
33+
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchema.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public abstract class JsonSchema {
4343
public final @Nullable Set<@Nullable Object> enumValues;
4444
public final @Nullable Pattern pattern;
4545
public final @Nullable Object defaultValue;
46+
public final boolean defaultValueSet;
47+
public final @Nullable Object constValue;
48+
public final boolean constValueSet;
4649
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;
4750

4851
protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
@@ -216,6 +219,15 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
216219
);
217220
}
218221
this.defaultValue = jsonSchemaInfo.defaultValue;
222+
this.defaultValueSet = jsonSchemaInfo.defaultValueSet;
223+
this.constValue = jsonSchemaInfo.constValue;
224+
this.constValueSet = jsonSchemaInfo.constValueSet;
225+
if (this.constValueSet) {
226+
keywordToValidator.put(
227+
"const",
228+
new ConstValidator(this.constValue)
229+
);
230+
}
219231
this.keywordToValidator = keywordToValidator;
220232
}
221233

@@ -233,7 +245,10 @@ public static PathToSchemasMap validate(
233245
for (Map.Entry<String, KeywordValidator> entry: thisKeywordToValidator.entrySet()) {
234246
String jsonKeyword = entry.getKey();
235247
if (disabledKeywords.contains(jsonKeyword)) {
236-
continue;
248+
boolean typeIntegerUseCase = jsonKeyword.equals("format") && "int".equals(jsonSchema.format);
249+
if (!typeIntegerUseCase) {
250+
continue;
251+
}
237252
}
238253
KeywordValidator validator = entry.getValue();
239254
@Nullable PathToSchemasMap otherPathToSchemas = validator.validate(

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/schemas/validation/JsonSchemaInfo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,17 @@ public JsonSchemaInfo pattern(Pattern pattern) {
129129
return this;
130130
}
131131
public @Nullable Object defaultValue = null;
132+
public boolean defaultValueSet = false;
132133
public JsonSchemaInfo defaultValue(@Nullable Object defaultValue) {
133134
this.defaultValue = defaultValue;
135+
this.defaultValueSet = true;
136+
return this;
137+
}
138+
public @Nullable Object constValue = null;
139+
public boolean constValueSet = false;
140+
public JsonSchemaInfo constValue(@Nullable Object constValue) {
141+
this.constValue = constValue;
142+
this.constValueSet = true;
134143
return this;
135144
}
136145
}

0 commit comments

Comments
 (0)