io.swagger.models.Info Java Examples

The following examples show how to use io.swagger.models.Info. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiDocConfig.java    From ambari-logsearch with Apache License 2.0 8 votes vote down vote up
@Bean
public BeanConfig swaggerConfig() {
  BeanConfig beanConfig = new BeanConfig();
  beanConfig.setSchemes(new String[]{"http", "https"});
  beanConfig.setBasePath(BASE_PATH);
  beanConfig.setTitle(TITLE);
  beanConfig.setDescription(DESCRIPTION);
  beanConfig.setLicense(LICENSE);
  beanConfig.setLicenseUrl(LICENSE_URL);
  beanConfig.setScan(true);
  beanConfig.setVersion(VERSION);
  beanConfig.setResourcePackage(ServiceLogsResource.class.getPackage().getName());

  License license = new License();
  license.setName(LICENSE);
  license.setUrl(LICENSE_URL);

  Info info = new Info();
  info.setDescription(DESCRIPTION);
  info.setTitle(TITLE);
  info.setVersion(VERSION);
  info.setLicense(license);
  beanConfig.setInfo(info);
  return beanConfig;
}
 
Example #2
Source File: SpringTimeSwaggerDocsController.java    From springtime with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	swagger = new Swagger();
	Info info = new Info();
	info.setTitle("GreetingService");
	swagger.setInfo(info);

	Map<String, Object> beans = applicationContext.getBeansWithAnnotation(SpringTimeService.class);
	Set<Class<?>> classes = new HashSet<Class<?>>();
	for (Object bean : beans.values()) {
		classes.add(bean.getClass());
	}

	Reader reader = new Reader(swagger, ReaderConfigUtils.getReaderConfig(null));
	swagger = reader.read(classes);
}
 
Example #3
Source File: AbstractDocumentSourceTest.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddDescriptionFile() throws URISyntaxException, MojoFailureException {

    // arrange
    URI fileUri = this.getClass().getResource("descriptionFile.txt").toURI();
    File descriptionFile = new File(fileUri);

    when(apiSource.getDescriptionFile()).thenReturn(descriptionFile);
    when(apiSource.getInfo()).thenReturn(new Info());

    // act
    AbstractDocumentSource externalDocsSource = new AbstractDocumentSource(log, apiSource, "UTF-8") {
        @Override
        protected ClassSwaggerReader resolveApiReader() throws GenerateException {
            return null;
        }

        @Override
        protected AbstractReader createReader() {
            return null;
        }
    };

    // assert
    assertThat(externalDocsSource.swagger.getInfo().getDescription(), is("Description file content\n"));
}
 
Example #4
Source File: ApiSourceTest.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetInfo0VendorExtensions() {
    Map<String, Object> logo = new HashMap<String, Object>();
    logo.put("logo", "logo url");
    logo.put("description", "This is our logo.");

    Map<String, Object> website = new HashMap<String, Object>();
    website.put("website", "website url");
    website.put("description", "This is our website.");

    Map<String, Object> expectedExtensions = new HashMap<String, Object>();
    expectedExtensions.put("x-logo", logo);
    expectedExtensions.put("x-website", website);


    Set<Class<?>> validClasses = Sets.newHashSet(ApiSourceTestClass.class);
    ApiSource apiSource = spy(ApiSource.class);

    when(apiSource.getValidClasses(SwaggerDefinition.class)).thenReturn(validClasses);
    Info info = apiSource.getInfo();

    Map<String, Object> vendorExtensions = info.getVendorExtensions();
    Assert.assertEquals(vendorExtensions.size(), 2);
    Assert.assertEquals(vendorExtensions, expectedExtensions);
}
 
Example #5
Source File: Java2SwaggerMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void configureSwagger() {
    swagger = new Swagger();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    Info info = new Info();
    Contact swaggerContact = new Contact();
    License swaggerLicense = new License();
    swaggerLicense.name(this.license)
        .url(this.licenseUrl);
    swaggerContact.name(this.contact);
    info.version(this.version)
        .description(this.description)
        .contact(swaggerContact)
        .license(swaggerLicense)
        .title(this.title);
    swagger.setInfo(info);
    if (this.schemes != null) {
        for (String scheme : this.schemes) {
            swagger.scheme(Scheme.forValue(scheme));
        }
    }
    swagger.setHost(this.host);
    swagger.setBasePath(this.basePath);
}
 
