Skip to content

Commit

Permalink
Fix nodejs-server path issue in windows platform (#7808)
Browse files Browse the repository at this point in the history
* fix nodejs-server path issue in windows platform

* only replace character in apiPackage
  • Loading branch information
wing328 authored Mar 12, 2018
1 parent 1bb1e44 commit e7f4fb3
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3324,7 +3324,7 @@ public static String camelize(String word, boolean lowercaseFirstLetter) {

public String apiFilename(String templateName, String tag) {
String suffix = apiTemplateFiles().get(templateName);
return apiFileFolder() + '/' + toApiFilename(tag) + suffix;
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
}

/**
Expand All @@ -3337,7 +3337,7 @@ public String apiFilename(String templateName, String tag) {
*/
public String apiDocFilename(String templateName, String tag) {
String suffix = apiDocTemplateFiles().get(templateName);
return apiDocFileFolder() + '/' + toApiDocFilename(tag) + suffix;
return apiDocFileFolder() + File.separator + toApiDocFilename(tag) + suffix;
}

/**
Expand All @@ -3350,7 +3350,7 @@ public String apiDocFilename(String templateName, String tag) {
*/
public String apiTestFilename(String templateName, String tag) {
String suffix = apiTestTemplateFiles().get(templateName);
return apiTestFileFolder() + '/' + toApiTestFilename(tag) + suffix;
return apiTestFileFolder() + File.separator + toApiTestFilename(tag) + suffix;
}

public boolean shouldOverwrite(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public NodeJSServerCodegen() {
additionalProperties.put("serverPort", serverPort);
additionalProperties.put("implFolder", implFolder);

supportingFiles.add(new SupportingFile("writer.mustache", ("utils").replace(".", "/"), "writer.js"));
supportingFiles.add(new SupportingFile("writer.mustache", ("utils").replace(".", File.separator), "writer.js"));

cliOptions.add(CliOption.newBoolean(GOOGLE_CLOUD_FUNCTIONS,
"When specified, it will generate the code which runs within Google Cloud Functions "
Expand Down Expand Up @@ -164,7 +164,7 @@ public String apiFilename(String templateName, String tag) {
}

private String implFileFolder(String output) {
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
return outputFolder + File.separator + output + File.separator + apiPackage().replace('.', File.separatorChar);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ info:
license:
name: "Apache-2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
Expand Down Expand Up @@ -524,7 +525,7 @@ paths:
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing. "
description: "The name that needs to be fetched. Use user1 for testing."
required: true
type: "string"
responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports.deleteUser = function(username) {
* Get user by user name
*
*
* username String The name that needs to be fetched. Use user1 for testing.
* username String The name that needs to be fetched. Use user1 for testing.
* returns User
**/
exports.getUserByName = function(username) {
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/nodejs/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3-SNAPSHOT
2.4.0-SNAPSHOT
48 changes: 45 additions & 3 deletions samples/server/petstore/nodejs/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ info:
contact:
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
name: "Apache-2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
Expand Down Expand Up @@ -108,11 +108,11 @@ paths:
type: "array"
items:
type: "string"
default: "available"
enum:
- "available"
- "pending"
- "sold"
default: "available"
collectionFormat: "csv"
responses:
200:
Expand Down Expand Up @@ -161,6 +161,7 @@ paths:
- petstore_auth:
- "write:pets"
- "read:pets"
deprecated: true
x-swagger-router-controller: "Pet"
/pet/{petId}:
get:
Expand Down Expand Up @@ -524,7 +525,7 @@ paths:
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing. "
description: "The name that needs to be fetched. Use user1 for testing."
required: true
type: "string"
responses:
Expand Down Expand Up @@ -625,6 +626,13 @@ definitions:
default: false
title: "Pet Order"
description: "An order for a pets from the pet store"
example:
petId: 6
quantity: 1
id: 0
shipDate: "2000-01-23T04:56:07.000+00:00"
complete: false
status: "placed"
xml:
name: "Order"
Category:
Expand All @@ -637,6 +645,9 @@ definitions:
type: "string"
title: "Pet category"
description: "A category for a pet"
example:
name: "name"
id: 6
xml:
name: "Category"
User:
Expand All @@ -663,6 +674,15 @@ definitions:
description: "User Status"
title: "a User"
description: "A User who is purchasing from the pet store"
example:
firstName: "firstName"
lastName: "lastName"
password: "password"
userStatus: 6
phone: "phone"
id: 0
email: "email"
username: "username"
xml:
name: "User"
Tag:
Expand All @@ -675,6 +695,9 @@ definitions:
type: "string"
title: "Pet Tag"
description: "A tag for a pet"
example:
name: "name"
id: 1
xml:
name: "Tag"
Pet:
Expand Down Expand Up @@ -714,6 +737,21 @@ definitions:
- "sold"
title: "a Pet"
description: "A pet for sale in the pet store"
example:
photoUrls:
- "photoUrls"
- "photoUrls"
name: "doggie"
id: 0
category:
name: "name"
id: 6
tags:
- name: "name"
id: 1
- name: "name"
id: 1
status: "available"
xml:
name: "Pet"
ApiResponse:
Expand All @@ -728,6 +766,10 @@ definitions:
type: "string"
title: "An uploaded response"
description: "Describes the result of uploading an image resource"
example:
code: 0
type: "type"
message: "message"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
4 changes: 2 additions & 2 deletions samples/server/petstore/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"main": "index.js",
"scripts": {
"prestart": "npm install",
"start": "node index.js"
"prestart": "npm install",
"start": "node index.js"
},
"keywords": [
"swagger"
Expand Down
63 changes: 52 additions & 11 deletions samples/server/petstore/nodejs/service/PetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,34 @@ exports.findPetsByStatus = function(status) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = [ {
"photoUrls" : [ "aeiou" ],
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "aeiou",
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "aeiou",
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}, {
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
Expand All @@ -74,15 +93,34 @@ exports.findPetsByTags = function(tags) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = [ {
"photoUrls" : [ "aeiou" ],
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "aeiou",
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "aeiou",
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}, {
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
Expand All @@ -107,15 +145,18 @@ exports.getPetById = function(petId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"photoUrls" : [ "aeiou" ],
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "aeiou",
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "aeiou",
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
Expand Down Expand Up @@ -173,8 +214,8 @@ exports.uploadFile = function(petId,additionalMetadata,file) {
var examples = {};
examples['application/json'] = {
"code" : 0,
"type" : "aeiou",
"message" : "aeiou"
"type" : "type",
"message" : "message"
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
Expand Down
16 changes: 8 additions & 8 deletions samples/server/petstore/nodejs/service/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ exports.deleteUser = function(username) {
* Get user by user name
*
*
* username String The name that needs to be fetched. Use user1 for testing.
* username String The name that needs to be fetched. Use user1 for testing.
* returns User
**/
exports.getUserByName = function(username) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"firstName" : "aeiou",
"lastName" : "aeiou",
"password" : "aeiou",
"firstName" : "firstName",
"lastName" : "lastName",
"password" : "password",
"userStatus" : 6,
"phone" : "aeiou",
"phone" : "phone",
"id" : 0,
"email" : "aeiou",
"username" : "aeiou"
"email" : "email",
"username" : "username"
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
Expand All @@ -97,7 +97,7 @@ exports.getUserByName = function(username) {
exports.loginUser = function(username,password) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = "aeiou";
examples['application/json'] = "";
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/nodejs/utils/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ var writeJson = exports.writeJson = function(response, arg1, arg2) {
payload = JSON.stringify(payload, null, 2);
}
response.writeHead(code, {'Content-Type': 'application/json'});
response.end(payload, code);
}
response.end(payload);
}

0 comments on commit e7f4fb3

Please sign in to comment.