mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Improvements to online codegen (#55)
* Change openapi-online context path * Fix openAPI generated spec of openapi-online
This commit is contained in:
parent
6b8079808b
commit
e3814f51d8
@ -1,8 +1,8 @@
|
|||||||
FROM openjdk:8-jre-alpine
|
FROM openjdk:8-jre-alpine
|
||||||
|
|
||||||
WORKDIR /generator
|
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
|
||||||
|
|
||||||
ENV GENERATOR_HOST=http://localhost
|
ENV GENERATOR_HOST=http://localhost
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ import org.springframework.context.annotation.ComponentScan;
|
|||||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... arg0) throws Exception {
|
public void run(String... arg0) {
|
||||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||||
throw new ExitException();
|
throw new ExitException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) {
|
||||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -51,9 +52,9 @@ public interface GenApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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 = {
|
@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}",
|
@RequestMapping(value = "/gen/download/{fileId}",
|
||||||
produces = { "application/octet-stream" },
|
produces = { "application/octet-stream" },
|
||||||
method = RequestMethod.GET)
|
method = RequestMethod.GET)
|
||||||
@ -82,9 +83,9 @@ public interface GenApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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 = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
|
@ApiResponse(code = 200, message = "successful operation") })
|
||||||
@RequestMapping(value = "/gen/clients/{language}",
|
@RequestMapping(value = "/gen/clients/{language}",
|
||||||
produces = { "application/json" },
|
produces = { "application/json" },
|
||||||
method = RequestMethod.GET)
|
method = RequestMethod.GET)
|
||||||
@ -93,9 +94,9 @@ public interface GenApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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 = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") })
|
@ApiResponse(code = 200, message = "successful operation") })
|
||||||
@RequestMapping(value = "/gen/servers/{framework}",
|
@RequestMapping(value = "/gen/servers/{framework}",
|
||||||
produces = { "application/json" },
|
produces = { "application/json" },
|
||||||
method = RequestMethod.GET)
|
method = RequestMethod.GET)
|
||||||
|
@ -19,8 +19,10 @@ package org.openapitools.codegen.online.api;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@RequestMapping("/api")
|
||||||
public class GenApiController implements GenApi {
|
public class GenApiController implements GenApi {
|
||||||
|
|
||||||
private final GenApiDelegate delegate;
|
private final GenApiDelegate delegate;
|
||||||
|
@ -27,7 +27,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
public class HomeController {
|
public class HomeController {
|
||||||
@RequestMapping(value = "/")
|
@RequestMapping(value = "/")
|
||||||
public String index() {
|
public String index() {
|
||||||
System.out.println("swagger-ui.html");
|
|
||||||
return "redirect:swagger-ui.html";
|
return "redirect:swagger-ui.html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,10 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.online.configuration;
|
package org.openapitools.codegen.online.configuration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
import springfox.documentation.service.ApiInfo;
|
import springfox.documentation.service.ApiInfo;
|
||||||
@ -28,6 +29,8 @@ import springfox.documentation.spi.DocumentationType;
|
|||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
@ -51,8 +54,12 @@ public class OpenAPIDocumentationConfig {
|
|||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
|
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
|
||||||
.build()
|
.build()
|
||||||
|
.forCodeGeneration(true)
|
||||||
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
|
||||||
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.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());
|
.apiInfo(apiInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ public class GeneratorInput {
|
|||||||
this.authorizationValue = authorizationValue;
|
this.authorizationValue = authorizationValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiModelProperty(dataType = "Object")
|
|
||||||
public JsonNode getSpec() {
|
public JsonNode getSpec() {
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,17 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Generator {
|
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) {
|
public static Map<String, CliOption> getOptions(String language) {
|
||||||
CodegenConfig config = null;
|
CodegenConfig config;
|
||||||
try {
|
try {
|
||||||
config = CodegenConfigLoader.forName(language);
|
config = CodegenConfigLoader.forName(language);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
|
||||||
language, e));
|
language, e));
|
||||||
}
|
}
|
||||||
Map<String, CliOption> map = new LinkedHashMap<String, CliOption>();
|
Map<String, CliOption> map = new LinkedHashMap<>();
|
||||||
for (CliOption option : config.cliOptions()) {
|
for (CliOption option : config.cliOptions()) {
|
||||||
map.put(option.getOpt(), option);
|
map.put(option.getOpt(), option);
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ public class Generator {
|
|||||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied");
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied");
|
||||||
}
|
}
|
||||||
} else if (opts.getAuthorizationValue() != null) {
|
} else if (opts.getAuthorizationValue() != null) {
|
||||||
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
|
List<AuthorizationValue> authorizationValues = new ArrayList<>();
|
||||||
authorizationValues.add(opts.getAuthorizationValue());
|
authorizationValues.add(opts.getAuthorizationValue());
|
||||||
openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI();
|
openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI();
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ public class Generator {
|
|||||||
|
|
||||||
String destPath = null;
|
String destPath = null;
|
||||||
|
|
||||||
if (opts != null && opts.getOptions() != null) {
|
if (opts.getOptions() != null) {
|
||||||
destPath = opts.getOptions().get("outputFolder");
|
destPath = opts.getOptions().get("outputFolder");
|
||||||
}
|
}
|
||||||
if (destPath == null) {
|
if (destPath == null) {
|
||||||
@ -129,7 +129,7 @@ public class Generator {
|
|||||||
|
|
||||||
clientOptInput.opts(clientOpts).openAPI(openapi);
|
clientOptInput.opts(clientOpts).openAPI(openapi);
|
||||||
|
|
||||||
CodegenConfig codegenConfig = null;
|
CodegenConfig codegenConfig;
|
||||||
try {
|
try {
|
||||||
codegenConfig = CodegenConfigLoader.forName(language);
|
codegenConfig = CodegenConfigLoader.forName(language);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
@ -150,7 +150,7 @@ public class Generator {
|
|||||||
try {
|
try {
|
||||||
List<File> files = new DefaultGenerator().opts(clientOptInput).generate();
|
List<File> files = new DefaultGenerator().opts(clientOptInput).generate();
|
||||||
if (files.size() > 0) {
|
if (files.size() > 0) {
|
||||||
List<File> filesToAdd = new ArrayList<File>();
|
List<File> filesToAdd = new ArrayList<>();
|
||||||
LOGGER.debug("adding to " + outputFolder);
|
LOGGER.debug("adding to " + outputFolder);
|
||||||
filesToAdd.add(new File(outputFolder));
|
filesToAdd.add(new File(outputFolder));
|
||||||
ZipUtil zip = new ZipUtil();
|
ZipUtil zip = new ZipUtil();
|
||||||
@ -177,7 +177,7 @@ public class Generator {
|
|||||||
return outputFilename;
|
return outputFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getTmpFolder() {
|
private static File getTmpFolder() {
|
||||||
try {
|
try {
|
||||||
File outputFolder = File.createTempFile("codegen-", "-tmp");
|
File outputFolder = File.createTempFile("codegen-", "-tmp");
|
||||||
outputFolder.delete();
|
outputFolder.delete();
|
||||||
|
@ -49,7 +49,7 @@ public class ZipUtil {
|
|||||||
* @throws IOException if IO exception occurs
|
* @throws IOException if IO exception occurs
|
||||||
*/
|
*/
|
||||||
public void compressFiles(List<File> listFiles, String destZipFile)
|
public void compressFiles(List<File> listFiles, String destZipFile)
|
||||||
throws FileNotFoundException, IOException {
|
throws IOException {
|
||||||
|
|
||||||
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
springfox.documentation.swagger.v2.path=/api-docs
|
springfox.documentation.swagger.v2.path=/api-docs
|
||||||
server.servlet.context-path=/api
|
|
||||||
server.port=8080
|
server.port=8080
|
||||||
spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat
|
spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat
|
||||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user