Smithy2OpenApi implements SmithyBuildPlugin { @Override public void execute(PluginContext context) { OpenApiConverter converter = OpenApiConverter.create(); context.getPluginClassLoader().ifPresent(converter::classLoader); OpenApiConfig config = OpenApiConfig.fromNode(context.getSettings()); ShapeId shapeId = config.getService(); converter.config(config); ObjectNode openApiNode = converter.convertToNode(context.getModel()); context.getFileManifest().writeJson(shapeId.getName() + ".openapi.json", openApiNode); }  @Override String getName(); @Override void execute(PluginContext context);  }
@Test public void pluginConvertsModel() { Model model = Model.assembler() .addImport(OpenApiConverterTest.class.getResource("test-service.json")) .discoverModels() .assemble() .unwrap(); MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() .settings(Node.objectNode() .withMember("service", "example.rest#RestService") ) .fileManifest(manifest) .model(model) .originalModel(model) .build(); new Smithy2OpenApi().execute(context); assertTrue(manifest.hasFile("RestService.openapi.json")); }
@Test public void throwsWhenServiceNotConfigured() { Model model = Model.assembler() .addImport(OpenApiConverterTest.class.getResource("test-service.json")) .discoverModels() .assemble() .unwrap(); MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() .settings(Node.objectNode()) .fileManifest(manifest) .model(model) .originalModel(model) .build(); assertThrows(OpenApiException.class, () -> { new Smithy2OpenApi().execute(context); }); }