@TaskAction public void generateSpec() throws IOException, GenerateException { ClassLoader loader = projectClassLoader(); Set<Class<?>> classes = new HashSet<>(); for (String pkg : apiPackages) { Reflections reflections = new Reflections( new ConfigurationBuilder() .addClassLoaders(loader) .addUrls(ClasspathHelper.forPackage(pkg, loader)) .setExpandSuperTypes(false) .filterInputsBy(new FilterBuilder().includePackage(pkg))); Set<Class<?>> springMVCClasses = reflections.getTypesAnnotatedWith( org.springframework.web.bind.annotation.RestController.class); classes.addAll(springMVCClasses); } SpringMvcApiReader reader = new SpringMvcApiReader(new Swagger(), log); Swagger swagger = reader.read(classes); for (SwaggerFilter filter : filters) { filter.apply(swagger); } Yaml.pretty().writeValue(swaggerFile, swagger); }
beanConfig.setScan(true); Swagger swagger = new Swagger(); swagger.securityDefinition("Scouter auth token", new ApiKeyAuthDefinition("Authorization", In.HEADER)); new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
public SwaggerGenerator(SwaggerGeneratorContext context, Class<?> cls) { this.swagger = new Swagger(); this.context = context; this.cls = cls; this.classLoader = JvmUtils.findClassLoader(); this.packageName = "gen.swagger"; }
public static Swagger parse(String content) { try { return Yaml.mapper().readValue(content, Swagger.class); } catch (Exception e) { return new Swagger(); // throw new Error(e); } }
@Test public void testUriSchemeComponent() throws URISyntaxException { Swagger swagger = new Swagger().host("http://localhost").basePath("/v2"); swagger.addScheme(Scheme.HTTP); swagger.addScheme(Scheme.HTTPS); Swagger2MarkupConverter.Context context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new UriSchemeComponent(context).apply(markupDocBuilder, UriSchemeComponent.parameters(swagger, OverviewDocument.SECTION_TITLE_LEVEL)); markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8); Path expectedFile = getExpectedFile(COMPONENT_NAME); DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME)); } }
parameter.setName(propertyDescriptor.getDisplayName()); ParameterProcessor.applyAnnotations(new Swagger(), parameter, type, Lists.newArrayList(propertySetterApiParam));
angular.module('swagger', []); angular.module('swagger') .factory('swaggerApi', function () { return new Swagger({ url: 'http://localhost:8081/api-docs', usePromise: true }); });
protected Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean readHidden, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters) { if (swagger == null) { swagger = new Swagger();
public AbstractDocumentSource(Log log, ApiSource apiSource) throws MojoFailureException { LOG = log; this.outputPath = apiSource.getOutputPath(); this.templatePath = apiSource.getTemplatePath(); this.swaggerPath = apiSource.getSwaggerDirectory(); this.modelSubstitute = apiSource.getModelSubstitute(); this.jsonExampleValues = apiSource.isJsonExampleValues(); swagger = new Swagger(); if (apiSource.getSchemes() != null) { for (String scheme : apiSource.getSchemes()) { swagger.scheme(Scheme.forValue(scheme)); } } // read description from file if (apiSource.getDescriptionFile() != null) { try { InputStream is = new FileInputStream(apiSource.getDescriptionFile()); apiSource.getInfo().setDescription(IOUtils.toString(is)); is.close(); } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } } swagger.setHost(apiSource.getHost()); swagger.setInfo(apiSource.getInfo()); swagger.setBasePath(apiSource.getBasePath()); swagger.setExternalDocs(apiSource.getExternalDocs()); this.apiSource = apiSource; }
public Swagger read(SpringResource resource) { if (swagger == null) { swagger = new Swagger();
.url("http://www.apache.org/licenses/LICENSE-2.0.html")); Swagger swagger = new Swagger().info(info) .basePath("/") .tags(ImmutableList.copyOf(tags))
public Swagger getSwagger() { Swagger value = (Swagger) getConfigOrSwagger(true); if (value == null && isServletConfigAvailable(sc)) { value = (Swagger) sc.getServletContext().getAttribute("swagger"); } if (value == null) value = new Swagger(); return value; }
@Test public void shouldDetermineHostFromSpecification() { assertThat(determineHost(new Swagger().host("api.example.com").scheme(Scheme.HTTPS))).isEqualTo("https://api.example.com"); assertThat(determineHost(new Swagger().host("api.example.com").scheme(Scheme.HTTP).scheme(Scheme.HTTPS))) .isEqualTo("https://api.example.com"); assertThat(determineHost(new Swagger().host("api.example.com").scheme(Scheme.HTTP))).isEqualTo("http://api.example.com"); }
@Test public void shouldDetermineConnectorName() { final Swagger swagger = new Swagger(); assertThat(generator.determineConnectorName(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("unspecified"); final Info info = new Info(); swagger.info(info); assertThat(generator.determineConnectorName(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("unspecified"); info.title("title"); assertThat(generator.determineConnectorName(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("title"); }
@Test public void shouldDetermineConnectorDescription() { final Swagger swagger = new Swagger(); assertThat(generator.determineConnectorDescription(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("unspecified"); final Info info = new Info(); swagger.info(info); assertThat(generator.determineConnectorDescription(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("unspecified"); info.description("description"); assertThat(generator.determineConnectorDescription(SWAGGER_TEMPLATE, createSettingsFrom(swagger))).isEqualTo("description"); }
@Test public void shouldReturnNullIfNoHttpSchemesFound() { assertThat(determineHost(new Swagger().scheme(Scheme.WS).scheme(Scheme.WSS))).isNull(); } }
@Test public void shouldFailToDetermineIfNoHostGivenAnywhere() { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> determineHost(new Swagger())) .withMessageStartingWith("Swagger specification does not provide"); assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> determineHost(new Swagger().scheme(Scheme.HTTP))) .withMessageStartingWith("Swagger specification does not provide"); assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> determineHost(new Swagger().host("host"))) .withMessageStartingWith("Swagger specification does not provide"); } }
@Test public void shouldMakeNonUniqueOperationIdsUnique() { final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation().operationId("foo")) .post(new Operation().operationId("foo")).put(new Operation().operationId("bar"))); final Connector generated = generator.configureConnector(SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(), createSettingsFrom(swagger)); final List<ConnectorAction> actions = generated.getActions(); assertThat(actions).hasSize(3); assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo")); assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1")); assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar")); }
public SwaggerHelperOperationDescriptionGenerationTest(final String operationSummary, final String operationDescription, final String expectedName, final String expectedDescription) { operation = new Operation().description(operationDescription).summary(operationSummary); swagger = new Swagger().path("/test", new Path().get(operation)); expected = new OperationDescription(expectedName, expectedDescription); }