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

Commit f4f07d9

Browse files
authored
Java client, simplifies ApiConfiguration servers info + adds operation code sample (#409)
* Adds SeverIndexInfo * Generates separate docs for server variables schema * Removes unused import * Adds missing docs newlines, removes EnumMap from security info * Adds Override annotations, removes nullability from enum input for security fetching * Adds operation code sample imports * Improves operation code sample, adds initial empty security info * Adds securitySchemes to operation code sample * Adds apiClient to operation code sample * Adds todo for operation required inputs * Refactors docs schema code sample template * Adds operation input samples for query path header and cookie parameters * Fixes request body doc links * Fixes request body path query header cookie variable name for code sample * Adds requestBoud samples in operation code sample * Adds response retrieval to operation docs * Changes all exceptions to be based on Exception * Adds exception throwing to json schema code * Updates all valudators to include exception throws in their signatures * Adds more needed throws info * throws signatures added to auto gen schemas * Uses RuntimeExceptions when checking types of properties because the exceptions will never be thrown * Adds more needed excption signatures * Adds many more exceptions to method signatures * Adds exception info to ResponseDeserializerTest * Updates getNewInstance to only throw RuntimExceptions * Fixes java tests in schema validation package * Fixes anytype and array type schema tests * Fixes schema tests * Fixes request body test * Fixes parameter tests * Fixes cookie parameter test in java * Fixes header tests * Regenerates java 303 sample with fixed schema tests * Fixes java tests * Fixes java tests * Imports request body schema when it is required * Adds general exception types to operation invocation * Upses SimpleEntry for header and parameter content info * Replaces header and parameter content map with SimpleEntry * Replaces OpenapiDocumentException with ApiException * Removes InvalidTypeException * Adds response exception catching to the operation docs * Adjusts operation docs * Adds exception catching for error response exceptions * Adds responses casting to operation docs * Adds response body if else to operation docs * Samples and docs regen * 310 java sample regen * Samples regen * Sample regen with fix for java array payloads with one null value * 303 java component schema tests regen * Samples regen
1 parent 06b89d2 commit f4f07d9

File tree

1,887 files changed

+24402
-18144
lines changed

Some content is hidden

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

1,887 files changed

+24402
-18144
lines changed

docs/generators/java.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
235235
| ---- | --------- | ---------- |
236236
|Info|✓|OAS2,OAS3
237237
|Servers|✓|OAS3
238-
|Paths||OAS2,OAS3
238+
|Paths||OAS2,OAS3
239239
|Webhooks|✗|OAS3
240240
|Components|✓|OAS3
241241
|Security|✓|OAS2,OAS3

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ src/main/java/org/openapijsonschematools/client/contenttype/ContentTypeSerialize
187187
src/main/java/org/openapijsonschematools/client/exceptions/ApiException.java
188188
src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java
189189
src/main/java/org/openapijsonschematools/client/exceptions/InvalidAdditionalPropertyException.java
190-
src/main/java/org/openapijsonschematools/client/exceptions/InvalidTypeException.java
190+
src/main/java/org/openapijsonschematools/client/exceptions/NotImplementedException.java
191191
src/main/java/org/openapijsonschematools/client/exceptions/UnsetPropertyException.java
192192
src/main/java/org/openapijsonschematools/client/exceptions/ValidationException.java
193193
src/main/java/org/openapijsonschematools/client/header/ContentHeader.java

samples/client/3_0_3_unit_test/java/docs/RootServerInfo.md

+23
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,36 @@ RootServerInfo.java
44
public class RootServerInfo
55

66
A class that provides a server, and any needed server info classes
7+
- a class that is a ServerProvider
78
- an enum class that stores server index values
89

910
## Nested Class Summary
1011
| Modifier and Type | Class and Description |
1112
| ----------------- | --------------------- |
13+
| static class | [RootServerInfo.RootServerInfo1](#rootserverinfo1)<br>class that stores a server index |
1214
| enum | [RootServerInfo.ServerIndex](#serverindex)<br>class that stores a server index |
1315

16+
## RootServerInfo1
17+
implements ServerProvider<[ServerIndex](#serverindex)><br>
18+
19+
A class that stores servers and allows one to be returned with a ServerIndex instance
20+
21+
### Constructor Summary
22+
| Constructor and Description |
23+
| --------------------------- |
24+
| RootServerInfo1()<br>Creates an instance using default server variable values |
25+
| RootServerInfo1(@Nullable [Server0](servers/Server0.md) server0)<br>Creates an instance using passed in servers |
26+
27+
### Field Summary
28+
| Modifier and Type | Field and Description |
29+
| ----------------- | --------------------- |
30+
| [Server0](servers/Server0.md) | server0 |
31+
32+
### Method Summary
33+
| Modifier and Type | Method and Description |
34+
| ----------------- | ---------------------- |
35+
| Server | getServer([ServerIndex](#serverindex) serverIndex) |
36+
1437
## ServerIndex
1538
enum ServerIndex<br>
1639

Original file line numberDiff line numberDiff line change
@@ -1,73 +1,33 @@
11
package org.openapijsonschematools.client;
22

3-
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
43
import org.openapijsonschematools.client.servers.Server0;
54
import org.openapijsonschematools.client.servers.Server;
65
import org.openapijsonschematools.client.servers.ServerProvider;
76
import org.checkerframework.checker.nullness.qual.Nullable;
87

9-
import java.util.AbstractMap;
10-
import java.util.Map;
118
import java.util.Objects;
12-
import java.util.EnumMap;
139

14-
public class RootServerInfo implements ServerProvider<RootServerInfo.ServerIndex> {
15-
final private Servers servers;
16-
final private ServerIndex serverIndex;
10+
public class RootServerInfo {
11+
public static class RootServerInfo1 implements ServerProvider<ServerIndex> {
12+
public final Server0 server0;
1713

18-
public RootServerInfo() {
19-
this.servers = new Servers();
20-
this.serverIndex = ServerIndex.SERVER_0;
21-
}
22-
23-
public RootServerInfo(Servers servers, ServerIndex serverIndex) {
24-
this.servers = servers;
25-
this.serverIndex = serverIndex;
26-
}
27-
28-
public static class Servers {
29-
private final EnumMap<ServerIndex, Server> servers;
30-
31-
public Servers() {
32-
servers = new EnumMap<>(
33-
Map.ofEntries(
34-
new AbstractMap.SimpleEntry<>(
35-
ServerIndex.SERVER_0,
36-
new Server0()
37-
)
38-
)
39-
);
14+
public RootServerInfo1() {
15+
server0 = new Server0();
4016
}
4117

42-
public Servers(
18+
public RootServerInfo1(
4319
@Nullable Server0 server0
4420
) {
45-
servers = new EnumMap<>(
46-
Map.ofEntries(
47-
new AbstractMap.SimpleEntry<>(
48-
ServerIndex.SERVER_0,
49-
Objects.requireNonNullElseGet(server0, Server0::new)
50-
)
51-
)
52-
);
21+
this.server0 = Objects.requireNonNullElseGet(server0, Server0::new);
5322
}
5423

55-
public Server get(ServerIndex serverIndex) {
56-
if (servers.containsKey(serverIndex)) {
57-
return get(serverIndex);
58-
}
59-
throw new UnsetPropertyException(serverIndex+" is unset");
24+
@Override
25+
public Server getServer(ServerIndex serverIndex) {
26+
return server0;
6027
}
6128
}
6229

6330
public enum ServerIndex {
6431
SERVER_0
6532
}
66-
67-
public Server getServer(@Nullable ServerIndex serverIndex) {
68-
if (serverIndex == null) {
69-
return servers.get(this.serverIndex);
70-
}
71-
return servers.get(serverIndex);
72-
}
7333
}

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
1212
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
1313
import org.openapijsonschematools.client.exceptions.InvalidAdditionalPropertyException;
14-
import org.openapijsonschematools.client.exceptions.InvalidTypeException;
1514
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
1615
import org.openapijsonschematools.client.exceptions.ValidationException;
1716
import org.openapijsonschematools.client.schemas.AnyTypeJsonSchema;
@@ -88,7 +87,7 @@ public boolean getAdditionalProperty(String name) throws UnsetPropertyException,
8887
throwIfKeyKnown(name, requiredKeys, optionalKeys);
8988
var value = getOrThrow(name);
9089
if (!(value instanceof Boolean)) {
91-
throw new InvalidTypeException("Invalid value stored for " + name);
90+
throw new RuntimeException("Invalid value stored for " + name);
9291
}
9392
return (boolean) value;
9493
}
@@ -299,15 +298,15 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getNewInstance(Ma
299298
for(Map.Entry<?, ?> entry: arg.entrySet()) {
300299
@Nullable Object entryKey = entry.getKey();
301300
if (!(entryKey instanceof String)) {
302-
throw new InvalidTypeException("Invalid non-string key value");
301+
throw new RuntimeException("Invalid non-string key value");
303302
}
304303
String propertyName = (String) entryKey;
305304
List<Object> propertyPathToItem = new ArrayList<>(pathToItem);
306305
propertyPathToItem.add(propertyName);
307306
Object value = entry.getValue();
308307
LinkedHashMap<JsonSchema<?>, Void> schemas = pathToSchemas.get(propertyPathToItem);
309308
if (schemas == null) {
310-
throw new InvalidTypeException("Validation result is invalid, schemas must exist for a pathToItem");
309+
throw new RuntimeException("Validation result is invalid, schemas must exist for a pathToItem");
311310
}
312311
JsonSchema<?> propertySchema = schemas.entrySet().iterator().next().getKey();
313312
@Nullable Object propertyInstance = propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas);
@@ -317,7 +316,7 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getNewInstance(Ma
317316
return new AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(castProperties);
318317
}
319318

320-
public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap validate(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
319+
public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap validate(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException {
321320
Set<List<Object>> pathSet = new HashSet<>();
322321
List<Object> pathToItem = List.of("args[0");
323322
Map<?, ?> castArg = castToAllowedTypes(arg, pathToItem, pathSet);
@@ -329,29 +328,29 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap validate(Map<?, ?
329328

330329

331330
@Override
332-
public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
331+
public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
333332
if (arg instanceof Map) {
334333
return validate((Map<?, ?>) arg, configuration);
335334
}
336-
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
335+
throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
337336
}
338337
@Override
339-
public @Nullable Object getNewInstance(@Nullable Object arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) throws InvalidTypeException {
338+
public @Nullable Object getNewInstance(@Nullable Object arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) {
340339
if (arg instanceof Map) {
341340
return getNewInstance((Map<?, ?>) arg, pathToItem, pathToSchemas);
342341
}
343-
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema");
342+
throw new RuntimeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema");
344343
}
345344
@Override
346-
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap validateAndBox(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
345+
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap validateAndBox(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException {
347346
return new AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap(validate(arg, configuration));
348347
}
349348
@Override
350-
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
349+
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
351350
if (arg instanceof Map<?, ?> castArg) {
352351
return validateAndBox(castArg, configuration);
353352
}
354-
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
353+
throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
355354
}
356355
}
357356

0 commit comments

Comments
 (0)