Skip to content

Instantly share code, notes, and snippets.

@BenjaminKlatt
BenjaminKlatt / springdoc-tomcat-pom.xml
Created February 14, 2021 10:02
SpringDoc OpenAPI download tomcat port configuration for integration test phase
<!-- Identify a free port for the spring boot integration test phase -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<goals><goal>reserve-network-port</goal></goals>
<phase>process-resources</phase>
@BenjaminKlatt
BenjaminKlatt / springdoc-download-pom.xml
Created February 14, 2021 10:00
SpringDoc OpenAPI spec download maven configuration
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
@BenjaminKlatt
BenjaminKlatt / application.properties
Created February 14, 2021 09:52
SpringDoc pretty printer configuration
springdoc.writer-with-default-pretty-printer=true
@BenjaminKlatt
BenjaminKlatt / OpenAPIConfiguration.java
Created February 14, 2021 09:50
SpringDoc OpenAPI base information configuration
@OpenAPIDefinition(
info = @Info(
title = "API Roundtrip Demo (viadee.de)",
description = "An API showcase demonstrating how to automatically generate an openapi spec and client based on this.",
version = "0.1.0",
contact = @Contact(
name = "Cloud @viadee",
url = "https://www.viadee.de",
email = "[email protected]"),
@BenjaminKlatt
BenjaminKlatt / springdoc-pom.xml
Created February 14, 2021 09:39
SpringDoc Dependency definition in maven pom.xml
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.4</version>
</dependency>
@BenjaminKlatt
BenjaminKlatt / UserApiController.java
Created February 14, 2021 09:35
Spring RestController implementation for UserAPI Example
@RestController
public class UserApiController implements UserApi {
private Map<String, User> users = new HashMap<>();
@Override
public List<User> findAll() {
return new ArrayList<>(users.values());
}
...
@BenjaminKlatt
BenjaminKlatt / UserApi.java
Last active February 14, 2021 09:31
Example User API for API Roundtrip
@RequestMapping("/api/users")
@Tag(name = "User API", description = "User Management API")
interface UserApi {
@GetMapping
@ResponseStatus(code = HttpStatus.OK)
List<User> findAll();
@GetMapping("/{id}")
@ResponseStatus(code = HttpStatus.OK)
@BenjaminKlatt
BenjaminKlatt / FreezingRulesTest.java
Last active October 12, 2020 21:30
ArchUnit Freeze Feature
@ArchTest
private static ArchRule controllers_should_be_suffixed =
freeze(
classes()
.that().areAnnotatedWith(RestController.class)
.should().haveSimpleNameEndingWith("Controller")
.andShould().resideInAPackage("..controller..")
.because("controllers must use business services instead of the persistence layer")
);
@BenjaminKlatt
BenjaminKlatt / TestWithAnnotations.java
Created October 12, 2020 21:06
ArchUnit Import Options
@AnalyzeClasses(
packages = " de.viadee.architecture.archunit",
importOptions = {
ImportOption.DoNotIncludeTests.class,
ImportOption.DoNotIncludeJars.class,
ImportOption.DoNotIncludeArchives.class })
public class MyTest {
...
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Note: deactivate debug logs for ArchUnit to prevent OutOfMemory errors on windows terminals. -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="com.tngtech.archunit" level="WARN"/>
</configuration>