Example #6
Source File: SwaggerServiceTest.java    From ob1k with Apache License 2.0 6 votes vote down vote up
private String createData() throws Exception {
  final Swagger expected = new Swagger();

  expected.host(HOST);
  when(request.getHeader("Host")).thenReturn(HOST);

  expected.info(new Info().title(CONTEXT_PATH.substring(1)).description("API Documentation").version("1.0"));

  createData(DummyService.class, "/api", expected, endpointsByPathMap, GET);
  createData(DummyService.class, "/api", expected, endpointsByPathMap, POST);
  createData(AnnotatedDummyService.class, "/apiAnnotated", expected, endpointsByPathMap,
          "an annotated test service", ANY, "millis", "millis since epoch");

  final ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  return mapper.writeValueAsString(expected);
}
 
Example #7
Source File: LicenseInfoComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testLicenseInfoComponent() throws URISyntaxException {

    Info info = new Info()
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))
            .termsOfService("Bla bla bla");

    Swagger2MarkupConverter.SwaggerContext context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new LicenseInfoComponent(context).apply(markupDocBuilder, LicenseInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}
 
Example #8
Source File: LicenseInfoComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Info info = params.info;
    License license = info.getLicense();
    String termOfService = info.getTermsOfService();
    if ((license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) || isNotBlank(termOfService)) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(LICENSE_INFORMATION));
        MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);
        if (license != null) {
            if (isNotBlank(license.getName())) {
                paragraph.italicText(labels.getLabel(LICENSE)).textLine(COLON + license.getName());
            }
            if (isNotBlank(license.getUrl())) {
                paragraph.italicText(labels.getLabel(LICENSE_URL)).textLine(COLON + license.getUrl());
            }
        }

        paragraph.italicText(labels.getLabel(TERMS_OF_SERVICE)).textLine(COLON + termOfService);

        markupDocBuilder.paragraph(paragraph.toString(), true);
    }

    return markupDocBuilder;
}
 
Example #9
Source File: SwaggerGenerator.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
private Swagger writeSwagger(Iterable<ApiConfig> configs, SwaggerContext context,
    GenerationContext genCtx)
    throws ApiConfigException {
  ImmutableListMultimap<ApiKey, ? extends ApiConfig> configsByKey = FluentIterable.from(configs)
      .index(CONFIG_TO_ROOTLESS_KEY);
  Swagger swagger = new Swagger()
      .produces("application/json")
      .consumes("application/json")
      .scheme(context.scheme)
      .host(context.hostname)
      .basePath(context.basePath)
      .info(new Info()
          .title(context.hostname)
          .version(context.docVersion));
  for (ApiKey apiKey : configsByKey.keySet()) {
    writeApi(apiKey, configsByKey.get(apiKey), swagger, genCtx);
  }
  writeQuotaDefinitions(swagger, genCtx);
  return swagger;
}
 
Example #10
Source File: TopLevelBuilder.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
/**
 * Adds additional information to {@link Service} object.
 *
 * @throws OpenApiConversionException
 */
private void createServiceInfoFromOpenApi(
    Service.Builder serviceBuilder, List<OpenApiFile> openApiFiles)
    throws OpenApiConversionException {
  for (OpenApiFile openApiFile : openApiFiles) {
    //TODO(user): need better way to resolve conflicts here
    if (openApiFile.swagger().getInfo() != null) {
      Info info = openApiFile.swagger().getInfo();
      if (info.getTitle() != null) {
        serviceBuilder.setTitle(info.getTitle());
      }
      if (info.getDescription() != null) {
        serviceBuilder.getDocumentationBuilder().setSummary(info.getDescription());
      }
    }
  }
}
 
Example #11
Source File: IoCSwaggerGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Preconfigure generator. By default it will genrate api for Data and RCP with JSon payloads only.
 * The api will be in YAML format. You might change default setting with config methods of the class
 * @param ctx context for generation
 * @param modulesToGenerate modules that will be transformed to swagger API
 */
