io.swagger.v3.oas.models.info.Info Java Examples

The following examples show how to use io.swagger.v3.oas.models.info.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: OpenApiFeature.java    From cxf with Apache License 2.0 7 votes vote down vote up
/**
 * The info will be used only if there is no @OpenAPIDefinition annotation is present.
 */
private Info getInfo(final Properties properties) {
    final Info info = new Info()
            .title(getOrFallback(getTitle(), properties, TITLE_PROPERTY))
            .version(getOrFallback(getVersion(), properties, VERSION_PROPERTY))
            .description(getOrFallback(getDescription(), properties, DESCRIPTION_PROPERTY))
            .termsOfService(getOrFallback(getTermsOfServiceUrl(), properties, TERMS_URL_PROPERTY))
            .contact(new Contact()
                    .name(getOrFallback(getContactName(), properties, CONTACT_PROPERTY))
                    .email(getContactEmail())
                    .url(getContactUrl()))
            .license(new License()
                    .name(getOrFallback(getLicense(), properties, LICENSE_PROPERTY))
                    .url(getOrFallback(getLicenseUrl(), properties, LICENSE_URL_PROPERTY)));

    if (info.getLicense().getName() == null) {
        info.getLicense().setName(DEFAULT_LICENSE_VALUE);
    }

    if (info.getLicense().getUrl() == null && DEFAULT_LICENSE_VALUE.equals(info.getLicense().getName())) {
        info.getLicense().setUrl(DEFAULT_LICENSE_URL);
    }

    return info;
}
 
Example #2
Source File: SerializerUtilsTest.java    From openapi-generator with Apache License 2.0 7 votes vote down vote up
private OpenAPI createCompleteExample() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setInfo(new Info().title("Some title").description("Some description"));
    openAPI.setExternalDocs(new ExternalDocumentation().url("http://abcdef.com").description("a-description"));
    openAPI.setServers(Arrays.asList(
            new Server().url("http://www.server1.com").description("first server"),
            new Server().url("http://www.server2.com").description("second server")
        ));
    openAPI.setSecurity(Arrays.asList(
            new SecurityRequirement().addList("some_auth", Arrays.asList("write", "read"))
        ));
    openAPI.setTags(Arrays.asList(
            new Tag().name("tag1").description("some 1 description"),
            new Tag().name("tag2").description("some 2 description"),
            new Tag().name("tag3").description("some 3 description")
        ));
    openAPI.path("/ping/pong", new PathItem().get(new Operation()
            .description("Some description")
            .operationId("pingOp")
            .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("Ok")))));
    openAPI.components(new Components().addSchemas("SomeObject", new ObjectSchema().description("An Obj").addProperties("id", new StringSchema())));
    openAPI.setExtensions(new LinkedHashMap<>()); // required because swagger-core is using HashMap instead of LinkedHashMap internally.
    openAPI.addExtension("x-custom", "value1");
    openAPI.addExtension("x-other", "value2");
    return openAPI;
}
 
Example #3
Source File: RustServerCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {

    Info info = openAPI.getInfo();

    URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
    additionalProperties.put("serverHost", url.getHost());
    additionalProperties.put("serverPort", URLPathUtils.getPort(url, serverPort));

    if (packageVersion == null || "".equals(packageVersion)) {
        List<String> versionComponents = new ArrayList<>(Arrays.asList(info.getVersion().split("[.]")));
        if (versionComponents.size() < 1) {
            versionComponents.add("1");
        }
        while (versionComponents.size() < 3) {
            versionComponents.add("0");
        }

        setPackageVersion(StringUtils.join(versionComponents, "."));
    }

    additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
}
 
Example #4
Source File: OpenAPIBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve properties info.
 *
 * @param info the info
 * @return the info
 */
private Info resolveProperties(Info info) {
	PropertyResolverUtils propertyResolverUtils = context.getBean(PropertyResolverUtils.class);
	resolveProperty(info::getTitle, info::title, propertyResolverUtils);
	resolveProperty(info::getDescription, info::description, propertyResolverUtils);
	resolveProperty(info::getVersion, info::version, propertyResolverUtils);
	resolveProperty(info::getTermsOfService, info::termsOfService, propertyResolverUtils);

	License license = info.getLicense();
	if (license != null) {
		resolveProperty(license::getName, license::name, propertyResolverUtils);
		resolveProperty(license::getUrl, license::url, propertyResolverUtils);
	}

	Contact contact = info.getContact();
	if (contact != null) {
		resolveProperty(contact::getName, contact::name, propertyResolverUtils);
		resolveProperty(contact::getEmail, contact::email, propertyResolverUtils);
		resolveProperty(contact::getUrl, contact::url, propertyResolverUtils);
	}
	return info;
}
 
