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

Commit 8a99120

Browse files
authored
Java, adds ApiConfiguration (#381)
* Makes servers publics, adds imports in apiconfiguration * Adds Servers files * Adds java comment * Adds classes to store servers for each jsonPath including root servers * ServerInfo classes updated * Samples regen
1 parent f392968 commit 8a99120

File tree

50 files changed

+1016
-129
lines changed

Some content is hidden

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

50 files changed

+1016
-129
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ docs/components/schemas/UriReferenceFormat.md
8888
docs/components/schemas/UriTemplateFormat.md
8989
docs/servers/Server0.md
9090
pom.xml
91+
src/main/java/org/openapijsonschematools/client/RootServerInfo.java
9192
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesAllowsASchemaWhichShouldValidate.java
9293
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesAreAllowedByDefault.java
9394
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesCanExistByItself.java
@@ -175,6 +176,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/UniqueitemsVa
175176
src/main/java/org/openapijsonschematools/client/components/schemas/UriFormat.java
176177
src/main/java/org/openapijsonschematools/client/components/schemas/UriReferenceFormat.java
177178
src/main/java/org/openapijsonschematools/client/components/schemas/UriTemplateFormat.java
179+
src/main/java/org/openapijsonschematools/client/configurations/ApiConfiguration.java
178180
src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java
179181
src/main/java/org/openapijsonschematools/client/configurations/SchemaConfiguration.java
180182
src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java
@@ -277,7 +279,9 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsVa
277279
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
278280
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationData.java
279281
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMetadata.java
282+
src/main/java/org/openapijsonschematools/client/servers/Server.java
280283
src/main/java/org/openapijsonschematools/client/servers/Server0.java
284+
src/main/java/org/openapijsonschematools/client/servers/ServerProvider.java
281285
src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java
282286
src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java
283287
src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.openapijsonschematools.client;
2+
3+
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
4+
import org.openapijsonschematools.client.servers.Server0;
5+
import org.openapijsonschematools.client.servers.Server;
6+
import org.openapijsonschematools.client.servers.ServerProvider;
7+
import org.checkerframework.checker.nullness.qual.Nullable;
8+
9+
import java.util.AbstractMap;
10+
import java.util.Map;
11+
import java.util.Objects;
12+
import java.util.EnumMap;
13+
14+
public class RootServerInfo implements ServerProvider<RootServerInfo.ServerIndex> {
15+
final private Servers servers;
16+
final private ServerIndex serverIndex;
17+
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+
);
40+
}
41+
42+
public Servers(
43+
@Nullable Server0 server0
44+
) {
45+
servers = new EnumMap<>(
46+
Map.ofEntries(
47+
new AbstractMap.SimpleEntry<>(
48+
ServerIndex.SERVER_0,
49+
Objects.requireNonNullElseGet(server0, Server0::new)
50+
)
51+
)
52+
);
53+
}
54+
55+
public Server get(ServerIndex serverIndex) {
56+
if (servers.containsKey(serverIndex)) {
57+
return get(serverIndex);
58+
}
59+
throw new UnsetPropertyException(serverIndex+" is unset");
60+
}
61+
}
62+
63+
public enum ServerIndex {
64+
SERVER_0
65+
}
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+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.openapijsonschematools.client.configurations;
2+
3+
import org.openapijsonschematools.client.servers.Server;
4+
import org.openapijsonschematools.client.RootServerInfo;
5+
import org.checkerframework.checker.nullness.qual.Nullable;
6+
7+
import java.util.Objects;
8+
9+
public class ApiConfiguration {
10+
private final ServerInfo serverInfo;
11+
12+
public ApiConfiguration() {
13+
serverInfo = new ServerInfo();
14+
}
15+
16+
public ApiConfiguration(ServerInfo serverInfo) {
17+
this.serverInfo = serverInfo;
18+
}
19+
20+
public static class ServerInfo {
21+
protected final RootServerInfo rootServerInfo;
22+
23+
public ServerInfo() {
24+
rootServerInfo = new RootServerInfo();
25+
}
26+
27+
public ServerInfo(
28+
@Nullable RootServerInfo rootServerInfo
29+
) {
30+
this.rootServerInfo = Objects.requireNonNullElseGet(rootServerInfo, RootServerInfo::new);
31+
}
32+
}
33+
34+
public Server getServer(RootServerInfo. @Nullable ServerIndex serverIndex) {
35+
return serverInfo.rootServerInfo.getServer(serverIndex);
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openapijsonschematools.client.servers;
2+
3+
public interface Server {
4+
String url();
5+
}
6+

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/servers/Server0.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.openapijsonschematools.client.servers.ServerWithoutVariables;
44

5-
class Server0 extends ServerWithoutVariables {
5+
public class Server0 extends ServerWithoutVariables {
66
public Server0() {
77
super("https://someserver.com/v1");
88
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.openapijsonschematools.client.servers;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
5+
public interface ServerProvider<T> {
6+
Server getServer(@Nullable T serverIndex);
7+
}
8+

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.Map;
44

5-
public abstract class ServerWithVariables<T extends Map<String, String>> {
5+
public abstract class ServerWithVariables<T extends Map<String, String>> implements Server {
66
public final String url;
77
public final T variables;
88

@@ -13,5 +13,9 @@ protected ServerWithVariables(String url, T variables) {
1313
}
1414
this.url = url;
1515
}
16+
17+
public String url(){
18+
return url;
19+
}
1620
}
1721

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.openapijsonschematools.client.servers;
22

3-
public abstract class ServerWithoutVariables {
3+
public abstract class ServerWithoutVariables implements Server {
44
public final String url;
55

66
protected ServerWithoutVariables(String url) {
77
this.url = url;
88
}
9+
10+
public String url(){
11+
return url;
12+
}
913
}
1014

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

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ docs/components/schemas/UuidFormat.md
144144
docs/components/schemas/ValidateAgainstCorrectBranchThenVsElse.md
145145
docs/servers/Server0.md
146146
pom.xml
147+
src/main/java/org/openapijsonschematools/client/RootServerInfo.java
147148
src/main/java/org/openapijsonschematools/client/components/schemas/ASchemaGivenForPrefixitems.java
148149
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalItemsAreAllowedByDefault.java
149150
src/main/java/org/openapijsonschematools/client/components/schemas/AdditionalpropertiesAreAllowedByDefault.java
@@ -287,6 +288,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/UriReferenceF
287288
src/main/java/org/openapijsonschematools/client/components/schemas/UriTemplateFormat.java
288289
src/main/java/org/openapijsonschematools/client/components/schemas/UuidFormat.java
289290
src/main/java/org/openapijsonschematools/client/components/schemas/ValidateAgainstCorrectBranchThenVsElse.java
291+
src/main/java/org/openapijsonschematools/client/configurations/ApiConfiguration.java
290292
src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java
291293
src/main/java/org/openapijsonschematools/client/configurations/SchemaConfiguration.java
292294
src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java
@@ -389,7 +391,9 @@ src/main/java/org/openapijsonschematools/client/schemas/validation/UniqueItemsVa
389391
src/main/java/org/openapijsonschematools/client/schemas/validation/UnsetAnyTypeJsonSchema.java
390392
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationData.java
391393
src/main/java/org/openapijsonschematools/client/schemas/validation/ValidationMetadata.java
394+
src/main/java/org/openapijsonschematools/client/servers/Server.java
392395
src/main/java/org/openapijsonschematools/client/servers/Server0.java
396+
src/main/java/org/openapijsonschematools/client/servers/ServerProvider.java
393397
src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java
394398
src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java
395399
src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.openapijsonschematools.client;
2+
3+
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
4+
import org.openapijsonschematools.client.servers.Server0;
5+
import org.openapijsonschematools.client.servers.Server;
6+
import org.openapijsonschematools.client.servers.ServerProvider;
7+
import org.checkerframework.checker.nullness.qual.Nullable;
8+
9+
import java.util.AbstractMap;
10+
import java.util.Map;
11+
import java.util.Objects;
12+
import java.util.EnumMap;
13+
14+
public class RootServerInfo implements ServerProvider<RootServerInfo.ServerIndex> {
15+
final private Servers servers;
16+
final private ServerIndex serverIndex;
17+
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+
);
40+
}
41+
42+
public Servers(
43+
@Nullable Server0 server0
44+
) {
45+
servers = new EnumMap<>(
46+
Map.ofEntries(
47+
new AbstractMap.SimpleEntry<>(
48+
ServerIndex.SERVER_0,
49+
Objects.requireNonNullElseGet(server0, Server0::new)
50+
)
51+
)
52+
);
53+
}
54+
55+
public Server get(ServerIndex serverIndex) {
56+
if (servers.containsKey(serverIndex)) {
57+
return get(serverIndex);
58+
}
59+
throw new UnsetPropertyException(serverIndex+" is unset");
60+
}
61+
}
62+
63+
public enum ServerIndex {
64+
SERVER_0
65+
}
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+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.openapijsonschematools.client.configurations;
2+
3+
import org.openapijsonschematools.client.servers.Server;
4+
import org.openapijsonschematools.client.RootServerInfo;
5+
import org.checkerframework.checker.nullness.qual.Nullable;
6+
7+
import java.util.Objects;
8+
9+
public class ApiConfiguration {
10+
private final ServerInfo serverInfo;
11+
12+
public ApiConfiguration() {
13+
serverInfo = new ServerInfo();
14+
}
15+
16+
public ApiConfiguration(ServerInfo serverInfo) {
17+
this.serverInfo = serverInfo;
18+
}
19+
20+
public static class ServerInfo {
21+
protected final RootServerInfo rootServerInfo;
22+
23+
public ServerInfo() {
24+
rootServerInfo = new RootServerInfo();
25+
}
26+
27+
public ServerInfo(
28+
@Nullable RootServerInfo rootServerInfo
29+
) {
30+
this.rootServerInfo = Objects.requireNonNullElseGet(rootServerInfo, RootServerInfo::new);
31+
}
32+
}
33+
34+
public Server getServer(RootServerInfo. @Nullable ServerIndex serverIndex) {
35+
return serverInfo.rootServerInfo.getServer(serverIndex);
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openapijsonschematools.client.servers;
2+
3+
public interface Server {
4+
String url();
5+
}
6+

samples/client/3_1_0_unit_test/java/src/main/java/org/openapijsonschematools/client/servers/Server0.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.openapijsonschematools.client.servers.ServerWithoutVariables;
44

5-
class Server0 extends ServerWithoutVariables {
5+
public class Server0 extends ServerWithoutVariables {
66
public Server0() {
77
super("https://someserver.com/v1");
88
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.openapijsonschematools.client.servers;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
5+
public interface ServerProvider<T> {
6+
Server getServer(@Nullable T serverIndex);
7+
}
8+

samples/client/3_1_0_unit_test/java/src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.Map;
44

5-
public abstract class ServerWithVariables<T extends Map<String, String>> {
5+
public abstract class ServerWithVariables<T extends Map<String, String>> implements Server {
66
public final String url;
77
public final T variables;
88

@@ -13,5 +13,9 @@ protected ServerWithVariables(String url, T variables) {
1313
}
1414
this.url = url;
1515
}
16+
17+
public String url(){
18+
return url;
19+
}
1620
}
1721

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.openapijsonschematools.client.servers;
22

3-
public abstract class ServerWithoutVariables {
3+
public abstract class ServerWithoutVariables implements Server {
44
public final String url;
55

66
protected ServerWithoutVariables(String url) {
77
this.url = url;
88
}
9+
10+
public String url(){
11+
return url;
12+
}
913
}
1014

0 commit comments

Comments
 (0)