@Inject
public IoCSwaggerGenerator(@Assisted SchemaContext ctx, @Assisted Set<Module> modulesToGenerate) {
    Objects.requireNonNull(ctx);
    Objects.requireNonNull(modulesToGenerate);
    if(modulesToGenerate.isEmpty()) throw new IllegalStateException("No modules to generate has been specified");
    this.ctx = ctx;
    this.modules = modulesToGenerate;
    target = new Swagger();
    converter = new AnnotatingTypeConverter(ctx);
    moduleUtils = new ModuleUtils(ctx);
    this.moduleNames = modulesToGenerate.stream().map(ModuleIdentifier::getName).collect(Collectors.toSet());
    //assign default strategy
    strategy(Strategy.optimizing);

    //no exposed swagger API
    target.info(new Info());

    //default postprocessors
    postprocessor = new ReplaceEmptyWithParent();
}
 
Example #12
Source File: AbstractSwaggerGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected void setJavaInterface(Info info) {
    if (!swaggerGeneratorFeature.isExtJavaInterfaceInVendor()) {
      return;
    }

    if (cls.isInterface()) {// && !isInterfaceReactive(cls)) {
      info.setVendorExtension(SwaggerConst.EXT_JAVA_INTF, cls.getName());
      return;
    }

//    if (cls.getInterfaces().length > 0) {
//      info.setVendorExtension(SwaggerConst.EXT_JAVA_INTF, cls.getInterfaces()[0].getName());
//      return;
//    }

    if (StringUtils.isEmpty(swaggerGeneratorFeature.getPackageName())) {
      return;
    }

    String intfName = swaggerGeneratorFeature.getPackageName() + "." + cls.getSimpleName() + "Intf";
    info.setVendorExtension(SwaggerConst.EXT_JAVA_INTF, intfName);
  }
 
Example #13
Source File: SwaggerAutoConfiguration.java    From dorado with Apache License 2.0 6 votes vote down vote up
@Bean(name = "swaggerApiContext")
public ApiContext buildApiContext() {
	Info info = new Info();
	info.title(swaggerConfig.getTitle()).description(swaggerConfig.getDescription())
			.termsOfService(swaggerConfig.getTermsOfServiceUrl()).version(swaggerConfig.getVersion());
	Contact contact = swaggerConfig.getContact();

	if (contact != null)
		info.setContact(new io.swagger.models.Contact().email(contact.getEmail()).name(contact.getName())
				.url(contact.getUrl()));

	info.setLicense(new License().name(swaggerConfig.getLicense()).url(swaggerConfig.getLicenseUrl()));

	ApiContext.Builder apiContextBuilder = ApiContext.builder().withInfo(info);

	ai.houyi.dorado.swagger.springboot.SwaggerProperties.ApiKey apiKey = swaggerConfig.getApiKey();
	if (apiKey != null) {
		ApiKey _apiKey = ApiKey.builder().withIn(swaggerConfig.getApiKey().getIn())
				.withName(swaggerConfig.getApiKey().getName()).build();
		apiContextBuilder.withApiKey(_apiKey);
	}

	return apiContextBuilder.build();
}
 
Example #14
Source File: ApiContextBuilderImpl.java    From dorado with Apache License 2.0 6 votes vote down vote up
@Override
// 这里定制Api全局信息,如文档描述、license,contact等信息
public ApiContext buildApiContext() {
	Info info = new Info()
			.contact(new Contact().email("[email protected]").name("weiping wang")
					.url("http://github.com/javagossip/dorado"))
			.license(new License().name("apache v2.0").url("http://www.apache.org"))
			.termsOfService("http://swagger.io/terms/").description("Dorado服务框架api接口文档")
			.title("dorado demo api接口文档").version("1.0.0");

	//构造api访问授权的apiKey
	ApiKey apiKey = ApiKey.builder().withName("Authorization").withIn("header").build();
	ApiContext apiContext = ApiContext.builder().withApiKey(apiKey)
			.withInfo(info).build();

	return apiContext;
}
 