Example #5
Source File: AbstractApiDocServiceTest.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
private OpenAPI getDummyOpenApiObject(List<Server> servers) {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setPaths(new Paths());
    openAPI.setTags(new ArrayList<>());
    openAPI.setOpenapi("3.0.0");
    openAPI.setServers(servers);

    Info info = new Info();
    info.setTitle("API Catalog");
    info.setDescription("REST API for the API Catalog service which is a component of the API Mediation Layer. Use this API to retrieve information regarding catalog dashboard tiles, tile contents and its status, API documentation and status for the registered services.");
    info.setVersion("1.0.0");
    openAPI.setInfo(info);

    Tag tag = new Tag();
    tag.setName("API Catalog");
    tag.setDescription("Current state information");
    openAPI.getTags().add(tag);

    openAPI.getPaths().put("/api1", new PathItem());
    openAPI.getPaths().put("/api2", new PathItem());
    return openAPI;
}
 
Example #6
Source File: ApiDocControllerTest.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
private OpenAPI getDummyOpenApiObject() {
    List<Server> servers = new ArrayList<>();
    servers.add(0, new Server().url("/api/v1/apicatalog"));
    OpenAPI openAPI = new OpenAPI();
    openAPI.setPaths(new Paths());
    openAPI.setTags(new ArrayList<>());
    openAPI.setOpenapi("3.0.0");
    openAPI.setServers(servers);

    Info info = new Info();
    info.setTitle("Service title");
    info.setDescription("Service description");
    info.setVersion("1.0.0");
    openAPI.setInfo(info);

    return openAPI;
}
 
Example #7
Source File: OpenApiObjectGenerator.java    From flow with Apache License 2.0 6 votes vote down vote up
private OpenAPI createBasicModel() {
    OpenAPI openAPI = new OpenAPI();

    Info info = new Info();
    info.setTitle(configuration.getApplicationTitle());
    info.setVersion(configuration.getApplicationApiVersion());
    openAPI.setInfo(info);

    Paths paths = new Paths();
    openAPI.setPaths(paths);

    Server server = new Server();
    server.setUrl(configuration.getServerUrl());
    server.setDescription(configuration.getServerDescription());
    openAPI.setServers(Collections.singletonList(server));
    Components components = new Components();
    SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme()
            .type(SecurityScheme.Type.OAUTH2)
            .flows(new OAuthFlows().password(new OAuthFlow()
                    .tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL)
                    .scopes(new Scopes())));
    components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME,
            vaadinConnectOAuth2Scheme);
    openAPI.components(components);
    return openAPI;
}
 
Example #8
Source File: RaptorSwaggerConverter.java    From raptor with Apache License 2.0 6 votes vote down vote up
/**
 * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#info-object
 *
 * @param protoFile
 * @return
 */
@Override
protected Info getInfo(ProtoFile protoFile, Service service) {
    Info info = new Info();

    ProtoFileMetaInfo protoFileMetaInfo = ProtoFileMetaInfo.readFrom(protoFile);
    InterfaceMetaInfo interfaceMetaInfo = InterfaceMetaInfo.readFrom(protoFile, service);

    String version = protoFileMetaInfo.getVersion();
    if(StringUtils.isBlank(version)) {
        version = "0.0.1";
    }

    //required
    info.title(service.name());
    info.version(version);

    //optional
    // TODO: 2018/5/23 将 protoFileMetaInfo 和 interfaceMetaInfo 整合到description中
    info.description(service.documentation());
    info.contact(getContact());
    info.license(getLicense());

    return info;
}
 
