= Swagger Exporter
:page-role: -toc

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


The xref:refguide:applib:index/services/swagger/SwaggerService.adoc[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 xref:docs:starters:simpleapp.adoc[simpleapp] starter app:

[source,java]
.SwaggerExport_IntegTest.java
----
@SpringBootTest(
    classes = {
        ApplicationIntegTestAbstract.AppManifest.class,             // <1>
        IsisModuleViewerRestfulObjectsJaxrsResteasy4.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 xref:vro:ROOT:about.adoc[Restful Objects] viewer because this contains the implementation of xref:refguide:applib:index/services/swagger/SwaggerService.adoc[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.