Example #15
Source File: ApexClientCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    Info info = swagger.getInfo();
    String calloutLabel = info.getTitle();
    additionalProperties.put("calloutLabel", calloutLabel);
    String sanitized = sanitizeName(calloutLabel);
    additionalProperties.put("calloutName", sanitized);
    supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials",
        sanitized + ".namedCredential"
    ));

    if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) {
        generateSfdxSupportingFiles();
    } else if (additionalProperties.get(BUILD_METHOD).equals("ant")) {
        generateAntSupportingFiles();
    }

}
 
Example #16
Source File: SwaggerHandlerImplTest.java    From spring-cloud-huawei with Apache License 2.0 6 votes vote down vote up
private void init() {
  mockMap.put("xxxx", apiListing);
  mockDoc = new Documentation("xx", "/xx", null, mockMap,
      null, Collections.emptySet(), Collections.emptySet(), null, Collections.emptySet(), Collections.emptyList());
  mockSwagger = new Swagger();
  mockSwagger.setInfo(new Info());
  Map<String, Model> defMap = new HashMap<>();
  defMap.put("xx", new ModelImpl());
  mockSwagger.setDefinitions(defMap);
  Map<String, Path> pathMap = new HashMap<>();
  pathMap.put("xx", new Path());
  mockSwagger.setPaths(pathMap);
  new Expectations() {
    {
      documentationCache.documentationByGroup(anyString);
      result = mockDoc;

      DefinitionCache.getClassNameBySchema(anyString);
      result = "app";

      mapper.mapDocumentation((Documentation) any);
      result = mockSwagger;
    }
  };
}
 
Example #17
Source File: OpenAPIV2Generator.java    From spring-openapi with MIT License 6 votes vote down vote up
public OpenAPIV2Generator(List<String> modelPackages, List<String> controllerBasePackages, Info info,
						  List<SchemaInterceptor> schemaInterceptors,
						  List<SchemaFieldInterceptor> schemaFieldInterceptors,
						  List<OperationParameterInterceptor> operationParameterInterceptors,
						  List<OperationInterceptor> operationInterceptors,
						  List<RequestBodyInterceptor> requestBodyInterceptors) {
	this.modelPackages = modelPackages;
	this.controllerBasePackages = controllerBasePackages;
	componentSchemaTransformer = new ComponentSchemaTransformer(schemaFieldInterceptors);
	globalHeaders = new ArrayList<>();

	GenerationContext operationsGenerationContext = new GenerationContext(null, removeRegexFormatFromPackages(modelPackages));
	operationsTransformer = new OperationsTransformer(
			operationsGenerationContext, operationParameterInterceptors, operationInterceptors, requestBodyInterceptors, globalHeaders
	);

	this.info = info;
	this.schemaInterceptors = schemaInterceptors;
	this.schemaFieldInterceptors = schemaFieldInterceptors;
	this.operationParameterInterceptors = operationParameterInterceptors;
	this.operationInterceptors = operationInterceptors;
	this.requestBodyInterceptors = requestBodyInterceptors;
}
 
Example #18
Source File: StaticHtml2Generator.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (StringUtils.isBlank(jsProjectName) && info.getTitle() != null) {
            // when jsProjectName is not specified, generate it from info.title
            jsProjectName = sanitizeName(dashize(info.getTitle()));
        }
    }

    // default values
    if (StringUtils.isBlank(jsProjectName)) {
        jsProjectName = "swagger-js-client";
    }
    if (StringUtils.isBlank(jsModuleName)) {
        jsModuleName = camelize(underscore(jsProjectName));
    }

    additionalProperties.put("jsProjectName", jsProjectName);
    additionalProperties.put("jsModuleName", jsModuleName);

    preparHtmlForGlobalDescription(swagger);
}
 
Example #19
Source File: DocumentationDrivenValidator.java    From assertj-swagger with Apache License 2.0 5 votes vote down vote up
private void validateInfo(Info actualInfo, Info expectedInfo) {

        // Version.  OFF by default.
        if (isAssertionEnabled(SwaggerAssertionType.VERSION)) {
            softAssertions.assertThat(actualInfo.getVersion()).as("Checking Version").isEqualTo(expectedInfo.getVersion());
        }

        // Everything (but potentially brittle, therefore OFF by default)
        if (isAssertionEnabled(SwaggerAssertionType.INFO)) {
            softAssertions.assertThat(actualInfo).as("Checking Info").isEqualToComparingFieldByField(expectedInfo);
        }
    }
 
