Skip to content

Commit 54a6c79

Browse files
authored
[NodeJS] Auto populate config using schema servers.url (#6980)
* [NodeJS] nodejs-express-server fix /api-docs path * Auto populate config using schema servers.url * [NodeJS] Auto populate config port 3000
1 parent 1dc65f0 commit 54a6c79

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class NodeJSExpressServerCodegen extends DefaultCodegen implements Codege
4646

4747
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSExpressServerCodegen.class);
4848
public static final String EXPORTED_NAME = "exportedName";
49+
public static final String SERVER_HOST = "serverHost";
4950
public static final String SERVER_PORT = "serverPort";
5051

5152
protected String apiVersion = "1.0.0";
@@ -334,6 +335,11 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
334335
String port = URLPathUtils.getPort(url, defaultServerPort);
335336
String basePath = url.getPath();
336337

338+
if (additionalProperties.containsKey(SERVER_HOST)) {
339+
host = additionalProperties.get(SERVER_HOST).toString();
340+
}
341+
this.additionalProperties.put(SERVER_HOST, host);
342+
337343
if (additionalProperties.containsKey(SERVER_PORT)) {
338344
port = additionalProperties.get(SERVER_PORT).toString();
339345
}

modules/openapi-generator/src/main/resources/nodejs-express-server/config.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const path = require('path');
22

33
const config = {
44
ROOT_DIR: __dirname,
5-
URL_PORT: 3000,
6-
URL_PATH: 'http://localhost',
7-
BASE_VERSION: 'v2',
5+
URL_PORT: {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}3000{{/serverPort}},
6+
URL_PATH: '{{#serverHost}}{{serverHost}}{{/serverHost}}{{^serverHost}}http://localhost{{/serverHost}}',
7+
BASE_VERSION: '{{#contextPath}}{{contextPath}}{{/contextPath}}{{^contextPath}}v2{{/contextPath}}',
88
CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'),
99
PROJECT_DIR: __dirname,
1010
};

0 commit comments

Comments
 (0)