Example #9
Source File: BeaconRestApi.java    From teku with Apache License 2.0 6 votes vote down vote up
private static OpenApiOptions getOpenApiOptions(
    final JsonProvider jsonProvider, final TekuConfiguration config) {
  final JacksonModelConverterFactory factory =
      new JacksonModelConverterFactory(jsonProvider.getObjectMapper());

  final Info applicationInfo =
      new Info()
          .title(StringUtils.capitalize(VersionProvider.CLIENT_IDENTITY))
          .version(VersionProvider.IMPLEMENTATION_VERSION)
          .description(
              "A minimal API specification for the beacon node, which enables a validator "
                  + "to connect and perform its obligations on the Ethereum 2.0 phase 0 beacon chain.")
          .license(
              new License()
                  .name("Apache 2.0")
                  .url("https://www.apache.org/licenses/LICENSE-2.0.html"));
  final OpenApiOptions options =
      new OpenApiOptions(applicationInfo).modelConverterFactory(factory);
  if (config.isRestApiDocsEnabled()) {
    options.path("/swagger-docs").swagger(new SwaggerOptions("/swagger-ui"));
  }
  return options;
}
 
Example #10
Source File: KotlinSpringServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
    codegen.processOpts();

    final OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    openAPI.setInfo(new Info());
    codegen.preprocessOpenAPI(openAPI);

    Assert.assertEquals(codegen.getLibrary(), KotlinSpringServerCodegen.SPRING_BOOT);
    Assert.assertTrue(codegen.supportedLibraries().containsKey(KotlinSpringServerCodegen.SPRING_BOOT));

    Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
    Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
    Assert.assertEquals(codegen.getBasePackage(), "org.openapitools");
    Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.BASE_PACKAGE), "org.openapitools");
    Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
    Assert.assertEquals(codegen.getServerPort(), "8080");
    Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080");
}
 
Example #11
Source File: SpringCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    final SpringCodegen codegen = new SpringCodegen();
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    openAPI.setInfo(new Info());
    codegen.preprocessOpenAPI(openAPI);

    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
    Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
    Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
    Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
    Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
    Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
    Assert.assertEquals(codegen.getBasePackage(), "org.openapitools");
    Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "org.openapitools");
    Assert.assertEquals(codegen.getConfigPackage(), "org.openapitools.configuration");
    Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "org.openapitools.configuration");
    Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8082");
    Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), false);
}
 
Example #12
Source File: TestUtils.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public static OpenAPI createOpenAPI() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.setComponents(new Components());
    openAPI.setPaths(new Paths());

    final Info info = new Info();
    info.setDescription("API under test");
    info.setVersion("1.0.7");
    info.setTitle("My title");
    openAPI.setInfo(info);

    final Server server = new Server();
    server.setUrl("https://localhost:9999/root");
    openAPI.setServers(Collections.singletonList(server));
    return openAPI;
}
 
Example #13
Source File: OverviewDocument.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
private void appendLicenseInfo(Section overviewDoc, Info info) {
    License license = info.getLicense();
    if (null != license) {
        StringBuilder sb = new StringBuilder();
        if (StringUtils.isNotBlank(license.getUrl())) {
            sb.append(license.getUrl()).append("[");
        }
        sb.append(license.getName());
        if (StringUtils.isNotBlank(license.getUrl())) {
            sb.append("]");
        }
        BlockImpl paragraph = new ParagraphBlockImpl(overviewDoc);
        paragraph.setSource(sb.toString());
        overviewDoc.append(paragraph);
    }
}
 
Example #14
Source File: Application.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI(@Value("${springdoc.version}") String appVersion) {
    return new OpenAPI().info(new Info().title("Foobar API")
        .version(appVersion)
        .description("This is a sample Foobar server created using springdocs - a library for OpenAPI 3 with spring boot.")
        .termsOfService("http://swagger.io/terms/")
        .license(new License().name("Apache 2.0")
            .url("http://springdoc.org")));
}
 
