Process server port (#2782)

This commit is contained in:
sunn 2019-05-02 19:22:23 +02:00 committed by GitHub
parent 1c16d9a9e8
commit d112eea088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -17,11 +17,16 @@
package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.URLPathUtils;
import java.io.File;
import java.net.URL;
import static org.openapitools.codegen.utils.StringUtils.*;
@ -188,7 +193,14 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
}
return result;
}
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
URL url = URLPathUtils.getServerURL(openAPI);
String port = URLPathUtils.getPort(url, "8080");
this.additionalProperties.put("serverPort", port);
}
@Override
public String toApiFilename(String name) {
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";

View File

@ -53,6 +53,17 @@ To run the server
./build/src/cpp-qt5-qhttpengine-server &
```
To override the default port via the command line, provide the parameters `port` and `address` like below
```shell
cpp-qt5-qhttpengine-server --port 9080 --address 127.17.0.1
```
or
```shell
cpp-qt5-qhttpengine-server -p 9080 -a 127.17.0.1
```
#### Invoke an API
```shell

View File

@ -58,7 +58,7 @@ int main(int argc, char * argv[])
QStringList() << "p" << "port",
"port to listen on",
"port",
"8080"
"{{serverPort}}"
);
parser.addOption(portOption);
parser.addHelpOption();