mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-08 13:36:11 +00:00
Implement Source DocumentationProvider, spring-mvc decommission (#11531)
* - Upgrade swagger-ui to 4.4.1 - Bring homeController.mustache up-to-date - Main class is now OpenApiGeneratorApplication - Introduce SpringBootTest.mustache - Remove option swaggerDocketConfig/openapiDocketConfig in favor of documentationProvider. * Generate Samples * Restore generator-online classes Fix spring-mvc builds * Generate Samples * Do not generate SpringFoxConfiguration.java when reactive ist set. * Fix generation of SpringFoxConfiguration * Generate Documentation * Reactive support: add dependency management for springdoc-openapi-webflux-ui * Generate Samples * Change SpringBootApplication to OpenApiGeneratorApplication * Generate Samples * Implement SwaggerUIFeatures in SpringCodegen * Generate Samples * Add useSwaggerUI: true to some test configs * Generate Samples * Update Documentation * Update Documentation * Update README.mustache * Generate Samples * useSwaggerUI is true by default * Generate Samples * Update Documentation * Add deprecation warnings to cli opts; Log a deprecation warning * Update Documentation * Generate Samples * Remove spring-mvc library * Remove spring-mvc from project and CI configs * Check whether the selected documentation provider requires us to boostrap swagger-ui. * Generate Samples * Generate samples * Generate samples * Generate samples
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenAPI2SpringBoot implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplication(OpenAPI2SpringBoot.class).run(args);
|
||||
}
|
||||
|
||||
static class ExitException extends RuntimeException implements ExitCodeGenerator {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
/*@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("Content-Type");
|
||||
}*/
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.openapitools;
|
||||
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"})
|
||||
public class OpenApiGeneratorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OpenApiGeneratorApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module jsonNullableModule() {
|
||||
return new JsonNullableModule();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.openapitools.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Home redirection to OpenAPI api documentation
|
||||
@@ -10,10 +12,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
static final String API_DOCS_PATH = "/v2/api-docs";
|
||||
|
||||
@GetMapping(value = "/swagger-config.yaml", produces = "text/plain")
|
||||
@ResponseBody
|
||||
public String swaggerConfig() {
|
||||
return "url: " + API_DOCS_PATH + "\n";
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index() {
|
||||
return "redirect:swagger-ui.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,13 @@ import springfox.documentation.spring.web.paths.RelativePathProvider;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class OpenAPIDocumentationConfig {
|
||||
public class SpringFoxConfiguration {
|
||||
|
||||
ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
@@ -1,4 +1,3 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.port=80
|
||||
spring.jackson.date-format=org.openapitools.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="webjars/swagger-ui/swagger-ui.css" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="webjars/swagger-ui/favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="webjars/swagger-ui/swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="webjars/swagger-ui/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Begin Swagger UI call region
|
||||
const ui = SwaggerUIBundle({
|
||||
configUrl: 'swagger-config.yaml',
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
});
|
||||
// End Swagger UI call region
|
||||
|
||||
window.ui = ui;
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.openapitools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OpenApiGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user