Example #20
Source File: ConsumerDrivenValidator.java    From assertj-swagger with Apache License 2.0 5 votes vote down vote up
private void validateInfo(Info actualInfo, Info expectedInfo) {

        // Version.  OFF by default.
        if (isAssertionEnabled(SwaggerAssertionType.VERSION)) {
            softAssertions.assertThat(actualInfo.getVersion()).as("Checking Version").isEqualTo(expectedInfo.getVersion());
        }

        // Everything (but potentially brittle, therefore OFF by default)
        if (isAssertionEnabled(SwaggerAssertionType.INFO)) {
            softAssertions.assertThat(actualInfo).as("Checking Info").isEqualToComparingFieldByField(expectedInfo);
        }
    }
 
Example #21
Source File: MSF4JBeanConfig.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private void updateInfoFromConfig() {
    if (getSwagger().getInfo() == null) {
        setInfo(new Info());
    }

    if (StringUtils.isNotBlank(getDescription())) {
        getSwagger().getInfo().setDescription(getDescription());
    }

    if (StringUtils.isNotBlank(getTitle())) {
        getSwagger().getInfo().setTitle(getTitle());
    }

    if (StringUtils.isNotBlank(getVersion())) {
        getSwagger().getInfo().setVersion(getVersion());
    }

    if (StringUtils.isNotBlank(getTermsOfServiceUrl())) {
        getSwagger().getInfo().setTermsOfService(getTermsOfServiceUrl());
    }

    if (getContact() != null) {
        getSwagger().getInfo().setContact((new Contact()).name(getContact()));
    }

    if (getLicense() != null && getLicenseUrl() != null) {
        getSwagger().getInfo().setLicense((new License()).name(getLicense()).url(getLicenseUrl()));
    }

    if (getSchemes() != null) {
        for (String scheme : getSchemes()) {
            reader.getSwagger().scheme(Scheme.forValue(scheme));
        }
    }

    reader.getSwagger().setInfo(getInfo());
}
 
Example #22
Source File: OpenAPIV2GeneratorTest.java    From spring-openapi with MIT License 5 votes vote down vote up
private Info createTestInfo() {
	Info info = new Info();
	info.setTitle("Test API");
	info.setDescription("Test description");
	info.setVersion("1.0.0");
	return info;
}
 
Example #23
Source File: RestServer.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
private void enableAutoGenerationOfSwaggerSpecification() {
    // The main scanner class used to scan the classes for swagger + jax-rs annoatations
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage("com.clicktravel.services,com.clicktravel.services.*");
    beanConfig.setSchemes(new String[] { "https" });
    beanConfig.setBasePath("/");
    final Info info = new Info();
    info.setVersion("2.0.0");
    beanConfig.setInfo(info);
    beanConfig.setTitle("Swagger Specification");
    beanConfig.setVersion("0.0.0");
    beanConfig.setScan(true);
}
 
Example #24
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method generates API definition to the given api
 *
 * @param swaggerData api
 * @return API definition in string format
 * @throws APIManagementException
 */
@Override
public String generateAPIDefinition(SwaggerData swaggerData) throws APIManagementException {
    Swagger swagger = new Swagger();

    //Create info object
    Info info = new Info();
    info.setTitle(swaggerData.getTitle());
    if (swaggerData.getDescription() != null) {
        info.setDescription(swaggerData.getDescription());
    }

    Contact contact = new Contact();
    //Create contact object and map business owner info
    if (swaggerData.getContactName() != null) {
        contact.setName(swaggerData.getContactName());
    }
    if (swaggerData.getContactEmail() != null) {
        contact.setEmail(swaggerData.getContactEmail());
    }
    if (swaggerData.getContactName() != null || swaggerData.getContactEmail() != null) {
        //put contact object to info object
        info.setContact(contact);
    }

    info.setVersion(swaggerData.getVersion());
    swagger.setInfo(info);
    updateSwaggerSecurityDefinition(swagger, swaggerData, "https://test.com");
    updateLegacyScopesFromSwagger(swagger, swaggerData);
    for (SwaggerData.Resource resource : swaggerData.getResources()) {
        addOrUpdatePathToSwagger(swagger, resource);
    }

    return getSwaggerJsonString(swagger);
}
 
