forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
commit
ef5c6a939d
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator;
|
package io.swagger.generator;
|
||||||
@ -32,13 +30,13 @@ public class Bootstrap extends HttpServlet {
|
|||||||
DynamicSwaggerConfig bc = new DynamicSwaggerConfig();
|
DynamicSwaggerConfig bc = new DynamicSwaggerConfig();
|
||||||
bc.setBasePath("/api");
|
bc.setBasePath("/api");
|
||||||
bc.setTitle("Swagger Generator");
|
bc.setTitle("Swagger Generator");
|
||||||
bc.setDescription("This is an online swagger codegen server. You can find out more " +
|
bc.setDescription("This is an online swagger codegen server. You can find out more "
|
||||||
"at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
|
+ "at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
|
||||||
bc.setTermsOfServiceUrl("http://swagger.io/terms/");
|
bc.setTermsOfServiceUrl("http://swagger.io/terms/");
|
||||||
bc.setContact("apiteam@swagger.io");
|
bc.setContact("apiteam@swagger.io");
|
||||||
bc.setLicense("Apache 2.0");
|
bc.setLicense("Apache 2.0");
|
||||||
InputStream stream = getClass().getResourceAsStream("/version.prop");
|
InputStream stream = getClass().getResourceAsStream("/version.prop");
|
||||||
if(stream == null) {
|
if (stream == null) {
|
||||||
bc.setVersion("0.0.0");
|
bc.setVersion("0.0.0");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,8 @@ public class DynamicSwaggerConfig extends BeanConfig {
|
|||||||
static {
|
static {
|
||||||
List<CodegenConfig> extensions = Codegen.getExtensions();
|
List<CodegenConfig> extensions = Codegen.getExtensions();
|
||||||
for (CodegenConfig config : extensions) {
|
for (CodegenConfig config : extensions) {
|
||||||
if (config.getTag().equals(CodegenType.CLIENT) || config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
if (config.getTag().equals(CodegenType.CLIENT)
|
||||||
|
|| config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||||
clients.add(config.getName());
|
clients.add(config.getName());
|
||||||
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
||||||
servers.add(config.getName());
|
servers.add(config.getName());
|
||||||
@ -44,7 +45,7 @@ public class DynamicSwaggerConfig extends BeanConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Operation get = clientPath.getGet();
|
Operation get = clientPath.getGet();
|
||||||
if(get != null) {
|
if (get != null) {
|
||||||
framework = get.getParameters().get(0);
|
framework = get.getParameters().get(0);
|
||||||
if (framework instanceof PathParameter) {
|
if (framework instanceof PathParameter) {
|
||||||
PathParameter param = (PathParameter) framework;
|
PathParameter param = (PathParameter) framework;
|
||||||
@ -63,7 +64,7 @@ public class DynamicSwaggerConfig extends BeanConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Operation get = serverPath.getGet();
|
Operation get = serverPath.getGet();
|
||||||
if(get != null) {
|
if (get != null) {
|
||||||
framework = get.getParameters().get(0);
|
framework = get.getParameters().get(0);
|
||||||
if (framework instanceof PathParameter) {
|
if (framework instanceof PathParameter) {
|
||||||
PathParameter param = (PathParameter) framework;
|
PathParameter param = (PathParameter) framework;
|
||||||
@ -72,8 +73,6 @@ public class DynamicSwaggerConfig extends BeanConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return swagger.info(getInfo())
|
return swagger.info(getInfo()).host(getHost()).basePath("/api");
|
||||||
.host(getHost())
|
|
||||||
.basePath("/api");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.exception;
|
package io.swagger.generator.exception;
|
||||||
@ -25,8 +23,7 @@ public class ApiException extends Exception {
|
|||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode()
|
public int getCode() {
|
||||||
{
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.exception;
|
package io.swagger.generator.exception;
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.exception;
|
package io.swagger.generator.exception;
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.model;
|
package io.swagger.generator.model;
|
||||||
@ -30,8 +28,7 @@ public class ApiResponse {
|
|||||||
String type;
|
String type;
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
public ApiResponse() {
|
public ApiResponse() {}
|
||||||
}
|
|
||||||
|
|
||||||
public ApiResponse(int code, String message) {
|
public ApiResponse(int code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.model;
|
package io.swagger.generator.model;
|
||||||
|
@ -57,4 +57,4 @@ public class GeneratorInput {
|
|||||||
public void setSecurityDefinition(SecuritySchemeDefinition auth) {
|
public void setSecurityDefinition(SecuritySchemeDefinition auth) {
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.model;
|
package io.swagger.generator.model;
|
||||||
@ -22,8 +20,7 @@ public class InputOption {
|
|||||||
private Boolean required;
|
private Boolean required;
|
||||||
private String defaultValue;
|
private String defaultValue;
|
||||||
|
|
||||||
public InputOption() {
|
public InputOption() {}
|
||||||
}
|
|
||||||
|
|
||||||
public InputOption(String name, String description, String defaultValue, Boolean required) {
|
public InputOption(String name, String description, String defaultValue, Boolean required) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -6,15 +6,15 @@ public class ResponseCode {
|
|||||||
private String code;
|
private String code;
|
||||||
private String link;
|
private String link;
|
||||||
|
|
||||||
public ResponseCode() {
|
public ResponseCode() {}
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseCode(String code, String link) {
|
public ResponseCode(String code, String link) {
|
||||||
setCode(code);
|
setCode(code);
|
||||||
setLink(link);
|
setLink(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiModelProperty(value = "File download code", example = "d40029be-eda6-4d62-b1ef-d05e2e91a72a")
|
@ApiModelProperty(value = "File download code",
|
||||||
|
example = "d40029be-eda6-4d62-b1ef-d05e2e91a72a")
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
@ -23,7 +23,9 @@ public class ResponseCode {
|
|||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiModelProperty(value = "URL for fetching the generated client", example = "http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a")
|
@ApiModelProperty(
|
||||||
|
value = "URL for fetching the generated client",
|
||||||
|
example = "http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a")
|
||||||
public String getLink() {
|
public String getLink() {
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
@ -31,4 +33,4 @@ public class ResponseCode {
|
|||||||
public void setLink(String link) {
|
public void setLink(String link) {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ public class Generator {
|
|||||||
try {
|
try {
|
||||||
config = CodegenConfigLoader.forName(language);
|
config = CodegenConfigLoader.forName(language);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BadRequestException(String.format("Unsupported target %s supplied. %s", language, e));
|
throw new BadRequestException(String.format("Unsupported target %s supplied. %s",
|
||||||
|
language, e));
|
||||||
}
|
}
|
||||||
Map<String, CliOption> map = new LinkedHashMap<String, CliOption>();
|
Map<String, CliOption> map = new LinkedHashMap<String, CliOption>();
|
||||||
for (CliOption option : config.cliOptions()) {
|
for (CliOption option : config.cliOptions()) {
|
||||||
@ -38,8 +39,7 @@ public class Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
CLIENT("client"),
|
CLIENT("client"), SERVER("server");
|
||||||
SERVER("server");
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ -60,37 +60,39 @@ public class Generator {
|
|||||||
return generate(language, opts, Type.SERVER);
|
return generate(language, opts, Type.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generate(String language, GeneratorInput opts, Type type) throws ApiException {
|
private static String generate(String language, GeneratorInput opts, Type type)
|
||||||
|
throws ApiException {
|
||||||
LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language));
|
LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language));
|
||||||
if (opts == null) {
|
if (opts == null) {
|
||||||
throw new BadRequestException("No options were supplied");
|
throw new BadRequestException("No options were supplied");
|
||||||
}
|
}
|
||||||
JsonNode node = opts.getSpec();
|
JsonNode node = opts.getSpec();
|
||||||
if(node != null && "{}".equals(node.toString())) {
|
if (node != null && "{}".equals(node.toString())) {
|
||||||
LOGGER.debug("ignoring empty spec");
|
LOGGER.debug("ignoring empty spec");
|
||||||
node = null;
|
node = null;
|
||||||
}
|
}
|
||||||
Swagger swagger;
|
Swagger swagger;
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
if (opts.getSwaggerUrl() != null) {
|
if (opts.getSwaggerUrl() != null) {
|
||||||
if(opts.getAuthorizationValue() != null) {
|
if (opts.getAuthorizationValue() != null) {
|
||||||
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
|
List<AuthorizationValue> authorizationValues =
|
||||||
|
new ArrayList<AuthorizationValue>();
|
||||||
authorizationValues.add(opts.getAuthorizationValue());
|
authorizationValues.add(opts.getAuthorizationValue());
|
||||||
|
|
||||||
swagger = new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues, true);
|
swagger =
|
||||||
}
|
new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues,
|
||||||
else {
|
true);
|
||||||
|
} else {
|
||||||
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
|
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException("No swagger specification was supplied");
|
throw new BadRequestException("No swagger specification was supplied");
|
||||||
}
|
}
|
||||||
} else if(opts.getAuthorizationValue() != null) {
|
} else if (opts.getAuthorizationValue() != null) {
|
||||||
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
|
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
|
||||||
authorizationValues.add(opts.getAuthorizationValue());
|
authorizationValues.add(opts.getAuthorizationValue());
|
||||||
swagger = new SwaggerParser().read(node, authorizationValues, true);
|
swagger = new SwaggerParser().read(node, authorizationValues, true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
swagger = new SwaggerParser().read(node, true);
|
swagger = new SwaggerParser().read(node, true);
|
||||||
}
|
}
|
||||||
if (swagger == null) {
|
if (swagger == null) {
|
||||||
@ -99,12 +101,11 @@ public class Generator {
|
|||||||
|
|
||||||
String destPath = null;
|
String destPath = null;
|
||||||
|
|
||||||
if(opts != null && opts.getOptions() != null) {
|
if (opts != null && opts.getOptions() != null) {
|
||||||
destPath = opts.getOptions().get("outputFolder");
|
destPath = opts.getOptions().get("outputFolder");
|
||||||
}
|
}
|
||||||
if(destPath == null) {
|
if (destPath == null) {
|
||||||
destPath = language + "-"
|
destPath = language + "-" + type.getTypeName();
|
||||||
+ type.getTypeName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientOptInput clientOptInput = new ClientOptInput();
|
ClientOptInput clientOptInput = new ClientOptInput();
|
||||||
@ -112,14 +113,12 @@ public class Generator {
|
|||||||
String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath;
|
String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath;
|
||||||
String outputFilename = outputFolder + "-bundle.zip";
|
String outputFilename = outputFolder + "-bundle.zip";
|
||||||
|
|
||||||
clientOptInput
|
clientOptInput.opts(clientOpts).swagger(swagger);
|
||||||
.opts(clientOpts)
|
|
||||||
.swagger(swagger);
|
|
||||||
|
|
||||||
CodegenConfig codegenConfig=null;
|
CodegenConfig codegenConfig = null;
|
||||||
try {
|
try {
|
||||||
codegenConfig = CodegenConfigLoader.forName(language);
|
codegenConfig = CodegenConfigLoader.forName(language);
|
||||||
} catch(RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new BadRequestException("Unsupported target " + language + " supplied");
|
throw new BadRequestException("Unsupported target " + language + " supplied");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,20 +142,19 @@ public class Generator {
|
|||||||
ZipUtil zip = new ZipUtil();
|
ZipUtil zip = new ZipUtil();
|
||||||
zip.compressFiles(filesToAdd, outputFilename);
|
zip.compressFiles(filesToAdd, outputFilename);
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException("A target generation was attempted, but no files were created!");
|
throw new BadRequestException(
|
||||||
|
"A target generation was attempted, but no files were created!");
|
||||||
}
|
}
|
||||||
for(File file: files) {
|
for (File file : files) {
|
||||||
try {
|
try {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
LOGGER.error("unable to delete file " + file.getAbsolutePath());
|
LOGGER.error("unable to delete file " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new File(outputFolder).delete();
|
new File(outputFolder).delete();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
LOGGER.error("unable to delete output folder " + outputFolder);
|
LOGGER.error("unable to delete output folder " + outputFolder);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -17,35 +17,26 @@ public class ExceptionWriter implements ExceptionMapper<Exception> {
|
|||||||
public Response toResponse(Exception exception) {
|
public Response toResponse(Exception exception) {
|
||||||
if (exception instanceof javax.ws.rs.WebApplicationException) {
|
if (exception instanceof javax.ws.rs.WebApplicationException) {
|
||||||
javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception;
|
javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception;
|
||||||
return Response
|
return Response.status(e.getResponse().getStatus())
|
||||||
.status(e.getResponse().getStatus())
|
.entity(new ApiResponse(e.getResponse().getStatus(), exception.getMessage()))
|
||||||
.entity(new ApiResponse(e.getResponse().getStatus(),
|
.build();
|
||||||
exception.getMessage())).build();
|
|
||||||
} else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) {
|
} else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) {
|
||||||
return Response.status(400)
|
return Response.status(400).entity(new ApiResponse(400, "bad input")).build();
|
||||||
.entity(new ApiResponse(400, "bad input")).build();
|
|
||||||
} else if (exception instanceof ValidationException) {
|
} else if (exception instanceof ValidationException) {
|
||||||
ValidationException e = (ValidationException) exception;
|
ValidationException e = (ValidationException) exception;
|
||||||
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
|
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
|
||||||
} else if (exception instanceof NotFoundException) {
|
} else if (exception instanceof NotFoundException) {
|
||||||
return Response
|
return Response.status(Status.NOT_FOUND)
|
||||||
.status(Status.NOT_FOUND)
|
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||||
.entity(new ApiResponse(ApiResponse.ERROR, exception
|
|
||||||
.getMessage())).build();
|
|
||||||
} else if (exception instanceof BadRequestException) {
|
} else if (exception instanceof BadRequestException) {
|
||||||
return Response
|
return Response.status(Status.BAD_REQUEST)
|
||||||
.status(Status.BAD_REQUEST)
|
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||||
.entity(new ApiResponse(ApiResponse.ERROR, exception
|
|
||||||
.getMessage())).build();
|
|
||||||
} else if (exception instanceof ApiException) {
|
} else if (exception instanceof ApiException) {
|
||||||
return Response
|
return Response.status(Status.BAD_REQUEST)
|
||||||
.status(Status.BAD_REQUEST)
|
.entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build();
|
||||||
.entity(new ApiResponse(ApiResponse.ERROR, exception
|
|
||||||
.getMessage())).build();
|
|
||||||
} else {
|
} else {
|
||||||
return Response.status(500)
|
return Response.status(500).entity(new ApiResponse(500, "something bad happened"))
|
||||||
.entity(new ApiResponse(500, "something bad happened"))
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ public class SwaggerResource {
|
|||||||
static {
|
static {
|
||||||
List<CodegenConfig> extensions = Codegen.getExtensions();
|
List<CodegenConfig> extensions = Codegen.getExtensions();
|
||||||
for (CodegenConfig config : extensions) {
|
for (CodegenConfig config : extensions) {
|
||||||
if (config.getTag().equals(CodegenType.CLIENT) || config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
if (config.getTag().equals(CodegenType.CLIENT)
|
||||||
|
|| config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||||
clients.add(config.getName());
|
clients.add(config.getName());
|
||||||
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
} else if (config.getTag().equals(CodegenType.SERVER)) {
|
||||||
servers.add(config.getName());
|
servers.add(config.getName());
|
||||||
@ -48,12 +49,11 @@ public class SwaggerResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/download/{fileId}")
|
@Path("/download/{fileId}")
|
||||||
@Produces({MediaType.APPLICATION_OCTET_STREAM})
|
@Produces({MediaType.APPLICATION_OCTET_STREAM})
|
||||||
@ApiOperation(value = "Downloads a pre-generated file",
|
@ApiOperation(
|
||||||
notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST " +
|
value = "Downloads a pre-generated file",
|
||||||
"operations. The fileId code can be used just once, after which a new `fileId` will need to " +
|
notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST "
|
||||||
"be requested.",
|
+ "operations. The fileId code can be used just once, after which a new `fileId` will need to "
|
||||||
response = String.class,
|
+ "be requested.", response = String.class, tags = {"clients", "servers"})
|
||||||
tags = {"clients", "servers"})
|
|
||||||
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
|
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
|
||||||
Generated g = fileMap.get(fileId);
|
Generated g = fileMap.get(fileId);
|
||||||
System.out.println("looking for fileId " + fileId);
|
System.out.println("looking for fileId " + fileId);
|
||||||
@ -64,16 +64,15 @@ public class SwaggerResource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
FileUtils.deleteDirectory(file.getParentFile());
|
FileUtils.deleteDirectory(file.getParentFile());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
System.out.println("failed to delete file " + file.getAbsolutePath());
|
System.out.println("failed to delete file " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.ok(bytes, "application/zip")
|
return Response
|
||||||
.header("Content-Disposition", "attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"")
|
.ok(bytes, "application/zip")
|
||||||
.header("Accept-Range", "bytes")
|
.header("Content-Disposition",
|
||||||
.header("Content-Length", bytes.length)
|
"attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"")
|
||||||
.build();
|
.header("Accept-Range", "bytes").header("Content-Length", bytes.length).build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(404).build();
|
return Response.status(404).build();
|
||||||
}
|
}
|
||||||
@ -84,23 +83,22 @@ public class SwaggerResource {
|
|||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
value = "Generates a client library",
|
value = "Generates a client library",
|
||||||
notes = "Accepts a `GeneratorInput` options map for spec location and generation options",
|
notes = "Accepts a `GeneratorInput` options map for spec location and generation options",
|
||||||
response = ResponseCode.class,
|
response = ResponseCode.class, tags = "clients")
|
||||||
tags = "clients")
|
|
||||||
public Response generateClient(
|
public Response generateClient(
|
||||||
@Context HttpServletRequest request,
|
@Context HttpServletRequest request,
|
||||||
@ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language,
|
@ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language,
|
||||||
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts) throws Exception {
|
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
String filename = Generator.generateClient(language, opts);
|
String filename = Generator.generateClient(language, opts);
|
||||||
String host = System.getenv("GENERATOR_HOST");
|
String host = System.getenv("GENERATOR_HOST");
|
||||||
|
|
||||||
if(StringUtils.isBlank(host)) {
|
if (StringUtils.isBlank(host)) {
|
||||||
String scheme = request.getHeader("X-SSL");
|
String scheme = request.getHeader("X-SSL");
|
||||||
String port = "";
|
String port = "";
|
||||||
if("1".equals(scheme)) {
|
if ("1".equals(scheme)) {
|
||||||
scheme = "https";
|
scheme = "https";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
scheme = request.getScheme();
|
scheme = request.getScheme();
|
||||||
port = ":" + request.getServerPort();
|
port = ":" + request.getServerPort();
|
||||||
}
|
}
|
||||||
@ -124,15 +122,12 @@ public class SwaggerResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/clients/{language}")
|
@Path("/clients/{language}")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@ApiOperation(
|
@ApiOperation(value = "Returns options for a client library", response = CliOption.class,
|
||||||
value = "Returns options for a client library",
|
responseContainer = "map", tags = "clients")
|
||||||
response = CliOption.class,
|
|
||||||
responseContainer = "map",
|
|
||||||
tags = "clients")
|
|
||||||
public Response getClientOptions(
|
public Response getClientOptions(
|
||||||
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
||||||
@ApiParam(value = "The target language for the client library", required = true)
|
@ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language)
|
||||||
@PathParam("language") String language) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Map<String, CliOption> opts = Generator.getOptions(language);
|
Map<String, CliOption> opts = Generator.getOptions(language);
|
||||||
|
|
||||||
@ -146,15 +141,12 @@ public class SwaggerResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/servers/{framework}")
|
@Path("/servers/{framework}")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@ApiOperation(
|
@ApiOperation(value = "Returns options for a server framework", response = CliOption.class,
|
||||||
value = "Returns options for a server framework",
|
responseContainer = "map", tags = "servers")
|
||||||
response = CliOption.class,
|
|
||||||
responseContainer = "map",
|
|
||||||
tags = "servers")
|
|
||||||
public Response getServerOptions(
|
public Response getServerOptions(
|
||||||
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
@SuppressWarnings("unused") @Context HttpServletRequest request,
|
||||||
@ApiParam(value = "The target language for the server framework", required = true)
|
@ApiParam(value = "The target language for the server framework", required = true) @PathParam("framework") String framework)
|
||||||
@PathParam("framework") String framework) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Map<String, CliOption> opts = Generator.getOptions(framework);
|
Map<String, CliOption> opts = Generator.getOptions(framework);
|
||||||
|
|
||||||
@ -168,9 +160,7 @@ public class SwaggerResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/clients")
|
@Path("/clients")
|
||||||
@ApiOperation(value = "Gets languages supported by the client generator",
|
@ApiOperation(value = "Gets languages supported by the client generator",
|
||||||
response = String.class,
|
response = String.class, responseContainer = "List", tags = "clients")
|
||||||
responseContainer = "List",
|
|
||||||
tags = "clients")
|
|
||||||
public Response clientOptions() {
|
public Response clientOptions() {
|
||||||
String[] languages = new String[clients.size()];
|
String[] languages = new String[clients.size()];
|
||||||
languages = clients.toArray(languages);
|
languages = clients.toArray(languages);
|
||||||
@ -180,9 +170,7 @@ public class SwaggerResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/servers")
|
@Path("/servers")
|
||||||
@ApiOperation(value = "Gets languages supported by the server generator",
|
@ApiOperation(value = "Gets languages supported by the server generator",
|
||||||
response = String.class,
|
response = String.class, responseContainer = "List", tags = "servers")
|
||||||
responseContainer = "List",
|
|
||||||
tags = "servers")
|
|
||||||
public Response serverOptions() {
|
public Response serverOptions() {
|
||||||
String[] languages = new String[servers.size()];
|
String[] languages = new String[servers.size()];
|
||||||
languages = servers.toArray(languages);
|
languages = servers.toArray(languages);
|
||||||
@ -191,22 +179,22 @@ public class SwaggerResource {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/servers/{framework}")
|
@Path("/servers/{framework}")
|
||||||
@ApiOperation(value = "Generates a server library",
|
@ApiOperation(
|
||||||
|
value = "Generates a server library",
|
||||||
notes = "Accepts a `GeneratorInput` options map for spec location and generation options.",
|
notes = "Accepts a `GeneratorInput` options map for spec location and generation options.",
|
||||||
response = ResponseCode.class,
|
response = ResponseCode.class, tags = "servers")
|
||||||
tags = "servers")
|
public Response generateServerForLanguage(@Context HttpServletRequest request, @ApiParam(
|
||||||
public Response generateServerForLanguage(
|
value = "framework", required = true) @PathParam("framework") String framework,
|
||||||
@Context HttpServletRequest request,
|
@ApiParam(value = "parameters", required = true) GeneratorInput opts) throws Exception {
|
||||||
@ApiParam(value = "framework", required = true) @PathParam("framework") String framework,
|
|
||||||
@ApiParam(value = "parameters", required = true) GeneratorInput opts)
|
|
||||||
throws Exception {
|
|
||||||
if (framework == null) {
|
if (framework == null) {
|
||||||
throw new BadRequestException("Framework is required");
|
throw new BadRequestException("Framework is required");
|
||||||
}
|
}
|
||||||
String filename = Generator.generateServer(framework, opts);
|
String filename = Generator.generateServer(framework, opts);
|
||||||
System.out.println("generated name: " + filename);
|
System.out.println("generated name: " + filename);
|
||||||
|
|
||||||
String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
|
String host =
|
||||||
|
request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
|
+ request.getServerPort();
|
||||||
|
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
String code = String.valueOf(UUID.randomUUID().toString());
|
String code = String.valueOf(UUID.randomUUID().toString());
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.util;
|
package io.swagger.generator.util;
|
||||||
@ -26,8 +24,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response,
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
FilterChain chain) throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
HttpServletResponse res = (HttpServletResponse) response;
|
HttpServletResponse res = (HttpServletResponse) response;
|
||||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||||
@ -36,10 +34,8 @@ public class ApiOriginFilter implements javax.servlet.Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -17,4 +17,4 @@ public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
|
|||||||
public JacksonJsonProvider() {
|
public JacksonJsonProvider() {
|
||||||
super.setMapper(commonMapper);
|
super.setMapper(commonMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,4 @@ public class ValidationException extends Exception {
|
|||||||
public void setMessage(String msg) {
|
public void setMessage(String msg) {
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,4 @@ public class ValidationMessage {
|
|||||||
public void setSeverity(String severity) {
|
public void setSeverity(String severity) {
|
||||||
this.severity = severity;
|
this.severity = severity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2016 SmartBear Software
|
* Copyright 2016 SmartBear Software
|
||||||
* <p>
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* you may not use this file except in compliance with the License.
|
* in compliance with the License. You may obtain a copy of the License at
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* <p>
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* See the License for the specific language governing permissions and
|
* the License.
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.swagger.generator.util;
|
package io.swagger.generator.util;
|
||||||
@ -27,8 +25,9 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This utility compresses a list of files to standard ZIP format file.
|
* This utility compresses a list of files to standard ZIP format file. It is able to compresses all
|
||||||
* It is able to compresses all sub files and sub directories, recursively.
|
* sub files and sub directories, recursively.
|
||||||
|
*
|
||||||
* @author Ha Minh Nam
|
* @author Ha Minh Nam
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -40,6 +39,7 @@ public class ZipUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compresses a collection of files to a destination zip file.
|
* Compresses a collection of files to a destination zip file.
|
||||||
|
*
|
||||||
* @param listFiles A collection of files and directories
|
* @param listFiles A collection of files and directories
|
||||||
* @param destZipFile The path of the destination zip file
|
* @param destZipFile The path of the destination zip file
|
||||||
* @throws FileNotFoundException if file not found
|
* @throws FileNotFoundException if file not found
|
||||||
@ -64,14 +64,15 @@ public class ZipUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directory to the current zip output stream.
|
* Adds a directory to the current zip output stream.
|
||||||
* @param folder the directory to be added
|
*
|
||||||
|
* @param folder the directory to be added
|
||||||
* @param parentFolder the path of parent directory
|
* @param parentFolder the path of parent directory
|
||||||
* @param zos the current zip output stream
|
* @param zos the current zip output stream
|
||||||
* @throws FileNotFoundException if file not found
|
* @throws FileNotFoundException if file not found
|
||||||
* @throws IOException if IO exception occurs
|
* @throws IOException if IO exception occurs
|
||||||
*/
|
*/
|
||||||
private void addFolderToZip(File folder, String parentFolder,
|
private void addFolderToZip(File folder, String parentFolder, ZipOutputStream zos)
|
||||||
ZipOutputStream zos) throws FileNotFoundException, IOException {
|
throws FileNotFoundException, IOException {
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : folder.listFiles()) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
addFolderToZip(file, parentFolder + "/" + file.getName(), zos);
|
addFolderToZip(file, parentFolder + "/" + file.getName(), zos);
|
||||||
@ -80,8 +81,7 @@ public class ZipUtil {
|
|||||||
|
|
||||||
zos.putNextEntry(new ZipEntry(parentFolder + "/" + file.getName()));
|
zos.putNextEntry(new ZipEntry(parentFolder + "/" + file.getName()));
|
||||||
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
|
||||||
new FileInputStream(file));
|
|
||||||
|
|
||||||
long bytesRead = 0;
|
long bytesRead = 0;
|
||||||
byte[] bytesIn = new byte[BUFFER_SIZE];
|
byte[] bytesIn = new byte[BUFFER_SIZE];
|
||||||
@ -99,17 +99,17 @@ public class ZipUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a file to the current zip output stream.
|
* Adds a file to the current zip output stream.
|
||||||
|
*
|
||||||
* @param file the file to be added
|
* @param file the file to be added
|
||||||
* @param zos the current zip output stream
|
* @param zos the current zip output stream
|
||||||
* @throws FileNotFoundException if file not found
|
* @throws FileNotFoundException if file not found
|
||||||
* @throws IOException if IO exception occurs
|
* @throws IOException if IO exception occurs
|
||||||
*/
|
*/
|
||||||
private static void addFileToZip(File file, ZipOutputStream zos)
|
private static void addFileToZip(File file, ZipOutputStream zos) throws FileNotFoundException,
|
||||||
throws FileNotFoundException, IOException {
|
IOException {
|
||||||
zos.putNextEntry(new ZipEntry(file.getName()));
|
zos.putNextEntry(new ZipEntry(file.getName()));
|
||||||
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
|
||||||
file));
|
|
||||||
|
|
||||||
byte[] bytesIn = new byte[BUFFER_SIZE];
|
byte[] bytesIn = new byte[BUFFER_SIZE];
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
@ -32,32 +32,35 @@ public class OnlineGeneratorOptionsTest {
|
|||||||
|
|
||||||
@DataProvider(name = OPTIONS_PROVIDER)
|
@DataProvider(name = OPTIONS_PROVIDER)
|
||||||
private static Object[][] listOptions() {
|
private static Object[][] listOptions() {
|
||||||
return new Object[][]{{new AkkaScalaClientOptionsProvider()}, {new AndroidClientOptionsProvider()},
|
return new Object[][] {
|
||||||
{new AsyncScalaClientOptionsProvider()}, {new CSharpClientOptionsProvider()},
|
{new AkkaScalaClientOptionsProvider()},
|
||||||
{new CsharpDotNet2ClientOptionsProvider()}, {new DartClientOptionsProvider()},
|
{new AndroidClientOptionsProvider()},
|
||||||
{new FlashClienOptionsProvider()}, {new JavaInflectorServerOptionsProvider()},
|
{new AsyncScalaClientOptionsProvider()},
|
||||||
|
{new CSharpClientOptionsProvider()},
|
||||||
|
{new CsharpDotNet2ClientOptionsProvider()},
|
||||||
|
{new DartClientOptionsProvider()},
|
||||||
|
{new FlashClienOptionsProvider()},
|
||||||
|
{new JavaInflectorServerOptionsProvider()},
|
||||||
{
|
{
|
||||||
new JavaOptionsProvider(),
|
new JavaOptionsProvider(),
|
||||||
new JavaOptionsProvider(ImmutableMap.of(CodegenConstants.LIBRARY, JavaClientCodegen.RETROFIT_2)
|
new JavaOptionsProvider(ImmutableMap.of(CodegenConstants.LIBRARY,
|
||||||
),
|
JavaClientCodegen.RETROFIT_2)),
|
||||||
new JavaOptionsProvider(ImmutableMap.of(
|
new JavaOptionsProvider(
|
||||||
CodegenConstants.LIBRARY, JavaClientCodegen.RETROFIT_2,
|
ImmutableMap.of(CodegenConstants.LIBRARY,
|
||||||
JavaClientCodegen.USE_RX_JAVA, "true")
|
JavaClientCodegen.RETROFIT_2,
|
||||||
)
|
JavaClientCodegen.USE_RX_JAVA, "true"))},
|
||||||
},
|
{new JaxRSServerOptionsProvider()}, {new NodeJSServerOptionsProvider()},
|
||||||
{new JaxRSServerOptionsProvider()},
|
{new ObjcClientOptionsProvider()}, {new PerlClientOptionsProvider()},
|
||||||
{new NodeJSServerOptionsProvider()}, {new ObjcClientOptionsProvider()},
|
{new PhpClientOptionsProvider()}, {new PythonClientOptionsProvider()},
|
||||||
{new PerlClientOptionsProvider()}, {new PhpClientOptionsProvider()},
|
{new Qt5CPPOptionsProvider()}, {new RubyClientOptionsProvider()},
|
||||||
{new PythonClientOptionsProvider()}, {new Qt5CPPOptionsProvider()},
|
{new ScalaClientOptionsProvider()}, {new ScalatraServerOptionsProvider()},
|
||||||
{new RubyClientOptionsProvider()}, {new ScalaClientOptionsProvider()},
|
{new SilexServerOptionsProvider()}, {new SinatraServerOptionsProvider()},
|
||||||
{new ScalatraServerOptionsProvider()}, {new SilexServerOptionsProvider()},
|
{new SlimFrameworkServerOptionsProvider()}, {new SpringOptionsProvider()},
|
||||||
{new SinatraServerOptionsProvider()}, {new SlimFrameworkServerOptionsProvider()},
|
{new StaticDocOptionsProvider()}, {new StaticHtmlOptionsProvider()},
|
||||||
{new SpringOptionsProvider()}, {new StaticDocOptionsProvider()},
|
{new SwaggerOptionsProvider()}, {new SwaggerYamlOptionsProvider()},
|
||||||
{new StaticHtmlOptionsProvider()}, {new SwaggerOptionsProvider()},
|
{new SwiftOptionsProvider()}, {new TizenClientOptionsProvider()},
|
||||||
{new SwaggerYamlOptionsProvider()}, {new SwiftOptionsProvider()},
|
{new TypeScriptAngularClientOptionsProvider()},
|
||||||
{new TizenClientOptionsProvider()}, {new TypeScriptAngularClientOptionsProvider()},
|
{new TypeScriptNodeClientOptionsProvider()}, {new LumenServerOptionsProvider()}};
|
||||||
{new TypeScriptNodeClientOptionsProvider()}, {new LumenServerOptionsProvider()}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = OPTIONS_PROVIDER)
|
@Test(dataProvider = OPTIONS_PROVIDER)
|
||||||
@ -83,15 +86,15 @@ public class OnlineGeneratorOptionsTest {
|
|||||||
outputFilename = Generator.generateClient(provider.getLanguage(), input);
|
outputFilename = Generator.generateClient(provider.getLanguage(), input);
|
||||||
}
|
}
|
||||||
final File dir = new File(new File(outputFilename).getParent());
|
final File dir = new File(new File(outputFilename).getParent());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileUtils.deleteDirectory(dir);
|
FileUtils.deleteDirectory(dir);
|
||||||
} catch (Exception e) { // directory can't be deleted for some reasons
|
} catch (Exception e) { // directory can't be deleted for some reasons
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
for (InvocationCounter option : options.values()) {
|
for (InvocationCounter option : options.values()) {
|
||||||
assertNotEquals(option.getCounter(), 0, String.format("Option \"%s\" wasn't processed.",
|
assertNotEquals(option.getCounter(), 0,
|
||||||
option.getValue()));
|
String.format("Option \"%s\" wasn't processed.", option.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,24 +138,27 @@ public class OnlineGeneratorOptionsTest {
|
|||||||
public static void getOptionsTest(OptionsProvider provider) throws ApiException {
|
public static void getOptionsTest(OptionsProvider provider) throws ApiException {
|
||||||
final Map<String, CliOption> opts = Generator.getOptions(provider.getLanguage());
|
final Map<String, CliOption> opts = Generator.getOptions(provider.getLanguage());
|
||||||
|
|
||||||
final Function<CliOption, CliOptionProxy> cliOptionWrapper = new Function<CliOption, CliOptionProxy>() {
|
final Function<CliOption, CliOptionProxy> cliOptionWrapper =
|
||||||
@Nullable
|
new Function<CliOption, CliOptionProxy>() {
|
||||||
@Override
|
@Nullable
|
||||||
public CliOptionProxy apply(@Nullable CliOption option) {
|
@Override
|
||||||
return new CliOptionProxy(option);
|
public CliOptionProxy apply(@Nullable CliOption option) {
|
||||||
}
|
return new CliOptionProxy(option);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
final List<CliOptionProxy> actual = Lists.transform(new ArrayList<CliOption>(opts.values()), cliOptionWrapper);
|
final List<CliOptionProxy> actual =
|
||||||
final List<CliOptionProxy> expected = Lists.transform(
|
Lists.transform(new ArrayList<CliOption>(opts.values()), cliOptionWrapper);
|
||||||
CodegenConfigLoader.forName(provider.getLanguage()).cliOptions(), cliOptionWrapper);
|
final List<CliOptionProxy> expected =
|
||||||
|
Lists.transform(CodegenConfigLoader.forName(provider.getLanguage()).cliOptions(),
|
||||||
|
cliOptionWrapper);
|
||||||
assertEquals(actual, expected);
|
assertEquals(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class CliOptionProxy {
|
protected static class CliOptionProxy {
|
||||||
private final CliOption wrapped;
|
private final CliOption wrapped;
|
||||||
|
|
||||||
public CliOptionProxy(CliOption wrapped){
|
public CliOptionProxy(CliOption wrapped) {
|
||||||
this.wrapped = wrapped;
|
this.wrapped = wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ public class OnlineJavaClientOptionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOptionsTest() throws ApiException {
|
public void getOptionsTest() throws ApiException {
|
||||||
final Map<String, CliOption> options = Generator.getOptions(new JavaOptionsProvider().getLanguage());
|
final Map<String, CliOption> options =
|
||||||
|
Generator.getOptions(new JavaOptionsProvider().getLanguage());
|
||||||
assertNotNull(options);
|
assertNotNull(options);
|
||||||
final CliOption opt = options.get(CodegenConstants.LIBRARY);
|
final CliOption opt = options.get(CodegenConstants.LIBRARY);
|
||||||
assertNotNull(opt);
|
assertNotNull(opt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user