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

Commit ba1eb09

Browse files
committed
Adds path parameters serializer
1 parent ef5a3c5 commit ba1eb09

File tree

22 files changed

+156
-118
lines changed

22 files changed

+156
-118
lines changed

samples/client/petstore/java/.openapi-generator/FILES

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ src/main/java/org/openapijsonschematools/client/parameter/Parameter.java
563563
src/main/java/org/openapijsonschematools/client/parameter/ParameterBase.java
564564
src/main/java/org/openapijsonschematools/client/parameter/ParameterInType.java
565565
src/main/java/org/openapijsonschematools/client/parameter/ParameterStyle.java
566+
src/main/java/org/openapijsonschematools/client/parameter/PathSerializer.java
566567
src/main/java/org/openapijsonschematools/client/parameter/QuerySerializer.java
567568
src/main/java/org/openapijsonschematools/client/parameter/SchemaParameter.java
568569
src/main/java/org/openapijsonschematools/client/paths/anotherfakedummy/patch/RequestBody.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapijsonschematools.client.parameter;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
5+
import java.util.AbstractMap;
6+
import java.util.Map;
7+
8+
public abstract class PathSerializer {
9+
private final Map<String, Parameter> parameters;
10+
11+
protected PathSerializer(Map<String, Parameter> parameters) {
12+
this.parameters = parameters;
13+
}
14+
15+
public String serialize(Map<String, ?> inData, String pathWithPlaceholders) {
16+
String result = pathWithPlaceholders;
17+
for (Map.Entry<String, ?> entry: inData.entrySet()) {
18+
String mapKey = entry.getKey();
19+
@Nullable Parameter parameter = parameters.get(mapKey);
20+
if (parameter == null) {
21+
throw new RuntimeException("Invalid state, a parameter must exist for every key");
22+
}
23+
@Nullable Object value = entry.getValue();
24+
AbstractMap.SimpleEntry<String, String> serialized = parameter.serialize(value);
25+
result = result.replace("{" + mapKey + "}", serialized.getValue());
26+
}
27+
return result;
28+
}
29+
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/commonparamsubdir/delete/Parameters.java

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

33
import org.openapijsonschematools.client.paths.commonparamsubdir.delete.parameters.Parameter0;
44
import org.openapijsonschematools.client.paths.commonparamsubdir.delete.parameters.Parameter1;
5+
import org.openapijsonschematools.client.parameter.PathSerializer;
56
import org.openapijsonschematools.client.parameter.HeadersSerializer;
67

78
import org.openapijsonschematools.client.parameter.Parameter;
@@ -11,16 +12,14 @@
1112

1213
public class Parameters {
1314

14-
public static class PathParametersSerializer {
15-
Map<String, Parameter> parameters;
16-
15+
public static class PathParametersSerializer extends PathSerializer {
1716
public PathParametersSerializer() {
18-
parameters = Map.ofEntries(
19-
new AbstractMap.SimpleEntry<>("subDir", new Parameter1.Parameter11())
17+
super(
18+
Map.ofEntries(
19+
new AbstractMap.SimpleEntry<>("subDir", new Parameter1.Parameter11())
20+
)
2021
);
2122
}
22-
23-
// deserialize PathParameters
2423
}
2524

2625
public static class HeaderParametersSerializer extends HeadersSerializer {

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/commonparamsubdir/get/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111

1212
public class Parameters {
1313

14-
public static class PathParametersSerializer {
15-
Map<String, Parameter> parameters;
16-
14+
public static class PathParametersSerializer extends PathSerializer {
1715
public PathParametersSerializer() {
18-
parameters = Map.ofEntries(
19-
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
16+
super(
17+
Map.ofEntries(
18+
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
19+
)
2020
);
2121
}
22-
23-
// deserialize PathParameters
2422
}
2523

2624
public static class QueryParametersSerializer extends QuerySerializer {

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/commonparamsubdir/post/Parameters.java

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

33
import org.openapijsonschematools.client.paths.commonparamsubdir.parameters.RouteParameter0;
44
import org.openapijsonschematools.client.paths.commonparamsubdir.post.parameters.Parameter0;
5+
import org.openapijsonschematools.client.parameter.PathSerializer;
56
import org.openapijsonschematools.client.parameter.HeadersSerializer;
67

78
import org.openapijsonschematools.client.parameter.Parameter;
@@ -11,16 +12,14 @@
1112

1213
public class Parameters {
1314

14-
public static class PathParametersSerializer {
15-
Map<String, Parameter> parameters;
16-
15+
public static class PathParametersSerializer extends PathSerializer {
1716
public PathParametersSerializer() {
18-
parameters = Map.ofEntries(
19-
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
17+
super(
18+
Map.ofEntries(
19+
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
20+
)
2021
);
2122
}
22-
23-
// deserialize PathParameters
2423
}
2524

2625
public static class HeaderParametersSerializer extends HeadersSerializer {

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/fake/delete/Parameters.java

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter3;
77
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter4;
88
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter5;
9+
import org.openapijsonschematools.client.parameter.PathSerializer;
910
import org.openapijsonschematools.client.parameter.HeadersSerializer;
1011
import org.openapijsonschematools.client.parameter.QuerySerializer;
1112

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/fake/get/Parameters.java

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter3;
77
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter4;
88
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter5;
9+
import org.openapijsonschematools.client.parameter.PathSerializer;
910
import org.openapijsonschematools.client.parameter.HeadersSerializer;
1011
import org.openapijsonschematools.client.parameter.QuerySerializer;
1112

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/fakedeletecoffeeid/delete/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("id", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("id", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/fakeparametercollisions1ababselfab/post/Parameters.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter16;
2020
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter17;
2121
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter18;
22+
import org.openapijsonschematools.client.parameter.PathSerializer;
2223
import org.openapijsonschematools.client.parameter.HeadersSerializer;
2324
import org.openapijsonschematools.client.parameter.QuerySerializer;
2425
import org.openapijsonschematools.client.parameter.CookieSerializer;
@@ -30,20 +31,18 @@
3031

3132
public class Parameters {
3233

33-
public static class PathParametersSerializer {
34-
Map<String, Parameter> parameters;
35-
34+
public static class PathParametersSerializer extends PathSerializer {
3635
public PathParametersSerializer() {
37-
parameters = Map.ofEntries(
38-
new AbstractMap.SimpleEntry<>("1", new Parameter9.Parameter91()),
39-
new AbstractMap.SimpleEntry<>("aB", new Parameter10.Parameter101()),
40-
new AbstractMap.SimpleEntry<>("Ab", new Parameter11.Parameter111()),
41-
new AbstractMap.SimpleEntry<>("self", new Parameter12.Parameter121()),
42-
new AbstractMap.SimpleEntry<>("A-B", new Parameter13.Parameter131())
36+
super(
37+
Map.ofEntries(
38+
new AbstractMap.SimpleEntry<>("1", new Parameter9.Parameter91()),
39+
new AbstractMap.SimpleEntry<>("aB", new Parameter10.Parameter101()),
40+
new AbstractMap.SimpleEntry<>("Ab", new Parameter11.Parameter111()),
41+
new AbstractMap.SimpleEntry<>("self", new Parameter12.Parameter121()),
42+
new AbstractMap.SimpleEntry<>("A-B", new Parameter13.Parameter131())
43+
)
4344
);
4445
}
45-
46-
// deserialize PathParameters
4746
}
4847

4948
public static class QueryParametersSerializer extends QuerySerializer {

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/fakepetiduploadimagewithrequiredfile/post/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/petpetid/delete/Parameters.java

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

33
import org.openapijsonschematools.client.paths.petpetid.delete.parameters.Parameter0;
44
import org.openapijsonschematools.client.paths.petpetid.delete.parameters.Parameter1;
5+
import org.openapijsonschematools.client.parameter.PathSerializer;
56
import org.openapijsonschematools.client.parameter.HeadersSerializer;
67

78
import org.openapijsonschematools.client.parameter.Parameter;
@@ -11,16 +12,14 @@
1112

1213
public class Parameters {
1314

14-
public static class PathParametersSerializer {
15-
Map<String, Parameter> parameters;
16-
15+
public static class PathParametersSerializer extends PathSerializer {
1716
public PathParametersSerializer() {
18-
parameters = Map.ofEntries(
19-
new AbstractMap.SimpleEntry<>("petId", new Parameter1.Parameter11())
17+
super(
18+
Map.ofEntries(
19+
new AbstractMap.SimpleEntry<>("petId", new Parameter1.Parameter11())
20+
)
2021
);
2122
}
22-
23-
// deserialize PathParameters
2423
}
2524

2625
public static class HeaderParametersSerializer extends HeadersSerializer {

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/petpetid/get/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/petpetid/post/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/petpetiduploadimage/post/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/storeorderorderid/delete/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/storeorderorderid/get/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/userusername/delete/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/paths/userusername/get/Parameters.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
public class Parameters {
1111

12-
public static class PathParametersSerializer {
13-
Map<String, Parameter> parameters;
14-
12+
public static class PathParametersSerializer extends PathSerializer {
1513
public PathParametersSerializer() {
16-
parameters = Map.ofEntries(
17-
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
14+
super(
15+
Map.ofEntries(
16+
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
17+
)
1818
);
1919
}
20-
21-
// deserialize PathParameters
2220
}
2321
}

0 commit comments

Comments
 (0)