[haskell-http-client] remove duplicates in produces/consumes; fix pathParam paramName issue (#273)

This commit is contained in:
Jon Schoning 2018-04-30 23:27:20 -05:00 committed by William Cheng
parent 0b3ec6b1f8
commit d3401396f5

View File

@ -807,6 +807,14 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
SetNoContent(op, X_INLINE_CONTENT_TYPE); SetNoContent(op, X_INLINE_CONTENT_TYPE);
} }
if (op.hasConsumes) { if (op.hasConsumes) {
// deduplicate
Map<String, Map<String, String>> consumes = new HashMap<>();
for (Map<String, String> m : op.consumes) {
consumes.put(m.get(MEDIA_TYPE), m);
}
op.consumes = new ArrayList<>(consumes.values());
// add metadata
for (Map<String, String> m : op.consumes) { for (Map<String, String> m : op.consumes) {
processMediaType(op, m); processMediaType(op, m);
processInlineConsumesContentType(op, m); processInlineConsumesContentType(op, m);
@ -817,6 +825,14 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
} }
} }
if (op.hasProduces) { if (op.hasProduces) {
// deduplicate
Map<String, Map<String, String>> produces = new HashMap<>();
for (Map<String, String> m : op.produces) {
produces.put(m.get(MEDIA_TYPE), m);
}
op.produces = new ArrayList<>(produces.values());
// add metadata
for (Map<String, String> m : op.produces) { for (Map<String, String> m : op.produces) {
processMediaType(op, m); processMediaType(op, m);
processInlineProducesContentType(op, m); processInlineProducesContentType(op, m);
@ -920,8 +936,10 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
private void processPathExpr(CodegenOperation op) { private void processPathExpr(CodegenOperation op) {
String xPath = "[\"" + escapeText(op.path) + "\"]"; String xPath = "[\"" + escapeText(op.path) + "\"]";
if (op.getHasPathParams()) { if (op.getHasPathParams()) {
for (CodegenParameter param : op.pathParams) { for (CodegenParameter param : op.allParams) {
xPath = xPath.replaceAll("\\{" + param.baseName + "\\}", "\",toPath " + param.paramName + ",\""); if(param.isPathParam) {
xPath = xPath.replaceAll("\\{" + param.baseName + "\\}", "\",toPath " + param.paramName + ",\"");
}
} }
xPath = xPath.replaceAll(",\"\",", ","); xPath = xPath.replaceAll(",\"\",", ",");
xPath = xPath.replaceAll("\"\",", ","); xPath = xPath.replaceAll("\"\",", ",");