@@ -28,10 +28,11 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
28
28
protected String implFolder = "service" ;
29
29
public static final String GOOGLE_CLOUD_FUNCTIONS = "googleCloudFunctions" ;
30
30
public static final String EXPORTED_NAME = "exportedName" ;
31
+ public static final String SERVER_PORT = "serverPort" ;
31
32
32
33
protected String apiVersion = "1.0.0" ;
33
- protected int serverPort = 8080 ;
34
34
protected String projectName = "swagger-server" ;
35
+ protected String defaultServerPort = "8080" ;
35
36
36
37
protected boolean googleCloudFunctions ;
37
38
protected String exportedName ;
@@ -82,7 +83,6 @@ public NodeJSServerCodegen() {
82
83
* are available in models, apis, and supporting files
83
84
*/
84
85
additionalProperties .put ("apiVersion" , apiVersion );
85
- additionalProperties .put ("serverPort" , serverPort );
86
86
additionalProperties .put ("implFolder" , implFolder );
87
87
88
88
supportingFiles .add (new SupportingFile ("writer.mustache" , ("utils" ).replace ("." , File .separator ), "writer.js" ));
@@ -96,6 +96,8 @@ public NodeJSServerCodegen() {
96
96
"When the generated code will be deployed to Google Cloud Functions, this option can be "
97
97
+ "used to update the name of the exported function. By default, it refers to the "
98
98
+ "basePath. This does not affect normal standalone nodejs server code." ));
99
+ cliOptions .add (new CliOption (SERVER_PORT ,
100
+ "TCP port to listen on." ));
99
101
}
100
102
101
103
@ Override
@@ -318,7 +320,7 @@ public void processOpts() {
318
320
@ Override
319
321
public void preprocessSwagger (Swagger swagger ) {
320
322
String host = swagger .getHost ();
321
- String port = "8080" ;
323
+ String port = defaultServerPort ;
322
324
323
325
if (!StringUtils .isEmpty (host )) {
324
326
String [] parts = host .split (":" );
@@ -331,7 +333,10 @@ public void preprocessSwagger(Swagger swagger) {
331
333
LOGGER .warn ("'host' in the specification is empty or undefined. Default to http://localhost." );
332
334
}
333
335
334
- this .additionalProperties .put ("serverPort" , port );
336
+ if (additionalProperties .containsKey (SERVER_PORT )) {
337
+ port = additionalProperties .get (SERVER_PORT ).toString ();
338
+ }
339
+ this .additionalProperties .put (SERVER_PORT , port );
335
340
336
341
if (swagger .getInfo () != null ) {
337
342
Info info = swagger .getInfo ();
0 commit comments