From 1e535575708f93263415ee2bbeb2f53b90f48153 Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 13 Jul 2017 15:36:04 +0800 Subject: [PATCH] run "mvn formatter:format" on swagger-generator --- .../java/io/swagger/generator/Bootstrap.java | 20 ++--- .../generator/DynamicSwaggerConfig.java | 11 ++- .../generator/exception/ApiException.java | 17 ++-- .../exception/BadRequestException.java | 14 ++- .../exception/NotFoundException.java | 14 ++- .../swagger/generator/model/ApiResponse.java | 17 ++-- .../io/swagger/generator/model/Generated.java | 14 ++- .../generator/model/GeneratorInput.java | 2 +- .../swagger/generator/model/InputOption.java | 17 ++-- .../swagger/generator/model/ResponseCode.java | 12 +-- .../swagger/generator/online/Generator.java | 54 ++++++------ .../generator/resource/ExceptionWriter.java | 33 +++---- .../generator/resource/SwaggerResource.java | 88 ++++++++----------- .../generator/util/ApiOriginFilter.java | 26 +++--- .../generator/util/JacksonJsonProvider.java | 2 +- .../generator/util/ValidationException.java | 2 +- .../generator/util/ValidationMessage.java | 2 +- .../io/swagger/generator/util/ZipUtil.java | 38 ++++---- .../online/OnlineGeneratorOptionsTest.java | 82 +++++++++-------- .../online/OnlineJavaClientOptionsTest.java | 3 +- 20 files changed, 216 insertions(+), 252 deletions(-) diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java b/modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java index c0af8dc56c9..a48a21355fc 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator; @@ -32,13 +30,13 @@ public class Bootstrap extends HttpServlet { DynamicSwaggerConfig bc = new DynamicSwaggerConfig(); bc.setBasePath("/api"); bc.setTitle("Swagger Generator"); - 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/)."); + 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/)."); bc.setTermsOfServiceUrl("http://swagger.io/terms/"); bc.setContact("apiteam@swagger.io"); bc.setLicense("Apache 2.0"); InputStream stream = getClass().getResourceAsStream("/version.prop"); - if(stream == null) { + if (stream == null) { bc.setVersion("0.0.0"); } else { try { diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/DynamicSwaggerConfig.java b/modules/swagger-generator/src/main/java/io/swagger/generator/DynamicSwaggerConfig.java index cc768bc6d10..35d143d4b7e 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/DynamicSwaggerConfig.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/DynamicSwaggerConfig.java @@ -21,7 +21,8 @@ public class DynamicSwaggerConfig extends BeanConfig { static { List extensions = Codegen.getExtensions(); 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()); } else if (config.getTag().equals(CodegenType.SERVER)) { servers.add(config.getName()); @@ -44,7 +45,7 @@ public class DynamicSwaggerConfig extends BeanConfig { } Operation get = clientPath.getGet(); - if(get != null) { + if (get != null) { framework = get.getParameters().get(0); if (framework instanceof PathParameter) { PathParameter param = (PathParameter) framework; @@ -63,7 +64,7 @@ public class DynamicSwaggerConfig extends BeanConfig { } Operation get = serverPath.getGet(); - if(get != null) { + if (get != null) { framework = get.getParameters().get(0); if (framework instanceof PathParameter) { PathParameter param = (PathParameter) framework; @@ -72,8 +73,6 @@ public class DynamicSwaggerConfig extends BeanConfig { } } - return swagger.info(getInfo()) - .host(getHost()) - .basePath("/api"); + return swagger.info(getInfo()).host(getHost()).basePath("/api"); } } diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/ApiException.java b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/ApiException.java index 11932b26295..ee5df08dade 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/ApiException.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/ApiException.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.exception; @@ -25,8 +23,7 @@ public class ApiException extends Exception { this.code = code; } - public int getCode() - { + public int getCode() { return code; } } diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/BadRequestException.java b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/BadRequestException.java index 2adf97b8bf4..6fa19c94c64 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/BadRequestException.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/BadRequestException.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.exception; diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/NotFoundException.java b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/NotFoundException.java index d3747be7d9a..f41d1402a48 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/exception/NotFoundException.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/exception/NotFoundException.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.exception; diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/model/ApiResponse.java b/modules/swagger-generator/src/main/java/io/swagger/generator/model/ApiResponse.java index 424b9dd2b0a..28d4bdc0b1a 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/model/ApiResponse.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/model/ApiResponse.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.model; @@ -30,8 +28,7 @@ public class ApiResponse { String type; String message; - public ApiResponse() { - } + public ApiResponse() {} public ApiResponse(int code, String message) { this.code = code; diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/model/Generated.java b/modules/swagger-generator/src/main/java/io/swagger/generator/model/Generated.java index f48be6a77da..b1d68a5da17 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/model/Generated.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/model/Generated.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.model; diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/model/GeneratorInput.java b/modules/swagger-generator/src/main/java/io/swagger/generator/model/GeneratorInput.java index fabde1e3104..439c730c8bd 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/model/GeneratorInput.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/model/GeneratorInput.java @@ -57,4 +57,4 @@ public class GeneratorInput { public void setSecurityDefinition(SecuritySchemeDefinition auth) { this.auth = auth; } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/model/InputOption.java b/modules/swagger-generator/src/main/java/io/swagger/generator/model/InputOption.java index 33df1bc5071..371f21a9a8c 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/model/InputOption.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/model/InputOption.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.model; @@ -22,8 +20,7 @@ public class InputOption { private Boolean required; private String defaultValue; - public InputOption() { - } + public InputOption() {} public InputOption(String name, String description, String defaultValue, Boolean required) { this.name = name; diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/model/ResponseCode.java b/modules/swagger-generator/src/main/java/io/swagger/generator/model/ResponseCode.java index 0fcc5312dac..37f20c9c04c 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/model/ResponseCode.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/model/ResponseCode.java @@ -6,15 +6,15 @@ public class ResponseCode { private String code; private String link; - public ResponseCode() { - } + public ResponseCode() {} public ResponseCode(String code, String link) { setCode(code); 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() { return code; } @@ -23,7 +23,9 @@ public class ResponseCode { 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() { return link; } @@ -31,4 +33,4 @@ public class ResponseCode { public void setLink(String link) { this.link = link; } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/online/Generator.java b/modules/swagger-generator/src/main/java/io/swagger/generator/online/Generator.java index fecd5706361..2435a3170ca 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/online/Generator.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/online/Generator.java @@ -28,7 +28,8 @@ public class Generator { try { config = CodegenConfigLoader.forName(language); } 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 map = new LinkedHashMap(); for (CliOption option : config.cliOptions()) { @@ -38,8 +39,7 @@ public class Generator { } public enum Type { - CLIENT("client"), - SERVER("server"); + CLIENT("client"), SERVER("server"); private String name; @@ -60,37 +60,39 @@ public class Generator { 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)); if (opts == null) { throw new BadRequestException("No options were supplied"); } JsonNode node = opts.getSpec(); - if(node != null && "{}".equals(node.toString())) { + if (node != null && "{}".equals(node.toString())) { LOGGER.debug("ignoring empty spec"); node = null; } Swagger swagger; if (node == null) { if (opts.getSwaggerUrl() != null) { - if(opts.getAuthorizationValue() != null) { - List authorizationValues = new ArrayList(); + if (opts.getAuthorizationValue() != null) { + List authorizationValues = + new ArrayList(); authorizationValues.add(opts.getAuthorizationValue()); - swagger = new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues, true); - } - else { + swagger = + new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues, + true); + } else { swagger = new SwaggerParser().read(opts.getSwaggerUrl()); } } else { throw new BadRequestException("No swagger specification was supplied"); } - } else if(opts.getAuthorizationValue() != null) { + } else if (opts.getAuthorizationValue() != null) { List authorizationValues = new ArrayList(); authorizationValues.add(opts.getAuthorizationValue()); swagger = new SwaggerParser().read(node, authorizationValues, true); - } - else { + } else { swagger = new SwaggerParser().read(node, true); } if (swagger == null) { @@ -99,12 +101,11 @@ public class Generator { String destPath = null; - if(opts != null && opts.getOptions() != null) { + if (opts != null && opts.getOptions() != null) { destPath = opts.getOptions().get("outputFolder"); } - if(destPath == null) { - destPath = language + "-" - + type.getTypeName(); + if (destPath == null) { + destPath = language + "-" + type.getTypeName(); } ClientOptInput clientOptInput = new ClientOptInput(); @@ -112,14 +113,12 @@ public class Generator { String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath; String outputFilename = outputFolder + "-bundle.zip"; - clientOptInput - .opts(clientOpts) - .swagger(swagger); + clientOptInput.opts(clientOpts).swagger(swagger); - CodegenConfig codegenConfig=null; + CodegenConfig codegenConfig = null; try { codegenConfig = CodegenConfigLoader.forName(language); - } catch(RuntimeException e) { + } catch (RuntimeException e) { throw new BadRequestException("Unsupported target " + language + " supplied"); } @@ -143,20 +142,19 @@ public class Generator { ZipUtil zip = new ZipUtil(); zip.compressFiles(filesToAdd, outputFilename); } 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 { file.delete(); - } - catch(Exception e) { + } catch (Exception e) { LOGGER.error("unable to delete file " + file.getAbsolutePath()); } } try { new File(outputFolder).delete(); - } - catch (Exception e) { + } catch (Exception e) { LOGGER.error("unable to delete output folder " + outputFolder); } } catch (Exception e) { diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/resource/ExceptionWriter.java b/modules/swagger-generator/src/main/java/io/swagger/generator/resource/ExceptionWriter.java index 122561ddd94..e2fac57d7d0 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/resource/ExceptionWriter.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/resource/ExceptionWriter.java @@ -17,35 +17,26 @@ public class ExceptionWriter implements ExceptionMapper { public Response toResponse(Exception exception) { if (exception instanceof javax.ws.rs.WebApplicationException) { javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception; - return Response - .status(e.getResponse().getStatus()) - .entity(new ApiResponse(e.getResponse().getStatus(), - exception.getMessage())).build(); + return Response.status(e.getResponse().getStatus()) + .entity(new ApiResponse(e.getResponse().getStatus(), exception.getMessage())) + .build(); } else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) { - return Response.status(400) - .entity(new ApiResponse(400, "bad input")).build(); + return Response.status(400).entity(new ApiResponse(400, "bad input")).build(); } else if (exception instanceof ValidationException) { ValidationException e = (ValidationException) exception; return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); } else if (exception instanceof NotFoundException) { - return Response - .status(Status.NOT_FOUND) - .entity(new ApiResponse(ApiResponse.ERROR, exception - .getMessage())).build(); + return Response.status(Status.NOT_FOUND) + .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); } else if (exception instanceof BadRequestException) { - return Response - .status(Status.BAD_REQUEST) - .entity(new ApiResponse(ApiResponse.ERROR, exception - .getMessage())).build(); + return Response.status(Status.BAD_REQUEST) + .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); } else if (exception instanceof ApiException) { - return Response - .status(Status.BAD_REQUEST) - .entity(new ApiResponse(ApiResponse.ERROR, exception - .getMessage())).build(); + return Response.status(Status.BAD_REQUEST) + .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); } else { - return Response.status(500) - .entity(new ApiResponse(500, "something bad happened")) + return Response.status(500).entity(new ApiResponse(500, "something bad happened")) .build(); } } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/resource/SwaggerResource.java b/modules/swagger-generator/src/main/java/io/swagger/generator/resource/SwaggerResource.java index ad6529bd36a..4220e1034a6 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/resource/SwaggerResource.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/resource/SwaggerResource.java @@ -34,7 +34,8 @@ public class SwaggerResource { static { List extensions = Codegen.getExtensions(); 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()); } else if (config.getTag().equals(CodegenType.SERVER)) { servers.add(config.getName()); @@ -48,12 +49,11 @@ public class SwaggerResource { @GET @Path("/download/{fileId}") @Produces({MediaType.APPLICATION_OCTET_STREAM}) - @ApiOperation(value = "Downloads a pre-generated file", - notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST " + - "operations. The fileId code can be used just once, after which a new `fileId` will need to " + - "be requested.", - response = String.class, - tags = {"clients", "servers"}) + @ApiOperation( + value = "Downloads a pre-generated file", + notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST " + + "operations. The fileId code can be used just once, after which a new `fileId` will need to " + + "be requested.", response = String.class, tags = {"clients", "servers"}) public Response downloadFile(@PathParam("fileId") String fileId) throws Exception { Generated g = fileMap.get(fileId); System.out.println("looking for fileId " + fileId); @@ -64,16 +64,15 @@ public class SwaggerResource { try { FileUtils.deleteDirectory(file.getParentFile()); - } - catch (Exception e) { + } catch (Exception e) { System.out.println("failed to delete file " + file.getAbsolutePath()); } - return Response.ok(bytes, "application/zip") - .header("Content-Disposition", "attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"") - .header("Accept-Range", "bytes") - .header("Content-Length", bytes.length) - .build(); + return Response + .ok(bytes, "application/zip") + .header("Content-Disposition", + "attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"") + .header("Accept-Range", "bytes").header("Content-Length", bytes.length).build(); } else { return Response.status(404).build(); } @@ -84,23 +83,22 @@ public class SwaggerResource { @ApiOperation( value = "Generates a client library", notes = "Accepts a `GeneratorInput` options map for spec location and generation options", - response = ResponseCode.class, - tags = "clients") + response = ResponseCode.class, tags = "clients") public Response generateClient( @Context HttpServletRequest request, @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 host = System.getenv("GENERATOR_HOST"); - if(StringUtils.isBlank(host)) { + if (StringUtils.isBlank(host)) { String scheme = request.getHeader("X-SSL"); String port = ""; - if("1".equals(scheme)) { + if ("1".equals(scheme)) { scheme = "https"; - } - else { + } else { scheme = request.getScheme(); port = ":" + request.getServerPort(); } @@ -124,15 +122,12 @@ public class SwaggerResource { @GET @Path("/clients/{language}") @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation( - value = "Returns options for a client library", - response = CliOption.class, - responseContainer = "map", - tags = "clients") + @ApiOperation(value = "Returns options for a client library", response = CliOption.class, + responseContainer = "map", tags = "clients") public Response getClientOptions( @SuppressWarnings("unused") @Context HttpServletRequest request, - @ApiParam(value = "The target language for the client library", required = true) - @PathParam("language") String language) throws Exception { + @ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language) + throws Exception { Map opts = Generator.getOptions(language); @@ -146,15 +141,12 @@ public class SwaggerResource { @GET @Path("/servers/{framework}") @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation( - value = "Returns options for a server framework", - response = CliOption.class, - responseContainer = "map", - tags = "servers") + @ApiOperation(value = "Returns options for a server framework", response = CliOption.class, + responseContainer = "map", tags = "servers") public Response getServerOptions( @SuppressWarnings("unused") @Context HttpServletRequest request, - @ApiParam(value = "The target language for the server framework", required = true) - @PathParam("framework") String framework) throws Exception { + @ApiParam(value = "The target language for the server framework", required = true) @PathParam("framework") String framework) + throws Exception { Map opts = Generator.getOptions(framework); @@ -168,9 +160,7 @@ public class SwaggerResource { @GET @Path("/clients") @ApiOperation(value = "Gets languages supported by the client generator", - response = String.class, - responseContainer = "List", - tags = "clients") + response = String.class, responseContainer = "List", tags = "clients") public Response clientOptions() { String[] languages = new String[clients.size()]; languages = clients.toArray(languages); @@ -180,9 +170,7 @@ public class SwaggerResource { @GET @Path("/servers") @ApiOperation(value = "Gets languages supported by the server generator", - response = String.class, - responseContainer = "List", - tags = "servers") + response = String.class, responseContainer = "List", tags = "servers") public Response serverOptions() { String[] languages = new String[servers.size()]; languages = servers.toArray(languages); @@ -191,22 +179,22 @@ public class SwaggerResource { @POST @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.", - response = ResponseCode.class, - tags = "servers") - public Response generateServerForLanguage( - @Context HttpServletRequest request, - @ApiParam(value = "framework", required = true) @PathParam("framework") String framework, - @ApiParam(value = "parameters", required = true) GeneratorInput opts) - throws Exception { + response = ResponseCode.class, tags = "servers") + public Response generateServerForLanguage(@Context HttpServletRequest request, @ApiParam( + value = "framework", required = true) @PathParam("framework") String framework, + @ApiParam(value = "parameters", required = true) GeneratorInput opts) throws Exception { if (framework == null) { throw new BadRequestException("Framework is required"); } String filename = Generator.generateServer(framework, opts); 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) { String code = String.valueOf(UUID.randomUUID().toString()); diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ApiOriginFilter.java b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ApiOriginFilter.java index aca470bd89b..b4eb8d92ff7 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ApiOriginFilter.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ApiOriginFilter.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.util; @@ -26,8 +24,8 @@ import java.io.IOException; public class ApiOriginFilter implements javax.servlet.Filter { @Override - public void doFilter(ServletRequest request, ServletResponse response, - FilterChain chain) throws IOException, ServletException { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { HttpServletResponse res = (HttpServletResponse) response; res.addHeader("Access-Control-Allow-Origin", "*"); res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); @@ -36,10 +34,8 @@ public class ApiOriginFilter implements javax.servlet.Filter { } @Override - public void destroy() { - } + public void destroy() {} @Override - public void init(FilterConfig filterConfig) throws ServletException { - } -} \ No newline at end of file + public void init(FilterConfig filterConfig) throws ServletException {} +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/util/JacksonJsonProvider.java b/modules/swagger-generator/src/main/java/io/swagger/generator/util/JacksonJsonProvider.java index 713ee2455c4..c26f11aa6d2 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/util/JacksonJsonProvider.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/util/JacksonJsonProvider.java @@ -17,4 +17,4 @@ public class JacksonJsonProvider extends JacksonJaxbJsonProvider { public JacksonJsonProvider() { super.setMapper(commonMapper); } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationException.java b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationException.java index 631541f6c01..99eb397e996 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationException.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationException.java @@ -25,4 +25,4 @@ public class ValidationException extends Exception { public void setMessage(String msg) { this.msg = msg; } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationMessage.java b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationMessage.java index 9e0218e3809..40b26562501 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationMessage.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationMessage.java @@ -26,4 +26,4 @@ public class ValidationMessage { public void setSeverity(String severity) { this.severity = severity; } -} \ No newline at end of file +} diff --git a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ZipUtil.java b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ZipUtil.java index 88b4cbf6c8a..80c1872b999 100644 --- a/modules/swagger-generator/src/main/java/io/swagger/generator/util/ZipUtil.java +++ b/modules/swagger-generator/src/main/java/io/swagger/generator/util/ZipUtil.java @@ -1,17 +1,15 @@ /** * Copyright 2016 SmartBear Software *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package io.swagger.generator.util; @@ -27,8 +25,9 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** - * This utility compresses a list of files to standard ZIP format file. - * It is able to compresses all sub files and sub directories, recursively. + * This utility compresses a list of files to standard ZIP format file. It is able to compresses all + * sub files and sub directories, recursively. + * * @author Ha Minh Nam * */ @@ -40,6 +39,7 @@ public class ZipUtil { /** * Compresses a collection of files to a destination zip file. + * * @param listFiles A collection of files and directories * @param destZipFile The path of the destination zip file * @throws FileNotFoundException if file not found @@ -64,14 +64,15 @@ public class ZipUtil { /** * 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 zos the current zip output stream * @throws FileNotFoundException if file not found * @throws IOException if IO exception occurs */ - private void addFolderToZip(File folder, String parentFolder, - ZipOutputStream zos) throws FileNotFoundException, IOException { + private void addFolderToZip(File folder, String parentFolder, ZipOutputStream zos) + throws FileNotFoundException, IOException { for (File file : folder.listFiles()) { if (file.isDirectory()) { addFolderToZip(file, parentFolder + "/" + file.getName(), zos); @@ -80,8 +81,7 @@ public class ZipUtil { zos.putNextEntry(new ZipEntry(parentFolder + "/" + file.getName())); - BufferedInputStream bis = new BufferedInputStream( - new FileInputStream(file)); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); long bytesRead = 0; byte[] bytesIn = new byte[BUFFER_SIZE]; @@ -99,17 +99,17 @@ public class ZipUtil { /** * Adds a file to the current zip output stream. + * * @param file the file to be added * @param zos the current zip output stream * @throws FileNotFoundException if file not found * @throws IOException if IO exception occurs */ - private static void addFileToZip(File file, ZipOutputStream zos) - throws FileNotFoundException, IOException { + private static void addFileToZip(File file, ZipOutputStream zos) throws FileNotFoundException, + IOException { zos.putNextEntry(new ZipEntry(file.getName())); - BufferedInputStream bis = new BufferedInputStream(new FileInputStream( - file)); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte[] bytesIn = new byte[BUFFER_SIZE]; int read = 0; diff --git a/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineGeneratorOptionsTest.java b/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineGeneratorOptionsTest.java index 900f659848f..c24307ea4fd 100644 --- a/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineGeneratorOptionsTest.java +++ b/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineGeneratorOptionsTest.java @@ -32,32 +32,35 @@ public class OnlineGeneratorOptionsTest { @DataProvider(name = OPTIONS_PROVIDER) private static Object[][] listOptions() { - return new Object[][]{{new AkkaScalaClientOptionsProvider()}, {new AndroidClientOptionsProvider()}, - {new AsyncScalaClientOptionsProvider()}, {new CSharpClientOptionsProvider()}, - {new CsharpDotNet2ClientOptionsProvider()}, {new DartClientOptionsProvider()}, - {new FlashClienOptionsProvider()}, {new JavaInflectorServerOptionsProvider()}, + return new Object[][] { + {new AkkaScalaClientOptionsProvider()}, + {new AndroidClientOptionsProvider()}, + {new AsyncScalaClientOptionsProvider()}, + {new CSharpClientOptionsProvider()}, + {new CsharpDotNet2ClientOptionsProvider()}, + {new DartClientOptionsProvider()}, + {new FlashClienOptionsProvider()}, + {new JavaInflectorServerOptionsProvider()}, { new JavaOptionsProvider(), - new JavaOptionsProvider(ImmutableMap.of(CodegenConstants.LIBRARY, JavaClientCodegen.RETROFIT_2) - ), - new JavaOptionsProvider(ImmutableMap.of( - CodegenConstants.LIBRARY, JavaClientCodegen.RETROFIT_2, - JavaClientCodegen.USE_RX_JAVA, "true") - ) - }, - {new JaxRSServerOptionsProvider()}, - {new NodeJSServerOptionsProvider()}, {new ObjcClientOptionsProvider()}, - {new PerlClientOptionsProvider()}, {new PhpClientOptionsProvider()}, - {new PythonClientOptionsProvider()}, {new Qt5CPPOptionsProvider()}, - {new RubyClientOptionsProvider()}, {new ScalaClientOptionsProvider()}, - {new ScalatraServerOptionsProvider()}, {new SilexServerOptionsProvider()}, - {new SinatraServerOptionsProvider()}, {new SlimFrameworkServerOptionsProvider()}, - {new SpringOptionsProvider()}, {new StaticDocOptionsProvider()}, - {new StaticHtmlOptionsProvider()}, {new SwaggerOptionsProvider()}, - {new SwaggerYamlOptionsProvider()}, {new SwiftOptionsProvider()}, - {new TizenClientOptionsProvider()}, {new TypeScriptAngularClientOptionsProvider()}, - {new TypeScriptNodeClientOptionsProvider()}, {new LumenServerOptionsProvider()} - }; + new JavaOptionsProvider(ImmutableMap.of(CodegenConstants.LIBRARY, + JavaClientCodegen.RETROFIT_2)), + new JavaOptionsProvider( + ImmutableMap.of(CodegenConstants.LIBRARY, + JavaClientCodegen.RETROFIT_2, + JavaClientCodegen.USE_RX_JAVA, "true"))}, + {new JaxRSServerOptionsProvider()}, {new NodeJSServerOptionsProvider()}, + {new ObjcClientOptionsProvider()}, {new PerlClientOptionsProvider()}, + {new PhpClientOptionsProvider()}, {new PythonClientOptionsProvider()}, + {new Qt5CPPOptionsProvider()}, {new RubyClientOptionsProvider()}, + {new ScalaClientOptionsProvider()}, {new ScalatraServerOptionsProvider()}, + {new SilexServerOptionsProvider()}, {new SinatraServerOptionsProvider()}, + {new SlimFrameworkServerOptionsProvider()}, {new SpringOptionsProvider()}, + {new StaticDocOptionsProvider()}, {new StaticHtmlOptionsProvider()}, + {new SwaggerOptionsProvider()}, {new SwaggerYamlOptionsProvider()}, + {new SwiftOptionsProvider()}, {new TizenClientOptionsProvider()}, + {new TypeScriptAngularClientOptionsProvider()}, + {new TypeScriptNodeClientOptionsProvider()}, {new LumenServerOptionsProvider()}}; } @Test(dataProvider = OPTIONS_PROVIDER) @@ -83,15 +86,15 @@ public class OnlineGeneratorOptionsTest { outputFilename = Generator.generateClient(provider.getLanguage(), input); } final File dir = new File(new File(outputFilename).getParent()); - + try { FileUtils.deleteDirectory(dir); } catch (Exception e) { // directory can't be deleted for some reasons e.printStackTrace(); } for (InvocationCounter option : options.values()) { - assertNotEquals(option.getCounter(), 0, String.format("Option \"%s\" wasn't processed.", - option.getValue())); + assertNotEquals(option.getCounter(), 0, + String.format("Option \"%s\" wasn't processed.", option.getValue())); } } @@ -135,24 +138,27 @@ public class OnlineGeneratorOptionsTest { public static void getOptionsTest(OptionsProvider provider) throws ApiException { final Map opts = Generator.getOptions(provider.getLanguage()); - final Function cliOptionWrapper = new Function() { - @Nullable - @Override - public CliOptionProxy apply(@Nullable CliOption option) { - return new CliOptionProxy(option); - } - }; + final Function cliOptionWrapper = + new Function() { + @Nullable + @Override + public CliOptionProxy apply(@Nullable CliOption option) { + return new CliOptionProxy(option); + } + }; - final List actual = Lists.transform(new ArrayList(opts.values()), cliOptionWrapper); - final List expected = Lists.transform( - CodegenConfigLoader.forName(provider.getLanguage()).cliOptions(), cliOptionWrapper); + final List actual = + Lists.transform(new ArrayList(opts.values()), cliOptionWrapper); + final List expected = + Lists.transform(CodegenConfigLoader.forName(provider.getLanguage()).cliOptions(), + cliOptionWrapper); assertEquals(actual, expected); } protected static class CliOptionProxy { private final CliOption wrapped; - public CliOptionProxy(CliOption wrapped){ + public CliOptionProxy(CliOption wrapped) { this.wrapped = wrapped; } diff --git a/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineJavaClientOptionsTest.java b/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineJavaClientOptionsTest.java index c58844fb1da..e3ad18ecbdc 100644 --- a/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineJavaClientOptionsTest.java +++ b/modules/swagger-generator/src/test/java/io/swagger/generator/online/OnlineJavaClientOptionsTest.java @@ -18,7 +18,8 @@ public class OnlineJavaClientOptionsTest { @Test public void getOptionsTest() throws ApiException { - final Map options = Generator.getOptions(new JavaOptionsProvider().getLanguage()); + final Map options = + Generator.getOptions(new JavaOptionsProvider().getLanguage()); assertNotNull(options); final CliOption opt = options.get(CodegenConstants.LIBRARY); assertNotNull(opt);