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

Java client, simplifies ApiConfiguration servers info + adds operation code sample #409

Merged
merged 53 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
707d421
Adds SeverIndexInfo
spacether Mar 27, 2024
777c593
Generates separate docs for server variables schema
spacether Mar 28, 2024
d2b1e0b
Removes unused import
spacether Mar 28, 2024
edc76ad
Adds missing docs newlines, removes EnumMap from security info
spacether Mar 28, 2024
5877bdf
Adds Override annotations, removes nullability from enum input for se…
spacether Mar 28, 2024
3cd545a
Adds operation code sample imports
spacether Mar 31, 2024
94c4938
Improves operation code sample, adds initial empty security info
spacether Mar 31, 2024
b28193e
Adds securitySchemes to operation code sample
spacether Mar 31, 2024
b9050a7
Adds apiClient to operation code sample
spacether Mar 31, 2024
c3c99eb
Adds todo for operation required inputs
spacether Mar 31, 2024
fbf0e77
Refactors docs schema code sample template
spacether Mar 31, 2024
0e69e1d
Adds operation input samples for query path header and cookie parameters
spacether Mar 31, 2024
71f5b1d
Fixes request body doc links
spacether Mar 31, 2024
6447c33
Fixes request body path query header cookie variable name for code sa…
spacether Mar 31, 2024
fa2aa7b
Adds requestBoud samples in operation code sample
spacether Apr 1, 2024
c9e01b4
Adds response retrieval to operation docs
spacether Apr 1, 2024
a1f6314
Changes all exceptions to be based on Exception
spacether Apr 1, 2024
2f9419d
Adds exception throwing to json schema code
spacether Apr 1, 2024
e91dc13
Updates all valudators to include exception throws in their signatures
spacether Apr 1, 2024
9abe48e
Adds more needed throws info
spacether Apr 1, 2024
446f7d7
throws signatures added to auto gen schemas
spacether Apr 1, 2024
c351cc2
Uses RuntimeExceptions when checking types of properties because the …
spacether Apr 1, 2024
c7cec9b
Adds more needed excption signatures
spacether Apr 2, 2024
dc8d345
Adds many more exceptions to method signatures
spacether Apr 2, 2024
2a29ed9
Adds exception info to ResponseDeserializerTest
spacether Apr 2, 2024
fe9fff4
Updates getNewInstance to only throw RuntimExceptions
spacether Apr 2, 2024
85fd44c
Fixes java tests in schema validation package
spacether Apr 2, 2024
5f9571b
Fixes anytype and array type schema tests
spacether Apr 2, 2024
7185a27
Fixes schema tests
spacether Apr 2, 2024
2db8f01
Fixes request body test
spacether Apr 2, 2024
195b617
Fixes parameter tests
spacether Apr 2, 2024
200a5aa
Fixes cookie parameter test in java
spacether Apr 2, 2024
e5b5e80
Fixes header tests
spacether Apr 2, 2024
a1040ba
Regenerates java 303 sample with fixed schema tests
spacether Apr 2, 2024
0a09a03
Fixes java tests
spacether Apr 2, 2024
81565d5
Fixes java tests
spacether Apr 2, 2024
834544d
Imports request body schema when it is required
spacether Apr 2, 2024
57ae4a3
Adds general exception types to operation invocation
spacether Apr 2, 2024
5398c98
Upses SimpleEntry for header and parameter content info
spacether Apr 3, 2024
7c813c8
Replaces header and parameter content map with SimpleEntry
spacether Apr 3, 2024
330cb31
Replaces OpenapiDocumentException with ApiException
spacether Apr 3, 2024
ba9aaf0
Removes InvalidTypeException
spacether Apr 3, 2024
ffbb7d1
Adds response exception catching to the operation docs
spacether Apr 3, 2024
76c3a89
Adjusts operation docs
spacether Apr 3, 2024
b5551d0
Adds exception catching for error response exceptions
spacether Apr 4, 2024
14b4504
Adds responses casting to operation docs
spacether Apr 4, 2024
c04581d
Adds response body if else to operation docs
spacether Apr 4, 2024
7533ca3
Samples and docs regen
spacether Apr 4, 2024
710c10b
310 java sample regen
spacether Apr 4, 2024
7490ba8
Samples regen
spacether Apr 5, 2024
6527ac5
Sample regen with fix for java array payloads with one null value
spacether Apr 5, 2024
e1451b4
303 java component schema tests regen
spacether Apr 5, 2024
a46495b
Samples regen
spacether Apr 5, 2024
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ---- | --------- | ---------- |
|Info|✓|OAS2,OAS3
|Servers|✓|OAS3
|Paths||OAS2,OAS3
|Paths||OAS2,OAS3
|Webhooks|✗|OAS3
|Components|✓|OAS3
|Security|✓|OAS2,OAS3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ src/main/java/org/openapijsonschematools/client/contenttype/ContentTypeSerialize
src/main/java/org/openapijsonschematools/client/exceptions/ApiException.java
src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java
src/main/java/org/openapijsonschematools/client/exceptions/InvalidAdditionalPropertyException.java
src/main/java/org/openapijsonschematools/client/exceptions/InvalidTypeException.java
src/main/java/org/openapijsonschematools/client/exceptions/NotImplementedException.java
src/main/java/org/openapijsonschematools/client/exceptions/UnsetPropertyException.java
src/main/java/org/openapijsonschematools/client/exceptions/ValidationException.java
src/main/java/org/openapijsonschematools/client/header/ContentHeader.java
Expand Down
23 changes: 23 additions & 0 deletions samples/client/3_0_3_unit_test/java/docs/RootServerInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@ RootServerInfo.java
public class RootServerInfo

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

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

