Skip to content

Commit

Permalink
[JavaScript] Fix licenseNames (#6605)
Browse files Browse the repository at this point in the history
* [JavaScript] Fix licenseName in package.mustache

* Fix invalid SPDX license expression in resources/2_0

* Update JavaScript samples
  • Loading branch information
hisener authored and wing328 committed Oct 8, 2017
1 parent 8a7940f commit 1f9f8c5
Show file tree
Hide file tree
Showing 57 changed files with 1,820 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
public static final String MODULE_NAME = "moduleName";
public static final String PROJECT_DESCRIPTION = "projectDescription";
public static final String PROJECT_VERSION = "projectVersion";
public static final String PROJECT_LICENSE_NAME = "projectLicenseName";
public static final String USE_PROMISES = "usePromises";
public static final String USE_INHERITANCE = "useInheritance";
public static final String EMIT_MODEL_METHODS = "emitModelMethods";
Expand Down Expand Up @@ -84,7 +83,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
protected String moduleName;
protected String projectDescription;
protected String projectVersion;
protected String projectLicenseName;
protected String licenseName;

protected String invokerPackage;
protected String sourceFolder = "src";
Expand Down Expand Up @@ -179,7 +178,7 @@ public JavascriptClientCodegen() {
"description of the project (Default: using info.description or \"Client library of <projectName>\")"));
cliOptions.add(new CliOption(PROJECT_VERSION,
"version of the project (Default: using info.version or \"1.0.0\")"));
cliOptions.add(new CliOption(PROJECT_LICENSE_NAME,
cliOptions.add(new CliOption(CodegenConstants.LICENSE_NAME,
"name of the license the project uses (Default: using info.license.name)"));
cliOptions.add(new CliOption(USE_PROMISES,
"use Promises as return values from the client API, instead of superagent callbacks")
Expand Down Expand Up @@ -244,8 +243,8 @@ public void processOpts() {
if (additionalProperties.containsKey(PROJECT_VERSION)) {
setProjectVersion(((String) additionalProperties.get(PROJECT_VERSION)));
}
if (additionalProperties.containsKey(PROJECT_LICENSE_NAME)) {
setProjectLicenseName(((String) additionalProperties.get(PROJECT_LICENSE_NAME)));
if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) {
setLicenseName(((String) additionalProperties.get(CodegenConstants.LICENSE_NAME)));
}
if (additionalProperties.containsKey(CodegenConstants.LOCAL_VARIABLE_PREFIX)) {
setLocalVariablePrefix((String) additionalProperties.get(CodegenConstants.LOCAL_VARIABLE_PREFIX));
Expand Down Expand Up @@ -291,12 +290,11 @@ public void preprocessSwagger(Swagger swagger) {
// when projectDescription is not specified, use info.description
projectDescription = sanitizeName(info.getDescription());
}
if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
// when projectLicense is not specified, use info.license
if (info.getLicense() != null) {
License license = info.getLicense();
additionalProperties.put(PROJECT_LICENSE_NAME, sanitizeName(license.getName()));
}

// when licenceName is not specified, use info.license
if (additionalProperties.get(CodegenConstants.LICENSE_NAME) == null && info.getLicense() != null) {
License license = info.getLicense();
licenseName = license.getName();
}
}

Expand All @@ -313,11 +311,15 @@ public void preprocessSwagger(Swagger swagger) {
if (projectDescription == null) {
projectDescription = "Client library of " + projectName;
}
if (StringUtils.isBlank(licenseName)) {
licenseName = "Unlicense";
}

additionalProperties.put(PROJECT_NAME, projectName);
additionalProperties.put(MODULE_NAME, moduleName);
additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
additionalProperties.put(PROJECT_VERSION, projectVersion);
additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
Expand Down Expand Up @@ -422,8 +424,8 @@ public void setProjectVersion(String projectVersion) {
this.projectVersion = projectVersion;
}

public void setProjectLicenseName(String projectLicenseName) {
this.projectLicenseName = projectLicenseName;
public void setLicenseName(String licenseName) {
this.licenseName = licenseName;
}

public void setUsePromises(boolean usePromises) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "{{{projectName}}}",
"version": "{{{projectVersion}}}",
"description": "{{{projectDescription}}}",
"license": "Unlicense",
"license": "{{licenseName}}",
"main": "{{sourceFolder}}{{#invokerPackage}}/{{invokerPackage}}{{/invokerPackage}}/index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "{{{projectName}}}",
"version": "{{{projectVersion}}}",
"description": "{{{projectDescription}}}",
"license": "Unlicense",
"license": "{{licenseName}}",
"main": "{{sourceFolder}}{{#invokerPackage}}/{{invokerPackage}}{{/invokerPackage}}/index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void setExpectations() {
times = 1;
clientCodegen.setProjectVersion(JavaScriptOptionsProvider.PROJECT_VERSION_VALUE);
times = 1;
clientCodegen.setProjectLicenseName(JavaScriptOptionsProvider.PROJECT_LICENSE_NAME_VALUE);
clientCodegen.setLicenseName(JavaScriptOptionsProvider.PROJECT_LICENSE_NAME_VALUE);
times = 1;
clientCodegen.setUsePromises(Boolean.valueOf(JavaScriptOptionsProvider.USE_PROMISES_VALUE));
times = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.swagger.codegen.options;

import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.options.OptionsProvider;
import io.swagger.codegen.languages.JavascriptClientCodegen;

import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -56,7 +55,7 @@ public JavaScriptOptionsProvider() {
.put(JavascriptClientCodegen.MODULE_NAME, MODULE_NAME_VALUE)
.put(JavascriptClientCodegen.PROJECT_DESCRIPTION, PROJECT_DESCRIPTION_VALUE)
.put(JavascriptClientCodegen.PROJECT_VERSION, PROJECT_VERSION_VALUE)
.put(JavascriptClientCodegen.PROJECT_LICENSE_NAME, PROJECT_LICENSE_NAME_VALUE)
.put(CodegenConstants.LICENSE_NAME, PROJECT_LICENSE_NAME_VALUE)
.put(JavascriptClientCodegen.USE_PROMISES, USE_PROMISES_VALUE)
.put(JavascriptClientCodegen.USE_INHERITANCE, USE_INHERITANCE_VALUE)
.put(JavascriptClientCodegen.EMIT_MODEL_METHODS, EMIT_MODEL_METHODS_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Swagger Petstore",
"termsOfService": "http://helloreverb.com/terms/",
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Swagger Petstore",
"termsOfService": "http://helloreverb.com/terms/",
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"title": "File Response Test",
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email":"[email protected]"
},
"license":{
"name":"Apache 2.0",
"name":"Apache-2.0",
"url":"http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down Expand Up @@ -1053,4 +1053,4 @@
"description":"Find out more about Swagger",
"url":"http://swagger.io"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
contact:
email: [email protected] */ ' " =end -- \r\n \n \r
license:
name: Apache 2.0 */ ' " =end -- \r\n \n \r
name: Apache-2.0 */ ' " =end -- \r\n \n \r
url: http://www.apache.org/licenses/LICENSE-2.0.html */ ' " =end -- \r\n \n \r
host: petstore.swagger.io */ ' " =end -- \r\n \n \r
basePath: /v2 */ ' " =end -- \r\n \n \r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
contact:
email: [email protected]
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
contact:
email: [email protected]
license:
name: Apache 2.0
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io:80
basePath: /v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
contact:
email: [email protected]
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down Expand Up @@ -99,4 +99,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down Expand Up @@ -92,4 +92,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
version: 1.0.0
title: Response header test
license:
name: Apache 2.0
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
basePath: /
schemes:
Expand Down Expand Up @@ -38,4 +38,4 @@ paths:
type: "integer"
description: "I am the error code"
'400':
description: Invalid ID supplied
description: Invalid ID supplied
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"name": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
Expand Down Expand Up @@ -138,4 +138,4 @@
}
}
}
}
}
12 changes: 6 additions & 6 deletions samples/client/petstore/javascript-es6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ Please follow the [installation](#installation) instruction and execute the foll
```javascript
var SwaggerPetstore = require('swagger_petstore');

var api = new SwaggerPetstore.FakeApi()
var api = new SwaggerPetstore.AnotherFakeApi()

var body = new SwaggerPetstore.Client(); // {Client} client model

var opts = {
'body': new SwaggerPetstore.OuterBoolean() // {OuterBoolean} Input boolean as post body
};

var callback = function(error, data, response) {
if (error) {
Expand All @@ -83,7 +82,7 @@ var callback = function(error, data, response) {
console.log('API called successfully. Returned data: ' + data);
}
};
api.fakeOuterBooleanSerialize(opts, callback);
api.testSpecialTags(body, callback);

```

Expand All @@ -93,6 +92,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*SwaggerPetstore.AnotherFakeApi* | [**testSpecialTags**](docs/AnotherFakeApi.md#testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags
*SwaggerPetstore.FakeApi* | [**fakeOuterBooleanSerialize**](docs/FakeApi.md#fakeOuterBooleanSerialize) | **POST** /fake/outer/boolean |
*SwaggerPetstore.FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite |
*SwaggerPetstore.FakeApi* | [**fakeOuterNumberSerialize**](docs/FakeApi.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number |
Expand All @@ -101,7 +101,7 @@ Class | Method | HTTP request | Description
*SwaggerPetstore.FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*SwaggerPetstore.FakeApi* | [**testEnumParameters**](docs/FakeApi.md#testEnumParameters) | **GET** /fake | To test enum parameters
*SwaggerPetstore.FakeApi* | [**testJsonFormData**](docs/FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data
*SwaggerPetstore.Fake_classname_tags123Api* | [**testClassname**](docs/Fake_classname_tags123Api.md#testClassname) | **PATCH** /fake_classname_test | To test class name in snake case
*SwaggerPetstore.FakeClassnameTags123Api* | [**testClassname**](docs/FakeClassnameTags123Api.md#testClassname) | **PATCH** /fake_classname_test | To test class name in snake case
*SwaggerPetstore.PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store
*SwaggerPetstore.PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
*SwaggerPetstore.PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
Expand Down
Loading

0 comments on commit 1f9f8c5

Please sign in to comment.