Java Code Examples for io.swagger.models.Swagger#addScheme()

The following examples show how to use io.swagger.models.Swagger#addScheme() . 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: UriSchemeComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testUriSchemeComponent() throws URISyntaxException {

    Swagger swagger = new Swagger().host("http://localhost").basePath("/v2");
    swagger.addScheme(Scheme.HTTP);
    swagger.addScheme(Scheme.HTTPS);

    Swagger2MarkupConverter.SwaggerContext 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));

}
 
Example 2
Source File: SwaggerUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method will create the info section of the swagger document.
 *
 * @param dataServiceName name of the data-service.
 * @param transports      enabled transports.
 * @param serverConfig    Server config object.
 * @param swaggerDoc      Swagger document object.
 * @throws AxisFault Exception occured while getting the host address from transports.
 */
private static void addSwaggerInfoSection(String dataServiceName, List<String> transports,
                                          MIServerConfig serverConfig, Swagger swaggerDoc) throws AxisFault {

    swaggerDoc.basePath("/" + SwaggerProcessorConstants.SERVICES_PREFIX + "/" + dataServiceName);

    if (transports.contains("https")) {
        swaggerDoc.addScheme(Scheme.HTTPS);
        swaggerDoc.addScheme(Scheme.HTTP);
        swaggerDoc.setHost(serverConfig.getHost("https"));
    } else {
        swaggerDoc.addScheme(Scheme.HTTP);
        swaggerDoc.setHost(serverConfig.getHost("http"));
    }

    Info info = new Info();
    info.title(dataServiceName);
    info.setVersion("1.0");
    info.description("API Definition of dataservice : " + dataServiceName);
    swaggerDoc.setInfo(info);

    swaggerDoc.addConsumes("application/json");
    swaggerDoc.addConsumes("application/xml");

    swaggerDoc.addProduces("application/json");
    swaggerDoc.addProduces("application/xml");
}
 
Example 3
Source File: JbootSwaggerManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void init() {
    if (!config.isConfigOk()) {
        return;
    }

    swagger = new Swagger();
    swagger.setHost(config.getHost());
    swagger.setBasePath("/");
    swagger.addScheme(HTTP);
    swagger.addScheme(HTTPS);


    Info swaggerInfo = new Info();
    swaggerInfo.setDescription(config.getDescription());
    swaggerInfo.setVersion(config.getVersion());
    swaggerInfo.setTitle(config.getTitle());
    swaggerInfo.setTermsOfService(config.getTermsOfService());

    Contact contact = new Contact();
    contact.setName(config.getContactName());
    contact.setEmail(config.getContactEmail());
    contact.setUrl(config.getContactUrl());
    swaggerInfo.setContact(contact);

    License license = new License();
    license.setName(config.getLicenseName());
    license.setUrl(config.getLicenseUrl());
    swaggerInfo.setLicense(license);


    swagger.setInfo(swaggerInfo);

    List<Class> classes = ClassScanner.scanClassByAnnotation(RequestMapping.class, false);

    Reader.read(swagger, classes);

}
 
Example 4
Source File: ProducerBootListener.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public void onAfterTransport(BootEvent event) {
  // register schema to microservice;
  Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();

  String swaggerSchema = "http";
  for (String endpoint : microservice.getInstance().getEndpoints()) {
    if (endpoint.startsWith("rest://") && endpoint.indexOf("sslEnabled=true") > 0) {
      swaggerSchema = "https";
    }
  }

  MicroserviceMeta microserviceMeta = event.getScbEngine().getProducerMicroserviceMeta();
  for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
    Swagger swagger = schemaMeta.getSwagger();
    swagger.addScheme(Scheme.forValue(swaggerSchema));
    String content = SwaggerUtils.swaggerToString(swagger);
    LOGGER.info("generate swagger for {}/{}/{}, swagger: {}",
        microserviceMeta.getAppId(),
        microserviceMeta.getMicroserviceName(),
        schemaMeta.getSchemaId(),
        content);

    RegistrationManager.INSTANCE.addSchema(schemaMeta.getSchemaId(), content);
  }

  saveBasePaths(microserviceMeta);
}