Swagger Exporter
The SwaggerService serializes the domain’s meta model as a Swagger 2.0 specification, either as JSON or YAML.
The SwaggerExporter
in turn is a utility class that simply writes this serialization out to a file from within an integration test.
The idea is that subsequent jobs in the build process could then pick up this file, typically to code-generation REST clients in other languages.
The example below is taken from the simpleapp starter app:
SwaggerExport_IntegTest.java
@SpringBootTest(
classes = {
ApplicationIntegTestAbstract.AppManifest.class, (1)
CausewayModuleViewerRestfulObjectsJaxrsResteasy4.class (2)
}
)
class SwaggerExport_IntegTest extends ApplicationIntegTestAbstract {
@Inject ServiceRegistry serviceRegistry;
@Test
void export() throws IOException {
val swaggerExporter = new SwaggerExporter(serviceRegistry); (3)
swaggerExporter.export(
SwaggerService.Visibility.PRIVATE, (4)
SwaggerService.Format.JSON); (4)
}
}
1 | bootstrap using the usual AppManifest for integration tests … |
2 | ... and also include the Restful Objects viewer because this contains the implementation of SwaggerService. |
3 | instantiate the SwaggerExporter utility class |
4 | Export specifies the required visibility and format. |
By default the file will be written to target/generated-resources/swagger-export
.
Overloads of the export(…)
method allow this to be changed as required.