-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bug/1167-jakarta-java8
- Loading branch information
Showing
9 changed files
with
288 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/LocalDateConverter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package {{configPackage}}; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class LocalDateConverter implements Converter<String, LocalDate> { | ||
private final DateTimeFormatter formatter; | ||
public LocalDateConverter(String dateFormat) { | ||
this.formatter = DateTimeFormatter.ofPattern(dateFormat); | ||
} | ||
|
||
@Override | ||
public LocalDate convert(String source) { | ||
if(source == null || source.isEmpty()) { | ||
return null; | ||
} | ||
return LocalDate.parse(source, this.formatter); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...in/resources/handlebars/JavaSpring/libraries/spring-boot3/LocalDateTimeConverter.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package {{configPackage}}; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class LocalDateTimeConverter implements Converter<String, LocalDateTime> { | ||
private final DateTimeFormatter formatter; | ||
public LocalDateTimeConverter(String dateFormat) { | ||
this.formatter = DateTimeFormatter.ofPattern(dateFormat); | ||
} | ||
|
||
@Override | ||
public LocalDateTime convert(String source) { | ||
if(source == null || source.isEmpty()) { | ||
return null; | ||
} | ||
return LocalDateTime.parse(source, this.formatter); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{{^interfaceOnly}}# Swagger generated server | ||
|
||
Spring Boot Server | ||
|
||
|
||
## Overview | ||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. | ||
By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub. | ||
This is an example of building a swagger-enabled server in Java using the SpringBoot framework. | ||
|
||
The underlying library integrating swagger to SpringBoot is [springdoc-openapi](https://github.com/springdoc/springdoc-openapi) | ||
|
||
Start your server as an simple java application | ||
|
||
You can view the api documentation in swagger-ui by pointing to | ||
http://localhost:8080/ | ||
|
||
Change default port value in application.properties{{/interfaceOnly}}{{#interfaceOnly}} | ||
# Swagger generated API stub | ||
|
||
Spring Framework stub | ||
|
||
|
||
## Overview | ||
This code was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. | ||
By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate an API stub. | ||
This is an example of building API stub interfaces in Java using the Spring framework. | ||
|
||
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints | ||
by adding ```@Controller``` classes that implement the interface. Eg: | ||
```java | ||
@Controller | ||
public class PetController implements PetApi { | ||
// implement all PetApi methods | ||
} | ||
``` | ||
{{/interfaceOnly}} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/application.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
springfox.documentation.open-api.v3.path=/api-docs | ||
server.servlet.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}} | ||
server.port={{serverPort}} |
16 changes: 16 additions & 0 deletions
16
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/homeController.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package {{configPackage}}; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
/** | ||
* Home redirection to swagger api documentation | ||
*/ | ||
@Controller | ||
public class HomeController { | ||
@RequestMapping(value = "/") | ||
public String index() { | ||
System.out.println("/swagger-ui/index.html"); | ||
return "redirect:/swagger-ui/"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/openAPISpringBoot.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package {{basePackage}}; | ||
|
||
import {{configPackage}}.LocalDateConverter; | ||
import {{configPackage}}.LocalDateTimeConverter; | ||
|
||
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.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.format.FormatterRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; | ||
|
||
@SpringBootApplication | ||
@ComponentScan(basePackages = { "{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"}) | ||
public class OpenAPISpringBoot 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(OpenAPISpringBoot.class).run(args); | ||
} | ||
|
||
@Configuration | ||
static class CustomDateConfig extends WebMvcConfigurationSupport { | ||
@Override | ||
public void addFormatters(FormatterRegistry registry) { | ||
registry.addConverter(new LocalDateConverter("{{#datePattern}}{{datePattern}}{{/datePattern}}{{^datePattern}}yyyy-MM-dd{{/datePattern}}")); | ||
registry.addConverter(new LocalDateTimeConverter("{{#dateTimePattern}}{{dateTimePattern}}{{/dateTimePattern}}{{^dateTimePattern}}yyyy-MM-dd'T'HH:mm:ss.SSS{{/dateTimePattern}}")); | ||
} | ||
} | ||
|
||
class ExitException extends RuntimeException implements ExitCodeGenerator { | ||
private static final long serialVersionUID = 1L; | ||
@Override | ||
public int getExitCode() { | ||
return 10; | ||
} | ||
|
||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/resources/handlebars/JavaSpring/libraries/spring-boot3/pom.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>{{groupId}}</groupId> | ||
<artifactId>{{artifactId}}</artifactId> | ||
<packaging>jar</packaging> | ||
<name>{{artifactId}}</name> | ||
<version>{{artifactVersion}}</version> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
<springboot-version>3.1.1</springboot-version> | ||
<swagger-annotations-version>2.2.14</swagger-annotations-version> | ||
</properties> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.1.1</version> | ||
</parent> | ||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${springboot-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
<version>${springboot-version}</version> | ||
</dependency> | ||
{{#withXml}} | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-xml</artifactId> | ||
</dependency> | ||
{{/withXml}} | ||
{{#useBeanValidation}} | ||
<!-- Bean Validation API support --> | ||
<dependency> | ||
<groupId>jakarta.validation</groupId> | ||
<artifactId>jakarta.validation-api</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.xml.bind</groupId> | ||
<artifactId>jakarta.xml.bind-api</artifactId> | ||
<version>4.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-impl</artifactId> | ||
<version>4.0.3</version> | ||
</dependency> | ||
{{/useBeanValidation}} | ||
{{#notNullJacksonAnnotation}} | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.10.1</version> | ||
</dependency> | ||
{{/notNullJacksonAnnotation}} | ||
|
||
<dependency> | ||
<groupId>io.swagger.core.v3</groupId> | ||
<artifactId>swagger-annotations</artifactId> | ||
<version>${swagger-annotations-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.plugin</groupId> | ||
<artifactId>spring-plugin-core</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${springboot-version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
...in/resources/handlebars/JavaSpring/libraries/spring-boot3/swaggerUiConfiguration.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package {{configPackage}}; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
{{>generatedAnnotation}} | ||
@Configuration | ||
public class SwaggerUiConfiguration implements WebMvcConfigurer { | ||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry. | ||
addResourceHandler("/swagger-ui/**") | ||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") | ||
.resourceChain(false); | ||
} | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.addViewController("/swagger-ui/").setViewName("forward:/swagger-ui/index.html"); | ||
} | ||
} |