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:
cachescrubber
2022-02-12 10:25:21 +01:00
committed by GitHub
parent b01bcfecde
commit 0ed147e7a4
656 changed files with 3951 additions and 62924 deletions

View File

@@ -1,6 +1,6 @@
README.md
pom.xml
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
src/main/java/org/openapitools/RFC3339DateFormat.java
src/main/java/org/openapitools/api/AnotherFakeApi.java
src/main/java/org/openapitools/api/AnotherFakeApiController.java
@@ -66,3 +66,4 @@ src/main/java/org/openapitools/model/User.java
src/main/java/org/openapitools/model/XmlItem.java
src/main/resources/application.properties
src/main/resources/openapi.yaml
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java

View File

@@ -2,15 +2,20 @@
Spring Boot Server
## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
The specification is available to download using the following url:
http://localhost:80/v3/api-docs/
Start your server as a simple java application
You can view the api documentation in swagger-ui by pointing to
http://localhost:80/
http://localhost:80/swagger-ui.html
Change default port value in application.properties

View File

@@ -10,11 +10,12 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springdoc.version>1.6.4</springdoc.version>
<swagger-ui.version>4.4.1-1</swagger-ui.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<version>2.6.3</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
@@ -63,5 +64,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,58 +0,0 @@
package org.openapitools;
import com.fasterxml.jackson.databind.Module;
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.ResourceHandlerRegistry;
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");
}*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
}
};
}
}

View File

@@ -0,0 +1,17 @@
package org.openapitools;
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);
}
}

View File

@@ -1,18 +1,10 @@
package org.openapitools.configuration;
import org.springframework.context.annotation.Bean;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.springframework.web.bind.annotation.GetMapping;
/**
* Home redirection to OpenAPI api documentation
@@ -20,34 +12,9 @@ import java.nio.charset.Charset;
@Controller
public class HomeController {
private static YAMLMapper yamlMapper = new YAMLMapper();
@Value("classpath:/openapi.yaml")
private Resource openapi;
@Bean
public String openapiContent() throws IOException {
try(InputStream is = openapi.getInputStream()) {
return StreamUtils.copyToString(is, Charset.defaultCharset());
}
}
@GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi")
@ResponseBody
public String openapiYaml() throws IOException {
return openapiContent();
}
@GetMapping(value = "/openapi.json", produces = "application/json")
@ResponseBody
public Object openapiJson() throws IOException {
return yamlMapper.readValue(openapiContent(), Object.class);
}
@RequestMapping("/")
public String index() {
return "redirect:swagger-ui/index.html?url=../openapi.json";
return "redirect:swagger-ui.html";
}
}
}

View File

@@ -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() {
}
}