Example #15
Source File: Bootstrap.java    From submarine with Apache License 2.0 5 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {

  OpenAPI oas = new OpenAPI();
  Info info = new Info()
           .title("Submarine Experiment API")
           .description("The Submarine REST API allows you to create, list, and get experiments. The\n" +
                   "API is hosted under the /v1/experiment route on the Submarine server. For example,\n" +
                   "to list experiments on a server hosted at http://localhost:8080, access\n" +
                   "http://localhost:8080/api/v1/experiment/")
           .termsOfService("http://swagger.io/terms/")
           .contact(new Contact()
           .email("[email protected]"))
           .version("0.4.0")
           .license(new License()
           .name("Apache 2.0")
           .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

  oas.info(info);
  List<Server> servers = new ArrayList<>();
  servers.add(new Server().url("/api"));
  oas.servers(servers);
  SwaggerConfiguration oasConfig = new SwaggerConfiguration()
          .openAPI(oas)
          .resourcePackages(Stream.of("org.apache.submarine.server.rest").collect(Collectors.toSet()));

  try {
    new JaxrsOpenApiContextBuilder()
            .servletConfig(config)
            .openApiConfiguration(oasConfig)
            .buildContext(true);
  } catch (OpenApiConfigurationException e) {
    throw new ServletException(e.getMessage(), e);
  }
}
 
Example #16
Source File: SpringBatchRestCoreAutoConfiguration.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components())
            .info(new Info()
                    .title("Spring Batch REST")
                    .version(buildProperties == null ? null : String.format("%s  -  Build time %s", buildProperties.getVersion(), buildProperties.getTime()))
                    .description("REST API for controlling and viewing <a href=\"https://spring.io/projects/spring-batch\">" +
                            "Spring Batch</a> jobs and their <a href=\"http://www.quartz-scheduler.org\">Quartz</a> schedules.")
                    .license(new License().name("Apache License 2.0").url("http://github.com/chrisgleissner/spring-batch-rest/blob/master/LICENSE")));
}
 
Example #17
Source File: SwaggerInfo.java    From swagger-maven-plugin with MIT License 5 votes vote down vote up
public Info createInfoModel() {
    Info info = new Info();

    if (title != null) {
        info.setTitle(title);
    }

    if (version != null) {
        info.setVersion(version);
    }

    if (description != null) {
        info.setDescription(description);
    }

    if (termsOfService != null) {
        info.setTermsOfService(termsOfService);
    }

    if (contact != null) {
        info.setContact(contact.createContactModel());
    }

    if (license != null) {
        info.setLicense(license.createLicenseModel());
    }

    if (extensions != null && !extensions.isEmpty()) {
        info.setExtensions(extensions);
    }

    return info;
}
 
Example #18
Source File: ProtoOpenAPI.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
/**
 * Add the minimal information required for OpenAPI Info segment.
 * The same name is assigned as the basePath.
 *
 * @param name API name
 */
void addOpenAPIInfo(String name) {
    Info info = new Info();
    info.setTitle(name);
    //version is mandatory for openAPI
    //version is set to 1.0.0 as default.
    info.setVersion(ProtoToOpenAPIConstants.DEFAULT_VERSION);
    openAPI.setInfo(info);
    openAPI.addExtension(OpenAPIConstants.BASEPATH, ProtoToOpenAPIConstants.PATH_SEPARATOR + name);
}
 
Example #19
Source File: SwaggerConverter.java    From raptor with Apache License 2.0 5 votes vote down vote up
/**
 * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#info-object
 *
 * @param protoFile
 * @return
 */
protected Info getInfo(ProtoFile protoFile, Service service) {
    Info info = new Info();

    //required
    info.title(service.name());
    info.version("0.0.1");

    //optional
    info.description(service.documentation());
    info.contact(getContact());
    info.license(getLicense());

    return info;
}
 
Example #20
Source File: MCRRestV2App.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private void setupOAS() {
    OpenAPI oas = new OpenAPI();
    Info oasInfo = new Info();
    oas.setInfo(oasInfo);
    oasInfo.setVersion(MCRCoreVersion.getVersion());
    oasInfo.setTitle(getApplicationName());
    License oasLicense = new License();
    oasLicense.setName("GNU General Public License, version 3");
    oasLicense.setUrl("http://www.gnu.org/licenses/gpl-3.0.txt");
    oasInfo.setLicense(oasLicense);
    URI baseURI = URI.create(MCRFrontendUtil.getBaseURL());
    Server oasServer = new Server();
    oasServer.setUrl(baseURI.resolve("api").toString());
    oas.addServersItem(oasServer);
    SwaggerConfiguration oasConfig = new SwaggerConfiguration()
        .openAPI(oas)
        .resourcePackages(Stream.of(getRestPackages()).collect(Collectors.toSet()))
        .ignoredRoutes(
            MCRConfiguration2.getString("MCR.RestAPI.V2.OpenAPI.IgnoredRoutes")
                .map(MCRConfiguration2::splitValue)
                .orElseGet(Stream::empty)
                .collect(Collectors.toSet()))
        .prettyPrint(true);
    try {
        new JaxrsOpenApiContextBuilder()
            .application(getApplication())
            .openApiConfiguration(oasConfig)
            .buildContext(true);
    } catch (OpenApiConfigurationException e) {
        throw new InternalServerErrorException(e);
    }
}
 
