mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Improvements on scala http4s server generator (#17693)
* improvements on scala https server generator * trigger dockerfile build
This commit is contained in:
parent
6a8ca1018f
commit
f31164b569
@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||||
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -66,7 +68,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
supportsMultipleInheritance = true;
|
supportsMultipleInheritance = true;
|
||||||
supportsInheritance = true;
|
supportsInheritance = true;
|
||||||
supportsMixins = true;
|
supportsMixins = true;
|
||||||
addOneOfInterfaceImports =true;
|
addOneOfInterfaceImports = true;
|
||||||
|
|
||||||
|
|
||||||
setReservedWordsLowerCase(
|
setReservedWordsLowerCase(
|
||||||
@ -141,7 +143,6 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
languageSpecificPrimitives = new HashSet<>(
|
languageSpecificPrimitives = new HashSet<>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"String",
|
"String",
|
||||||
@ -197,6 +198,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Map<String, String> locationStatusToResponse = new HashMap<>();
|
private final static Map<String, String> locationStatusToResponse = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
locationStatusToResponse.put("300", "MultipleChoices");
|
locationStatusToResponse.put("300", "MultipleChoices");
|
||||||
locationStatusToResponse.put("301", "MovedPermanently");
|
locationStatusToResponse.put("301", "MovedPermanently");
|
||||||
@ -207,16 +209,19 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final static Map<String, String> wwwAuthStatusToResponse = new HashMap<>();
|
private final static Map<String, String> wwwAuthStatusToResponse = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
wwwAuthStatusToResponse.put("401", "Unauthorized");
|
wwwAuthStatusToResponse.put("401", "Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Map<String, String> allowStatusToResponse = new HashMap<>();
|
private final static Map<String, String> allowStatusToResponse = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
allowStatusToResponse.put("405", "MethodNotAllowed");
|
allowStatusToResponse.put("405", "MethodNotAllowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Map<String, String> proxyAuthStatusToResponse = new HashMap<>();
|
private final static Map<String, String> proxyAuthStatusToResponse = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
proxyAuthStatusToResponse.put("407", "ProxyAuthenticationRequired");
|
proxyAuthStatusToResponse.put("407", "ProxyAuthenticationRequired");
|
||||||
}
|
}
|
||||||
@ -314,7 +319,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
apiTemplateFiles.put("api.mustache", ".scala");
|
apiTemplateFiles.put("api.mustache", ".scala");
|
||||||
|
|
||||||
if (!additionalProperties.containsKey(EXCLUDE_SBT) && !Boolean.parseBoolean((String)additionalProperties.get(EXCLUDE_SBT))) {
|
if (!additionalProperties.containsKey(EXCLUDE_SBT) && !Boolean.parseBoolean((String) additionalProperties.get(EXCLUDE_SBT))) {
|
||||||
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
|
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
|
||||||
supportingFiles.add(new SupportingFile("build.properties", "project", "build.properties"));
|
supportingFiles.add(new SupportingFile("build.properties", "project", "build.properties"));
|
||||||
}
|
}
|
||||||
@ -328,18 +333,18 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnablePostProcessFile() {
|
public boolean isEnablePostProcessFile() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessFile(File file, String fileType) {
|
public void postProcessFile(File file, String fileType) {
|
||||||
System.out.println("postprocess " + file.toString());
|
LOGGER.debug("postprocess " + file.toString());
|
||||||
super.postProcessFile(file, fileType);
|
super.postProcessFile(file, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
|
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
|
||||||
Map<String, ModelsMap> modelsMap = super.postProcessAllModels(objs);
|
Map<String, ModelsMap> modelsMap = super.postProcessAllModels(objs);
|
||||||
|
|
||||||
for (ModelsMap mm : modelsMap.values()) {
|
for (ModelsMap mm : modelsMap.values()) {
|
||||||
for (ModelMap model : mm.getModels()) {
|
for (ModelMap model : mm.getModels()) {
|
||||||
@ -367,7 +372,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
// add refined constraints
|
// add refined constraints
|
||||||
|
|
||||||
for (CodegenProperty prop: cModel.vars) {
|
for (CodegenProperty prop : cModel.vars) {
|
||||||
Set<String> imports = new TreeSet<>();
|
Set<String> imports = new TreeSet<>();
|
||||||
|
|
||||||
prop.getVendorExtensions().putAll(refineProp(prop, imports));
|
prop.getVendorExtensions().putAll(refineProp(prop, imports));
|
||||||
@ -389,8 +394,8 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
vendorExtensions.put("x-type", "Refined[" + dataType + ", " + refinedRgt + "]");
|
vendorExtensions.put("x-type", "Refined[" + dataType + ", " + refinedRgt + "]");
|
||||||
vendorExtensions.put("x-refined-lft", dataType);
|
vendorExtensions.put("x-refined-lft", dataType);
|
||||||
vendorExtensions.put("x-refined-rgt", refinedRgt);
|
vendorExtensions.put("x-refined-rgt", refinedRgt);
|
||||||
vendorExtensions.put("x-refined", true);
|
vendorExtensions.put("x-refined", true);
|
||||||
} else {
|
} else {
|
||||||
vendorExtensions.put("x-type", dataType);
|
vendorExtensions.put("x-type", dataType);
|
||||||
}
|
}
|
||||||
@ -407,8 +412,8 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
ArrayList<String> refined = new ArrayList<>();
|
ArrayList<String> refined = new ArrayList<>();
|
||||||
|
|
||||||
if (prop.getMinLength() != null) {
|
if (prop.getMinLength() != null) {
|
||||||
refined.add("MinSize[" + prop.getMinLength() + "]");
|
refined.add("MinSize[" + prop.getMinLength() + "]");
|
||||||
imports.add("MinSize");
|
imports.add("MinSize");
|
||||||
}
|
}
|
||||||
if (prop.getMaxLength() != null) {
|
if (prop.getMaxLength() != null) {
|
||||||
refined.add("MaxSize[" + prop.getMaxLength() + "]");
|
refined.add("MaxSize[" + prop.getMaxLength() + "]");
|
||||||
@ -485,7 +490,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
List<ModelMap> models = (List<ModelMap>) bundle.get("models");
|
List<ModelMap> models = (List<ModelMap>) bundle.get("models");
|
||||||
TreeSet<String> allImports = new TreeSet<>();
|
TreeSet<String> allImports = new TreeSet<>();
|
||||||
for (ModelMap mm: models) {
|
for (ModelMap mm : models) {
|
||||||
for (String nextImport : mm.getModel().imports) {
|
for (String nextImport : mm.getModel().imports) {
|
||||||
String mapping = importMapping().get(nextImport);
|
String mapping = importMapping().get(nextImport);
|
||||||
if (mapping != null && !defaultIncludes().contains(mapping)) {
|
if (mapping != null && !defaultIncludes().contains(mapping)) {
|
||||||
@ -504,9 +509,9 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
ApiInfoMap apiInfoMap = (ApiInfoMap) bundle.get("apiInfo");
|
ApiInfoMap apiInfoMap = (ApiInfoMap) bundle.get("apiInfo");
|
||||||
Map<String, List<String>> authToOperationMap = new TreeMap<>();
|
Map<String, List<String>> authToOperationMap = new TreeMap<>();
|
||||||
for (OperationsMap op: apiInfoMap.getApis()) {
|
for (OperationsMap op : apiInfoMap.getApis()) {
|
||||||
List<HashMap<String, Object>> opsByAuth = (List<HashMap<String, Object>>) op.get("operationsByAuth");
|
List<HashMap<String, Object>> opsByAuth = (List<HashMap<String, Object>>) op.get("operationsByAuth");
|
||||||
for (HashMap<String, Object> auth: opsByAuth) {
|
for (HashMap<String, Object> auth : opsByAuth) {
|
||||||
String autName = (String) auth.get("auth");
|
String autName = (String) auth.get("auth");
|
||||||
String classname = (String) op.get("classname");
|
String classname = (String) op.get("classname");
|
||||||
List<String> classnames = authToOperationMap.computeIfAbsent(autName, k -> new ArrayList<>());
|
List<String> classnames = authToOperationMap.computeIfAbsent(autName, k -> new ArrayList<>());
|
||||||
@ -549,7 +554,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + File.separator + apiFileFolderRelative() ;
|
return outputFolder + File.separator + apiFileFolderRelative();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String apiFileFolderRelative() {
|
private String apiFileFolderRelative() {
|
||||||
@ -599,7 +604,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decide wat methods do we need in responses:
|
// decide wat methods do we need in responses:
|
||||||
for (CodegenResponse resp: op.responses) {
|
for (CodegenResponse resp : op.responses) {
|
||||||
if (resp.code.equals("0"))
|
if (resp.code.equals("0"))
|
||||||
resp.code = "200"; // 200 by default
|
resp.code = "200"; // 200 by default
|
||||||
|
|
||||||
@ -649,11 +654,11 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (op.authMethods != null) {
|
if (op.authMethods != null) {
|
||||||
for (CodegenSecurity cs: op.authMethods) {
|
for (CodegenSecurity cs : op.authMethods) {
|
||||||
allAuth.add(cs.name);
|
allAuth.add(cs.name);
|
||||||
}
|
}
|
||||||
List<Map<String, Object>> authDup = new ArrayList<>();
|
List<Map<String, Object>> authDup = new ArrayList<>();
|
||||||
for (CodegenSecurity authMeth: op.authMethods) {
|
for (CodegenSecurity authMeth : op.authMethods) {
|
||||||
Map<String, Object> vals = new HashMap<>();
|
Map<String, Object> vals = new HashMap<>();
|
||||||
vals.put("authName", authMeth.name);
|
vals.put("authName", authMeth.name);
|
||||||
vals.put("operation", op);
|
vals.put("operation", op);
|
||||||
@ -781,7 +786,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
op.imports.addAll(imports);
|
op.imports.addAll(imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cpToPathParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
|
private String cpToPathParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
|
||||||
// don't support containers and arrays yet, reset to string
|
// don't support containers and arrays yet, reset to string
|
||||||
if (cp.isContainer || cp.isArray) {
|
if (cp.isContainer || cp.isArray) {
|
||||||
cp.setDataType("String");
|
cp.setDataType("String");
|
||||||
@ -809,20 +814,20 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
String queryString = "";
|
String queryString = "";
|
||||||
|
|
||||||
for (CodegenParameter cp : op.queryParams) {
|
for (CodegenParameter cp : op.queryParams) {
|
||||||
if (queryString.isEmpty()) {
|
if (queryString.isEmpty()) {
|
||||||
queryString = queryString + " :? ";
|
queryString = queryString + " :? ";
|
||||||
} else {
|
} else {
|
||||||
queryString = queryString + " +& ";
|
queryString = queryString + " +& ";
|
||||||
}
|
}
|
||||||
|
|
||||||
queryString = queryString + cpToQueryParameter(cp, imports, cp.vendorExtensions);
|
queryString = queryString + cpToQueryParameter(cp, imports, cp.vendorExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
op.vendorExtensions.put("x-codegen-query", queryString);
|
op.vendorExtensions.put("x-codegen-query", queryString);
|
||||||
op.imports.addAll(imports);
|
op.imports.addAll(imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cpToQueryParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
|
private String cpToQueryParameter(CodegenParameter cp, Set<String> imports, Map<String, Object> vendorExtensions) {
|
||||||
// don't support containers and arrays yet, reset to string
|
// don't support containers and arrays yet, reset to string
|
||||||
if (cp.isContainer && !cp.isArray) {
|
if (cp.isContainer && !cp.isArray) {
|
||||||
cp.setDataType("String");
|
cp.setDataType("String");
|
||||||
@ -848,5 +853,7 @@ public class ScalaHttp4sServerCodegen extends DefaultCodegen implements CodegenC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.SCALA; }
|
public GeneratorLanguage generatorLanguage() {
|
||||||
|
return GeneratorLanguage.SCALA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -414,7 +414,6 @@
|
|||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>release</id>
|
<id>release</id>
|
||||||
<build>
|
<build>
|
||||||
@ -447,7 +446,6 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>release-sign-artifacts</id>
|
<id>release-sign-artifacts</id>
|
||||||
<activation>
|
<activation>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user