SwaggerGenerator implements RestDocumentationGenerator { @Override public void generateDocumentation(Writer writer, String serverPrefix, Locale locale) { LOGGER.info("Generating REST documentation"); SwaggerModel swaggerModel = initialSwaggerModel(serverPrefix, locale); swaggerModel.addDefinition("Metadata", buildMetadataDefinition()); for (Entity entity : allEntities.retrieveAll()) { addCrudEndpoints(swaggerModel, entity, locale); addLookupEndpoints(swaggerModel, entity, locale); addDefinitions(swaggerModel, entity); } if (swaggerModel.getDefinitions().size() == 1) { swaggerModel.getInfo().setDescription(String.format("%s \n\n**%s [%s](%s)**", msg(locale, API_DESCRIPTION_KEY), msg(locale, NO_ENTITY_IS_EXPOSED_KEY), msg(locale, REST_API_DOCS_KEY), property(REST_API_DOCS_URL_KEY))); } Gson gson = buildGson(); gson.toJson(swaggerModel, writer); }  @Override void generateDocumentation(Writer writer, String serverPrefix, Locale locale); @Autowired @Qualifier("swaggerProperties") void setSwaggerProperties(Properties swaggerProperties); @Autowired void setAllEntities(AllEntities allEntities); @Resource(name="swaggerMessageSource") void setSwaggerMessageSource(MessageSource messageSource);  }
@Test public void shouldGenerateJson() { StringWriter stringWriter = new StringWriter(); swaggerGenerator.generateDocumentation(stringWriter, "/motech-platform-server", LOCALE); Gson gson = new GsonBuilder() .registerTypeAdapter(Response.class, new ResponseAdapter()) .registerTypeAdapter(ParameterType.class, new ParameterTypeAdapter()) .create(); SwaggerModel swaggerModel = gson.fromJson(stringWriter.toString(), SwaggerModel.class); verifyCommonModel(swaggerModel); verifyDefinitions(swaggerModel); verifyPaths(swaggerModel); }