Example #21
Source File: OpenApiTest.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Test
public void testOpenApiEndpoint() {
    OpenAPI openAPI = new OpenAPI();

    openAPI.info(
        new Info()
            .title("My Service")
            .description("Service REST API")
            .contact(
                new Contact()
                    .email("[email protected]"))
    );

    ServiceRegistration<OpenAPI> serviceRegistration =
        bundleContext.registerService(
            OpenAPI.class, openAPI, new Hashtable<>());

    try {
        WebTarget webTarget = createDefaultTarget().
            path("openapi.json");

        registerAddon(new TestOpenApiResource());

        String response = webTarget.request().get(String.class);

        assertTrue(response.contains("operation"));
    }
    finally {
        serviceRegistration.unregister();
    }
}
 
Example #22
Source File: SpringDocTestApp.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public OpenAPI customOpenAPI() {
	return new OpenAPI()
			.components(new Components().addSecuritySchemes("basicScheme",
					new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
			.info(new Info().title("Tweet API").version("v0")
					.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
 
Example #23
Source File: JaxRsActivatorNew.java    From pnc with Apache License 2.0 5 votes vote down vote up
private void configureSwagger() {
    OpenAPI oas = new OpenAPI();
    Info info = new Info().title("PNC")
            .description("PNC build system")
            .termsOfService("http://swagger.io/terms/")
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    oas.info(info);
    oas.addServersItem(new Server().url("/pnc-rest-new"));

    final SecurityScheme authScheme = getAuthScheme();
    if (authScheme == null) {
        logger.warn("Not adding auth scheme to openapi definition as auth scheme could not been generated.");
    } else {
        oas.schemaRequirement(KEYCLOAK_AUTH, authScheme);
        oas.addSecurityItem(new SecurityRequirement().addList(KEYCLOAK_AUTH));
    }

    SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);

    try {
        new JaxrsOpenApiContextBuilder().servletConfig(servletConfig)
                .application(this)
                .openApiConfiguration(oasConfig)
                .buildContext(true);
    } catch (OpenApiConfigurationException ex) {
        throw new IllegalArgumentException("Failed to setup OpenAPI configuration", ex);
    }
}
 
Example #24
Source File: ElixirClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
    Info info = openAPI.getInfo();
    if (moduleName == null) {
        if (info.getTitle() != null) {
            // default to the appName (from title field)
            setModuleName(modulized(escapeText(info.getTitle())));
        } else {
            setModuleName(defaultModuleName);
        }
    }
    additionalProperties.put("moduleName", moduleName);

    if (!additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
        additionalProperties.put(CodegenConstants.PACKAGE_NAME, underscored(moduleName));
    }

    supportingFiles.add(new SupportingFile("connection.ex.mustache",
            sourceFolder(),
            "connection.ex"));

    supportingFiles.add(new SupportingFile("request_builder.ex.mustache",
            sourceFolder(),
            "request_builder.ex"));


    supportingFiles.add(new SupportingFile("deserializer.ex.mustache",
            sourceFolder(),
            "deserializer.ex"));
}
 
Example #25
Source File: InputModeller.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns a {@link SystemInputDef system input definition} for the API requests defined by the given
 * OpenAPI specification. Returns null if the given spec defines no API requests to model.
 */
protected SystemInputDef requestInputModel( OpenAPI api)
  {
  Info info;
  String title;
  try
    {
    info = expectedValueOf( api.getInfo(), "API info");
    title = expectedValueOf( StringUtils.trimToNull( info.getTitle()), "API title");
    }
  catch( Exception e)
    {
    throw new OpenApiException( "Invalid API spec", e);
    }

  return
    resultFor( title,
      () -> {
      SystemInputDef inputDef =
        SystemInputDefBuilder.with( toIdentifier( title))
        .has( "title", title)
        .has( "version", info.getVersion())
        .hasIf( "server", membersOf( api.getServers()).findFirst().map( InputModeller::getServerUrl))
        .functions( entriesOf( api.getPaths()).flatMap( path -> pathRequestDefs( api, path.getKey(), path.getValue())))
        .build();

      return
        inputDef.getFunctionInputDefs().hasNext()
        ? inputDef
        : null;
      });
  }
 
Example #26
Source File: InputModeller.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns a {@link SystemInputDef system input definition} for the API responses defined by the given
 * OpenAPI specification. Returns null if the given spec defines no API responses to model.
 */
protected SystemInputDef responseInputModel( OpenAPI api)
  {
  Info info;
  String title;
  try
    {
    info = expectedValueOf( api.getInfo(), "API info");
    title = expectedValueOf( StringUtils.trimToNull( info.getTitle()), "API title");
    }
  catch( Exception e)
    {
    throw new OpenApiException( "Invalid API spec", e);
    }

  return
    resultFor( title,
      () -> {
      SystemInputDef inputDef =
        SystemInputDefBuilder.with( toIdentifier( title))
        .has( "title", title)
        .has( "version", info.getVersion())
        .hasIf( "server", membersOf( api.getServers()).findFirst().map( InputModeller::getServerUrl))
        .functions( entriesOf( api.getPaths()).flatMap( path -> pathResponseDefs( api, path.getKey(), path.getValue())))
        .build();

      return
        inputDef.getFunctionInputDefs().hasNext()
        ? inputDef
        : null;
      });
  }
 
Example #27
Source File: OverviewDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Override
public Document apply(Document document, Parameters parameters) {
    Info apiInfo = parameters.openAPI.getInfo();
    document.setAttribute("openapi", parameters.openAPI.getOpenapi(), true);
    addDocumentTitle(document, apiInfo);
    addAuthorInfo(document, apiInfo);
    addVersionInfo(document, apiInfo);

    applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEFORE, document));
    Document subDocument = new DocumentImpl(document);
    Section overviewDoc = new SectionImpl(subDocument, "section", new HashMap<>(), new ArrayList<>(),
            null, new ArrayList<>(), 1, "", new ArrayList<>(),
            null, null, "", "", false, false);
    applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_BEGIN, subDocument));
    overviewDoc.setTitle(labels.getLabel(SECTION_TITLE_OVERVIEW));

    appendDescription(overviewDoc, apiInfo.getDescription());
    appendTermsOfServiceInfo(overviewDoc, apiInfo);
    appendLicenseInfo(overviewDoc, apiInfo);
    subDocument.append(overviewDoc);
    applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_END, subDocument));
    document.append(subDocument);

    externalDocumentationComponent.apply(document, parameters.openAPI.getExternalDocs());
    tagsComponent.apply(document, parameters.openAPI.getTags());
    applyOverviewDocumentExtension(new Context(OverviewDocumentExtension.Position.DOCUMENT_AFTER, document));
    return document;
}
 
