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

Commit 3048be6

Browse files
authored
Java generator, adds schema default + Servers (#355)
* Stores default in schemas * Adds schema defaults, writes server base classes * Root variables fixed * Fixes server class names for path servers * Fixes path verb servers * 303 java sample updated * Fixes datetime default values * Fixes the type of defaultValue in docs * Adds DefaultValueMethod interface * Fiexs type error when accessing defaultValue by adding DefaultValueMethod interface * Petstore regen with schema docs * Adds servers feature in java docs * Samples regen
1 parent 3d94aee commit 3048be6

File tree

86 files changed

+2490
-45
lines changed

Some content is hidden

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

86 files changed

+2490
-45
lines changed

docs/generators/java.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
168168
### Client Modification Feature
169169
| Name | Supported | Defined By |
170170
| ---- | --------- | ---------- |
171-
|BasePath||ToolingExtension
171+
|BasePath||ToolingExtension
172172
|Authorizations|✗|ToolingExtension
173173
|UserAgent|✗|ToolingExtension
174174
|MockServer|✗|ToolingExtension
@@ -216,7 +216,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
216216
| Name | Supported | Defined By |
217217
| ---- | --------- | ---------- |
218218
|Readme|✓|ToolingExtension
219-
|Servers||OAS3
219+
|Servers||OAS3
220220
|Security|✗|OAS2,OAS3
221221
|ComponentSchemas|✓|OAS3
222222
|ComponentResponses|✗|OAS3
@@ -233,7 +233,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
233233
| Name | Supported | Defined By |
234234
| ---- | --------- | ---------- |
235235
|Info|✓|OAS2,OAS3
236-
|Servers||OAS3
236+
|Servers||OAS3
237237
|Paths|✗|OAS2,OAS3
238238
|Webhooks|✗|OAS3
239239
|Components|✓|OAS3

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ docs/components/schemas/UniqueitemsValidation.md
8686
docs/components/schemas/UriFormat.md
8787
docs/components/schemas/UriReferenceFormat.md
8888
docs/components/schemas/UriTemplateFormat.md
89+
docs/servers/Server0.md
8990
pom.xml
9091
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesAllowsASchemaWhichShouldValidate.java
9192
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesAreAllowedByDefault.java
@@ -209,6 +210,7 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanEnumVa
209210
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanSchemaValidator.java
210211
src/main/java/org/openapijsonschematools/client/schemas/validation/BooleanValueMethod.java
211212
src/main/java/org/openapijsonschematools/client/schemas/validation/CustomIsoparser.java
213+
src/main/java/org/openapijsonschematools/client/schemas/validation/DefaultValueMethod.java
212214
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleEnumValidator.java
213215
src/main/java/org/openapijsonschematools/client/schemas/validation/DoubleValueMethod.java
214216
src/main/java/org/openapijsonschematools/client/schemas/validation/EnumValidator.java
@@ -261,6 +263,9 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/TypeValidator
261263
src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsValidator.java
262264
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
263265
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMetadata.java
266+
src/main/java/org/openapijsonschematools/client/servers/Server0.java
267+
src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java
268+
src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java
264269
src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java
265270
src/test/java/org/openapijsonschematools/client/schemas/AnyTypeSchemaTest.java
266271
src/test/java/org/openapijsonschematools/client/schemas/ArrayTypeSchemaTest.java

samples/client/3_0_3_unit_test/java/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ org.openapijsonschematools.client.components.schemas to validate input payloads
148148
output classes. Json schemas allow multiple types for one schema, so a schema's validate method can have
149149
allowed input and output types.
150150

151+
## Servers
152+
| server_index | Class | Description |
153+
| ------------ | ----- | ----------- |
154+
| 0 | [Server0](docs/servers/Server0.md) | |
155+
151156
## Component Schemas
152157

153158
| Class | Description |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ String validatedPayload = InvalidStringValueForDefault.Bar.validate(
111111
| ----------------- | ---------------------- |
112112
| Set<Class<?>> | type = Set.of(<br/>&nbsp;&nbsp;&nbsp;&nbsp;String.class<br/>)<br/> |
113113
| Integer | minLength = 4 |
114+
| @Nullable Object | defaultValue = "bad" |
114115

115116
### Method Summary
116117
| Modifier and Type | Method and Description |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ int validatedPayload = TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing.
133133
| ----------------- | ---------------------- |
134134
| 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/> |
135135
| Number | maximum = 3 |
136+
| @Nullable Object | defaultValue = 5.0 |
136137

137138
### Method Summary
138139
| Modifier and Type | Method and Description |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
org.openapijsonschematools.client.servers.Server0
2+
# Server Server0
3+
public class Server0
4+
5+
A class that stores a server url
6+
7+
### Constructor Summary
8+
| Constructor and Description |
9+
| --------------------------- |
10+
| Server0()<br>Creates a server |
11+
12+
### Field Summary
13+
| Modifier and Type | Field and Description |
14+
| ----------------- | --------------------- |
15+
| String | url = "https://someserver.com/v1" |
16+
17+
[[Back to top]](#top) [[Back to Servers]](../../README.md#Servers) [[Back to README]](../../README.md)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openapijsonschematools.client.schemas.BaseBuilder;
2121
import org.openapijsonschematools.client.schemas.UnsetAddPropsSetter;
2222
import org.openapijsonschematools.client.schemas.validation.BooleanSchemaValidator;
23+
import org.openapijsonschematools.client.schemas.validation.DefaultValueMethod;
2324
import org.openapijsonschematools.client.schemas.validation.FrozenList;
2425
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
2526
import org.openapijsonschematools.client.schemas.validation.JsonSchema;
@@ -37,7 +38,7 @@ public class InvalidStringValueForDefault {
3738
// nest classes so all schemas and input/output classes can be public
3839

3940

40-
public static class Bar extends JsonSchema implements StringSchemaValidator {
41+
public static class Bar extends JsonSchema implements StringSchemaValidator, DefaultValueMethod<String> {
4142
private static @Nullable Bar instance = null;
4243

4344
protected Bar() {
@@ -46,6 +47,7 @@ protected Bar() {
4647
String.class
4748
))
4849
.minLength(4)
50+
.defaultValue("bad")
4951
);
5052
}
5153

@@ -81,6 +83,12 @@ public String validate(String arg, SchemaConfiguration configuration) throws Val
8183
}
8284
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema");
8385
}
86+
public String defaultValue() {
87+
if (defaultValue instanceof String) {
88+
return (String) defaultValue;
89+
}
90+
throw new InvalidTypeException("Invalid type stored in defaultValue");
91+
}
8492
}
8593

8694
public static class InvalidStringValueForDefaultMap extends FrozenMap<@Nullable Object> {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.openapijsonschematools.client.exceptions.ValidationException;
1717
import org.openapijsonschematools.client.schemas.BaseBuilder;
1818
import org.openapijsonschematools.client.schemas.UnsetAddPropsSetter;
19+
import org.openapijsonschematools.client.schemas.validation.DefaultValueMethod;
1920
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
2021
import org.openapijsonschematools.client.schemas.validation.JsonSchema;
2122
import org.openapijsonschematools.client.schemas.validation.JsonSchemaInfo;
@@ -41,6 +42,7 @@ protected Alpha() {
4142
Double.class
4243
))
4344
.maximum(3)
45+
.defaultValue(5.0)
4446
);
4547
}
4648

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.openapijsonschematools.client.schemas.validation;
2+
3+
public interface DefaultValueMethod<T> {
4+
T defaultValue();
5+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public abstract class JsonSchema {
4242
public final @Nullable Boolean uniqueItems;
4343
public final @Nullable Set<@Nullable Object> enumValues;
4444
public final @Nullable Pattern pattern;
45+
public final @Nullable Object defaultValue;
4546
private final LinkedHashMap<String, KeywordValidator> keywordToValidator;
4647

4748
protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
@@ -214,6 +215,7 @@ protected JsonSchema(JsonSchemaInfo jsonSchemaInfo) {
214215
new PatternValidator(this.pattern)
215216
);
216217
}
218+
this.defaultValue = jsonSchemaInfo.defaultValue;
217219
this.keywordToValidator = keywordToValidator;
218220
}
219221

0 commit comments

Comments
 (0)