fix string compare in haskell generator (#18410)

This commit is contained in:
William Cheng 2024-04-17 15:13:05 +08:00 committed by GitHub
parent dd97def5fa
commit 7609273a02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -333,13 +333,14 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
/** /**
* Internal method to set the generateToSchema parameter. * Internal method to set the generateToSchema parameter.
* * <p>
* Basically we're generating ToSchema instances (generically) for all schemas. * Basically we're generating ToSchema instances (generically) for all schemas.
* However, if any of the contained datatypes doesn't have the ToSchema instance, * However, if any of the contained datatypes doesn't have the ToSchema instance,
* we cannot generate it for its "ancestor" type. * we cannot generate it for its "ancestor" type.
* This is the case with the "Data.Aeson.Value" type: it doesn't (and cannot) have * This is the case with the "Data.Aeson.Value" type: it doesn't (and cannot) have
* a Swagger-compatible ToSchema instance. So we have to detect its presence "downstream" * a Swagger-compatible ToSchema instance. So we have to detect its presence "downstream"
* the current schema, and if we find it we just don't generate any ToSchema instance. * the current schema, and if we find it we just don't generate any ToSchema instance.
*
* @param model * @param model
*/ */
private void setGenerateToSchema(CodegenModel model) { private void setGenerateToSchema(CodegenModel model) {
@ -356,7 +357,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
List<CodegenModel> children = model.getChildren(); List<CodegenModel> children = model.getChildren();
if (children != null) { if (children != null) {
for(CodegenModel child : children) { for (CodegenModel child : children) {
setGenerateToSchema(child); setGenerateToSchema(child);
} }
} }
@ -512,7 +513,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
// Query parameters appended to routes // Query parameters appended to routes
for (CodegenParameter param : op.queryParams) { for (CodegenParameter param : op.queryParams) {
String paramType = param.dataType; String paramType = param.dataType;
if (param.contentType == "application/json") { if ("application/json".equals(param.contentType)) {
if (param.isArray) { if (param.isArray) {
paramType = "[JSONQueryParam " + paramType.substring(1, paramType.length() - 1) + "]"; paramType = "[JSONQueryParam " + paramType.substring(1, paramType.length() - 1) + "]";
} else { } else {
@ -554,7 +555,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
path.add("Header \"" + param.baseName + "\" " + param.dataType); path.add("Header \"" + param.baseName + "\" " + param.dataType);
String paramType = param.dataType; String paramType = param.dataType;
if (param.contentType == "application/json") { if ("application/json".equals(param.contentType)) {
if (param.isArray) { if (param.isArray) {
paramType = "(JSONQueryParam " + paramType.substring(1, paramType.length() - 1) + ")"; paramType = "(JSONQueryParam " + paramType.substring(1, paramType.length() - 1) + ")";
} else { } else {
@ -721,5 +722,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
} }
@Override @Override
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.HASKELL; } public GeneratorLanguage generatorLanguage() {
return GeneratorLanguage.HASKELL;
}
} }