Example #28
Source File: JavascriptFlowtypedClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
    super.preprocessOpenAPI(openAPI);

    if (openAPI.getInfo() != null) {
        Info info = openAPI.getInfo();
        if (StringUtils.isBlank(npmName) && info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            npmName = sanitizeName(dashize(info.getTitle()));
        }
        if (StringUtils.isBlank(npmVersion)) {
            // when projectVersion is not specified, use info.version
            npmVersion = escapeUnsafeCharacters(escapeQuotationMark(info.getVersion()));
        }
    }

    // default values
    if (StringUtils.isBlank(npmName)) {
        npmName = "openapi-js-client";
    }
    if (StringUtils.isBlank(npmVersion)) {
        npmVersion = "1.0.0";
    }

    additionalProperties.put(NPM_NAME, npmName);
    additionalProperties.put(NPM_VERSION, npmVersion);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
}
 
Example #29
Source File: StaticHtmlGenerator.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public void preprocessOpenAPI(OpenAPI openAPI) {
    Info info = openAPI.getInfo();
    info.setDescription(toHtml(info.getDescription()));
    info.setTitle(toHtml(info.getTitle()));
    Map<String, Schema> models = ModelUtils.getSchemas(openAPI);
    for (Schema model : models.values()) {
        model.setDescription(toHtml(model.getDescription()));
        model.setTitle(toHtml(model.getTitle()));
    }
}
 
Example #30
Source File: SwaggerConverter.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
public Info convert(io.swagger.models.Info v2Info) {
    Info info = new Info();

    info.setContact(convert(v2Info.getContact()));
    info.setDescription(v2Info.getDescription());
    info.setLicense(convert(v2Info.getLicense()));
    info.setTermsOfService(v2Info.getTermsOfService());
    info.setTitle(v2Info.getTitle());
    info.setVersion(v2Info.getVersion());
    info.setExtensions(convert(v2Info.getVendorExtensions()));

    return info;
}