Skip to content

Commit

Permalink
Adds path parameters serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
spacether committed Mar 6, 2024
1 parent ef5a3c5 commit ba1eb09
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 118 deletions.
1 change: 1 addition & 0 deletions samples/client/petstore/java/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ src/main/java/org/openapijsonschematools/client/parameter/Parameter.java
src/main/java/org/openapijsonschematools/client/parameter/ParameterBase.java
src/main/java/org/openapijsonschematools/client/parameter/ParameterInType.java
src/main/java/org/openapijsonschematools/client/parameter/ParameterStyle.java
src/main/java/org/openapijsonschematools/client/parameter/PathSerializer.java
src/main/java/org/openapijsonschematools/client/parameter/QuerySerializer.java
src/main/java/org/openapijsonschematools/client/parameter/SchemaParameter.java
src/main/java/org/openapijsonschematools/client/paths/anotherfakedummy/patch/RequestBody.java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.openapijsonschematools.client.parameter;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.AbstractMap;
import java.util.Map;

public abstract class PathSerializer {
private final Map<String, Parameter> parameters;

protected PathSerializer(Map<String, Parameter> parameters) {
this.parameters = parameters;
}

public String serialize(Map<String, ?> inData, String pathWithPlaceholders) {
String result = pathWithPlaceholders;
for (Map.Entry<String, ?> entry: inData.entrySet()) {
String mapKey = entry.getKey();
@Nullable Parameter parameter = parameters.get(mapKey);
if (parameter == null) {
throw new RuntimeException("Invalid state, a parameter must exist for every key");
}
@Nullable Object value = entry.getValue();
AbstractMap.SimpleEntry<String, String> serialized = parameter.serialize(value);
result = result.replace("{" + mapKey + "}", serialized.getValue());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.openapijsonschematools.client.paths.commonparamsubdir.delete.parameters.Parameter0;
import org.openapijsonschematools.client.paths.commonparamsubdir.delete.parameters.Parameter1;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;

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

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new Parameter1.Parameter11())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new Parameter1.Parameter11())
)
);
}

// deserialize PathParameters
}

public static class HeaderParametersSerializer extends HeadersSerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
)
);
}

// deserialize PathParameters
}

public static class QueryParametersSerializer extends QuerySerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.openapijsonschematools.client.paths.commonparamsubdir.parameters.RouteParameter0;
import org.openapijsonschematools.client.paths.commonparamsubdir.post.parameters.Parameter0;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;

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

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("subDir", new RouteParameter0.RouteParameter01())
)
);
}

// deserialize PathParameters
}

public static class HeaderParametersSerializer extends HeadersSerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter3;
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter4;
import org.openapijsonschematools.client.paths.fake.delete.parameters.Parameter5;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;
import org.openapijsonschematools.client.parameter.QuerySerializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter3;
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter4;
import org.openapijsonschematools.client.paths.fake.get.parameters.Parameter5;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;
import org.openapijsonschematools.client.parameter.QuerySerializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("id", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("id", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter16;
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter17;
import org.openapijsonschematools.client.paths.fakeparametercollisions1ababselfab.post.parameters.Parameter18;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;
import org.openapijsonschematools.client.parameter.QuerySerializer;
import org.openapijsonschematools.client.parameter.CookieSerializer;
Expand All @@ -30,20 +31,18 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("1", new Parameter9.Parameter91()),
new AbstractMap.SimpleEntry<>("aB", new Parameter10.Parameter101()),
new AbstractMap.SimpleEntry<>("Ab", new Parameter11.Parameter111()),
new AbstractMap.SimpleEntry<>("self", new Parameter12.Parameter121()),
new AbstractMap.SimpleEntry<>("A-B", new Parameter13.Parameter131())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("1", new Parameter9.Parameter91()),
new AbstractMap.SimpleEntry<>("aB", new Parameter10.Parameter101()),
new AbstractMap.SimpleEntry<>("Ab", new Parameter11.Parameter111()),
new AbstractMap.SimpleEntry<>("self", new Parameter12.Parameter121()),
new AbstractMap.SimpleEntry<>("A-B", new Parameter13.Parameter131())
)
);
}

// deserialize PathParameters
}

public static class QueryParametersSerializer extends QuerySerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.openapijsonschematools.client.paths.petpetid.delete.parameters.Parameter0;
import org.openapijsonschematools.client.paths.petpetid.delete.parameters.Parameter1;
import org.openapijsonschematools.client.parameter.PathSerializer;
import org.openapijsonschematools.client.parameter.HeadersSerializer;

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

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter1.Parameter11())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter1.Parameter11())
)
);
}

// deserialize PathParameters
}

public static class HeaderParametersSerializer extends HeadersSerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("petId", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("order_id", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class Parameters {

public static class PathParametersSerializer {
Map<String, Parameter> parameters;

public static class PathParametersSerializer extends PathSerializer {
public PathParametersSerializer() {
parameters = Map.ofEntries(
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
super(
Map.ofEntries(
new AbstractMap.SimpleEntry<>("", new Parameter0.Parameter01())
)
);
}

// deserialize PathParameters
}
}
Loading

0 comments on commit ba1eb09

Please sign in to comment.