## RootServerInfo1
implements ServerProvider<[ServerIndex](#serverindex)><br>

A class that stores servers and allows one to be returned with a ServerIndex instance

### Constructor Summary
| Constructor and Description |
| --------------------------- |
| RootServerInfo1()<br>Creates an instance using default server variable values |
| RootServerInfo1(@Nullable [Server0](servers/Server0.md) server0)<br>Creates an instance using passed in servers |

### Field Summary
| Modifier and Type | Field and Description |
| ----------------- | --------------------- |
| [Server0](servers/Server0.md) | server0 |

### Method Summary
| Modifier and Type | Method and Description |
| ----------------- | ---------------------- |
| Server | getServer([ServerIndex](#serverindex) serverIndex) |

## ServerIndex
enum ServerIndex<br>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,33 @@
package org.openapijsonschematools.client;

import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
import org.openapijsonschematools.client.servers.Server0;
import org.openapijsonschematools.client.servers.Server;
import org.openapijsonschematools.client.servers.ServerProvider;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Objects;
import java.util.EnumMap;

public class RootServerInfo implements ServerProvider<RootServerInfo.ServerIndex> {
final private Servers servers;
final private ServerIndex serverIndex;
public class RootServerInfo {
public static class RootServerInfo1 implements ServerProvider<ServerIndex> {
public final Server0 server0;

public RootServerInfo() {
this.servers = new Servers();
this.serverIndex = ServerIndex.SERVER_0;
}

public RootServerInfo(Servers servers, ServerIndex serverIndex) {
this.servers = servers;
this.serverIndex = serverIndex;
}

public static class Servers {
private final EnumMap<ServerIndex, Server> servers;

public Servers() {
servers = new EnumMap<>(
Map.ofEntries(
new AbstractMap.SimpleEntry<>(
ServerIndex.SERVER_0,
new Server0()
)
)
);
public RootServerInfo1() {
server0 = new Server0();
}

public Servers(
public RootServerInfo1(
@Nullable Server0 server0
) {
servers = new EnumMap<>(
Map.ofEntries(
new AbstractMap.SimpleEntry<>(
ServerIndex.SERVER_0,
Objects.requireNonNullElseGet(server0, Server0::new)
)
)
);
this.server0 = Objects.requireNonNullElseGet(server0, Server0::new);
}

public Server get(ServerIndex serverIndex) {
if (servers.containsKey(serverIndex)) {
return get(serverIndex);
}
throw new UnsetPropertyException(serverIndex+" is unset");
@Override
public Server getServer(ServerIndex serverIndex) {
return server0;
}
}

public enum ServerIndex {
SERVER_0
}

public Server getServer(@Nullable ServerIndex serverIndex) {
if (serverIndex == null) {
return servers.get(this.serverIndex);
}
return servers.get(serverIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
import org.openapijsonschematools.client.exceptions.InvalidAdditionalPropertyException;
import org.openapijsonschematools.client.exceptions.InvalidTypeException;
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
import org.openapijsonschematools.client.exceptions.ValidationException;
import org.openapijsonschematools.client.schemas.AnyTypeJsonSchema;
Expand Down Expand Up @@ -88,7 +87,7 @@ public boolean getAdditionalProperty(String name) throws UnsetPropertyException,
throwIfKeyKnown(name, requiredKeys, optionalKeys);
var value = getOrThrow(name);
if (!(value instanceof Boolean)) {
throw new InvalidTypeException("Invalid value stored for " + name);
throw new RuntimeException("Invalid value stored for " + name);
}
return (boolean) value;
}
Expand Down Expand Up @@ -299,15 +298,15 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getNewInstance(Ma
for(Map.Entry<?, ?> entry: arg.entrySet()) {
@Nullable Object entryKey = entry.getKey();
if (!(entryKey instanceof String)) {
throw new InvalidTypeException("Invalid non-string key value");
throw new RuntimeException("Invalid non-string key value");
}
String propertyName = (String) entryKey;
List<Object> propertyPathToItem = new ArrayList<>(pathToItem);
propertyPathToItem.add(propertyName);
Object value = entry.getValue();
LinkedHashMap<JsonSchema<?>, Void> schemas = pathToSchemas.get(propertyPathToItem);
if (schemas == null) {
throw new InvalidTypeException("Validation result is invalid, schemas must exist for a pathToItem");
throw new RuntimeException("Validation result is invalid, schemas must exist for a pathToItem");
}
JsonSchema<?> propertySchema = schemas.entrySet().iterator().next().getKey();
@Nullable Object propertyInstance = propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas);
Expand All @@ -317,7 +316,7 @@ public AdditionalpropertiesAllowsASchemaWhichShouldValidateMap getNewInstance(Ma
return new AdditionalpropertiesAllowsASchemaWhichShouldValidateMap(castProperties);
}

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


@Override
public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
if (arg instanceof Map) {
return validate((Map<?, ?>) arg, configuration);
}
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
}
@Override
public @Nullable Object getNewInstance(@Nullable Object arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) throws InvalidTypeException {
public @Nullable Object getNewInstance(@Nullable Object arg, List<Object> pathToItem, PathToSchemasMap pathToSchemas) {
if (arg instanceof Map) {
return getNewInstance((Map<?, ?>) arg, pathToItem, pathToSchemas);
}
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema");
throw new RuntimeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema");
}
@Override
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap validateAndBox(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap validateAndBox(Map<?, ?> arg, SchemaConfiguration configuration) throws ValidationException {
return new AdditionalpropertiesAllowsASchemaWhichShouldValidate1BoxedMap(validate(arg, configuration));
}
@Override
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException, InvalidTypeException {
public AdditionalpropertiesAllowsASchemaWhichShouldValidate1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException {
if (arg instanceof Map<?, ?> castArg) {
return validateAndBox(castArg, configuration);
}
throw new InvalidTypeException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema");
}
}

Expand Down
Loading