Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improvements to online codegen #55

Merged
merged 2 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/openapi-generator-online/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM openjdk:8-jre-alpine

WORKDIR /generator

COPY target/openapi-generator-online-3.0.0-SNAPSHOT.jar /generator/openapi-generator-online.jar
COPY target/*.jar /generator/openapi-generator-online.jar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbornet I tried *.jar before but I got errors and that's why I used the full filename instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird. Works on my machine 😉 . And that's also what we do in JHipster.
Did you do mvn clean before packaging ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go with this. If it breaks with errors, we'll just revert the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I also tested *.jar locally before and worked fine for me)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the error reported by the CI (travis):

Removing intermediate container eaef9e5f5b5b
Step 3/6 : COPY target/*.jar /generator/openapi-generator-online.jar
When using COPY with more than one source file, the destination must be a directory and end with a /

Ref: https://travis-ci.org/OpenAPITools/openapi-generator/builds/379603374

I'll submit a PR to fix it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems there are multiple jar in the target directory. That shouldn't be the case, isn't it ?
Can you try COPY target/openapi-generator-online*.jar /generator/openapi-generator-online.jar so there's no need to modify the Dockerfile for each new version ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same result:

Removing intermediate container 5b368abf32be
Step 3/6 : COPY target/openapi-generator-online-*.jar /generator/openapi-generator-online.jar
When using COPY with more than one source file, the destination must be a directory and end with a /

Let's go with the hard-coded solution for the time being as it's not something we want to automate with the highest priority.


ENV GENERATOR_HOST=http://localhost

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
public class OpenAPI2SpringBoot implements CommandLineRunner {

@Override
public void run(String... arg0) throws Exception {
public void run(String... arg0) {
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
throw new ExitException();
}
}

public static void main(String[] args) throws Exception {
public static void main(String[] args) {
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -51,9 +52,9 @@ default ResponseEntity<List<String>> clientOptions() {
}


@ApiOperation(value = "Downloads a pre-generated file", nickname = "downloadFile", 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", nickname = "downloadFile", 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 = MultipartFile.class, tags={ "clients","servers", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class) })
@ApiResponse(code = 200, message = "successful operation", response = MultipartFile.class) })
@RequestMapping(value = "/gen/download/{fileId}",
produces = { "application/octet-stream" },
method = RequestMethod.GET)
Expand Down Expand Up @@ -82,9 +83,9 @@ default ResponseEntity<ResponseCode> generateServerForLanguage(@ApiParam(value =
}


@ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "clients", })
@ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", tags={ "clients", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
@ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/gen/clients/{language}",
produces = { "application/json" },
method = RequestMethod.GET)
Expand All @@ -93,9 +94,9 @@ default ResponseEntity<Map<String, CliOption>> getClientOptions(@ApiParam(value
}


@ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "servers", })
@ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", tags={ "servers", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
@ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/gen/servers/{framework}",
produces = { "application/json" },
method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/api")
public class GenApiController implements GenApi {

private final GenApiDelegate delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
public class HomeController {
@RequestMapping(value = "/")
public String index() {
System.out.println("swagger-ui.html");
return "redirect:swagger-ui.html";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

package org.openapitools.codegen.online.configuration;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.core.io.Resource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
Expand All @@ -28,6 +29,8 @@
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.io.InputStream;


@Configuration
@EnableSwagger2
Expand All @@ -51,8 +54,12 @@ public Docket customImplementation(){
.select()
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
.build()
.forCodeGeneration(true)
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
.directModelSubstitute(JsonNode.class, java.lang.Object.class)
.ignoredParameterTypes(Resource.class)
.ignoredParameterTypes(InputStream.class)
.apiInfo(apiInfo());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void setAuthorizationValue(AuthorizationValue authorizationValue) {
this.authorizationValue = authorizationValue;
}

@ApiModelProperty(dataType = "Object")
public JsonNode getSpec() {
return spec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
import java.util.Map;

public class Generator {
static Logger LOGGER = LoggerFactory.getLogger(Generator.class);
private static Logger LOGGER = LoggerFactory.getLogger(Generator.class);

public static Map<String, CliOption> getOptions(String language) {
CodegenConfig config = null;
CodegenConfig config;
try {
config = CodegenConfigLoader.forName(language);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
language, e));
}
Map<String, CliOption> map = new LinkedHashMap<String, CliOption>();
Map<String, CliOption> map = new LinkedHashMap<>();
for (CliOption option : config.cliOptions()) {
map.put(option.getOpt(), option);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ private static String generate(String language, GeneratorInput opts, Type type)
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied");
}
} else if (opts.getAuthorizationValue() != null) {
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
List<AuthorizationValue> authorizationValues = new ArrayList<>();
authorizationValues.add(opts.getAuthorizationValue());
openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI();

Expand All @@ -115,7 +115,7 @@ private static String generate(String language, GeneratorInput opts, Type type)

String destPath = null;

if (opts != null && opts.getOptions() != null) {
if (opts.getOptions() != null) {
destPath = opts.getOptions().get("outputFolder");
}
if (destPath == null) {
Expand All @@ -129,7 +129,7 @@ private static String generate(String language, GeneratorInput opts, Type type)

clientOptInput.opts(clientOpts).openAPI(openapi);

CodegenConfig codegenConfig = null;
CodegenConfig codegenConfig;
try {
codegenConfig = CodegenConfigLoader.forName(language);
} catch (RuntimeException e) {
Expand All @@ -150,7 +150,7 @@ private static String generate(String language, GeneratorInput opts, Type type)
try {
List<File> files = new DefaultGenerator().opts(clientOptInput).generate();
if (files.size() > 0) {
List<File> filesToAdd = new ArrayList<File>();
List<File> filesToAdd = new ArrayList<>();
LOGGER.debug("adding to " + outputFolder);
filesToAdd.add(new File(outputFolder));
ZipUtil zip = new ZipUtil();
Expand All @@ -177,7 +177,7 @@ private static String generate(String language, GeneratorInput opts, Type type)
return outputFilename;
}

protected static File getTmpFolder() {
private static File getTmpFolder() {
try {
File outputFolder = File.createTempFile("codegen-", "-tmp");
outputFolder.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ZipUtil {
* @throws IOException if IO exception occurs
*/
public void compressFiles(List<File> listFiles, String destZipFile)
throws FileNotFoundException, IOException {
throws IOException {

ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
springfox.documentation.swagger.v2.path=/api-docs
server.servlet.context-path=/api
server.port=8080
spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false