Example #25
Source File: UpdateManager.java    From cellery-distribution with Apache License 2.0 5 votes vote down vote up
/**
 * Creates Swagger Info
 *
 * @param api API sent by controller
 * @return Swagger Info
 */
private static Info createSwaggerInfo(API api) {
    Info info = new Info();
    info.setVersion(cellConfig.getVersion());
    info.setTitle(generateAPIName(api));
    return info;
}
 
Example #26
Source File: ServiceCombDocumentationSwaggerMapper.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private void changeSwaggerInfo(String originalSchemaId, Swagger swagger) {
  String fullClassName = DefinitionCache.getFullClassNameBySchema(originalSchemaId);
  String xInterfaceName = genXInterfaceName(appName, serviceName, mapSchemaId(originalSchemaId));

  Info info = swagger.getInfo();
  info.setTitle(TITLE_PREFIX + fullClassName);
  info.setVendorExtension(X_JAVA_INTERFACE, xInterfaceName);
}
 
Example #27
Source File: StaticHtmlGenerator.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
public void preprocessSwagger(Swagger swagger) {
    Info info = swagger.getInfo();
    info.setDescription(toHtml(info.getDescription()));
    info.setTitle(toHtml(info.getTitle()));
    Map<String, Model> models = swagger.getDefinitions();
    for (Model model : models.values()) {
        model.setDescription(toHtml(model.getDescription()));
        model.setTitle(toHtml(model.getTitle()));
    }
}
 
Example #28
Source File: DefinitionParserServiceTest.java    From swaggerhub-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTestClass(){
    definitionParserService = new DefinitionParserService();

    this.swagger = new Swagger();
    Info info = new Info();
    swagger.setInfo(info);

    objectMapper = new ObjectMapper();
}
 
Example #29
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static Class<?> getInterface(Swagger swagger) {
  Info info = swagger.getInfo();
  if (info == null) {
    return null;
  }

  String name = getInterfaceName(info.getVendorExtensions());
  if (StringUtils.isEmpty(name)) {
    return null;
  }

  return ReflectUtils.getClassByName(name);
}
 
Example #30
Source File: SwaggerGenerator.java    From yang2swagger with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Preconfigure generator. By default it will genrate api for Data and RCP with JSon payloads only.
 * The api will be in YAML format. You might change default setting with config methods of the class
 * @param ctx context for generation
 * @param modulesToGenerate modules that will be transformed to swagger API
 */
public SwaggerGenerator(SchemaContext ctx, Set<org.opendaylight.yangtools.yang.model.api.Module> modulesToGenerate) {
    Objects.requireNonNull(ctx);
    Objects.requireNonNull(modulesToGenerate);

    if(ctx.getModules().isEmpty()) {
        log.error("No modules found in the context.");
        throw new IllegalStateException("No modules found in the context.");
    }
    if(modulesToGenerate.isEmpty()) {
        log.error("No modules has been specified for swagger generation");
        if(log.isInfoEnabled()) {
            String msg = ctx.getModules().stream().map(ModuleIdentifier::getName).collect(Collectors.joining(", "));
            log.info("Modules in the context are: {}", msg);
        }
        throw new IllegalStateException("No modules to generate has been specified");
    }
    this.ctx = ctx;
    this.modules = modulesToGenerate;
    target = new Swagger();
    converter = new AnnotatingTypeConverter(ctx);
    moduleUtils = new ModuleUtils(ctx);
    this.moduleNames = modulesToGenerate.stream().map(ModuleIdentifier::getName).collect(Collectors.toSet());
    //assign default strategy
    strategy(Strategy.optimizing);

    //no exposed swagger API
    target.info(new Info());

    pathHandlerBuilder = new com.mrv.yangtools.codegen.impl.path.rfc8040.PathHandlerBuilder();
    //default postprocessors
    postprocessor = new ReplaceEmptyWithParent();
}