Java Code Examples for io.swagger.v3.oas.models.info.Info#getContact()

The following examples show how to use io.swagger.v3.oas.models.info.Info#getContact() . 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: 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 2
Source File: OverviewDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
private void addAuthorInfo(Document rootDocument, Info info) {
    Contact contact = info.getContact();
    if (null != contact) {
        String author = Optional.ofNullable(contact.getName()).orElse("");
        String email = contact.getEmail();
        if (StringUtils.isNotBlank(email)) {
            rootDocument.setAttribute("email", email, true);
        }
        rootDocument.setAttribute("author", author, true);
        rootDocument.setAttribute("authorcount", 1L, true);
    }
}
 
Example 3
Source File: OpenAPIDeserializerTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "data")
public void readInfoObject(JsonNode rootNode) throws Exception {


    final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
    final SwaggerParseResult result = deserializer.deserialize(rootNode);

    Assert.assertNotNull(result);

    final OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertEquals(openAPI.getOpenapi(),"3.0.1");


    final Info info = openAPI.getInfo();
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getTitle(), "Sample Pet Store App");
    Assert.assertEquals(info.getDescription(), "This is a sample server Petstore");
    Assert.assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
    Assert.assertNotNull(info.getExtensions().get("x-info"));
    Assert.assertEquals(info.getExtensions().get("x-info").toString(),"info extension");

    final Contact contact = info.getContact();
    Assert.assertNotNull(contact);
    Assert.assertEquals(contact.getName(),"API Support");
    Assert.assertEquals(contact.getUrl(),"http://www.example.com/support");
    Assert.assertEquals(contact.getEmail(),"[email protected]");
    Assert.assertNotNull(contact.getExtensions().get("x-contact"));
    Assert.assertEquals(contact.getExtensions().get("x-contact").toString(),"contact extension");

    final License license = info.getLicense();
    Assert.assertNotNull(license);
    Assert.assertEquals(license.getName(), "Apache 2.0");
    Assert.assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
    Assert.assertNotNull(license.getExtensions());

    Assert.assertEquals(info.getVersion(), "1.0.1");

}
 
Example 4
Source File: ClojureClientCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
    super.preprocessOpenAPI(openAPI);

    if (additionalProperties.containsKey(PROJECT_NAME)) {
        projectName = ((String) additionalProperties.get(PROJECT_NAME));
    }
    if (additionalProperties.containsKey(PROJECT_DESCRIPTION)) {
        projectDescription = ((String) additionalProperties.get(PROJECT_DESCRIPTION));
    }
    if (additionalProperties.containsKey(PROJECT_VERSION)) {
        projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
    }
    if (additionalProperties.containsKey(BASE_NAMESPACE)) {
        baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE));
    }

    if (openAPI.getInfo() != null) {
        Info info = openAPI.getInfo();
        if (projectName == null && info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            projectName = dashize(info.getTitle());
        }
        if (projectVersion == null) {
            // when projectVersion is not specified, use info.version
            projectVersion = info.getVersion();
        }
        if (projectDescription == null) {
            // when projectDescription is not specified, use info.description
            projectDescription = info.getDescription();
        }

        if (info.getContact() != null) {
            Contact contact = info.getContact();
            if (additionalProperties.get(PROJECT_URL) == null) {
                additionalProperties.put(PROJECT_URL, contact.getUrl());
            }
        }
        if (info.getLicense() != null) {
            License license = info.getLicense();
            if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
                additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
            }
            if (additionalProperties.get(PROJECT_LICENSE_URL) == null) {
                additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl());
            }
        }
    }

    // default values
    if (projectName == null) {
        projectName = "openapi-clj-client";
    }
    if (projectVersion == null) {
        projectVersion = "1.0.0";
    }
    if (projectDescription == null) {
        projectDescription = "Client library of " + projectName;
    }
    if (baseNamespace == null) {
        baseNamespace = dashize(projectName);
    }
    apiPackage = baseNamespace + ".api";
    modelPackage = baseNamespace + ".specs";

    additionalProperties.put(PROJECT_NAME, projectName);
    additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
    additionalProperties.put(PROJECT_VERSION, projectVersion);
    additionalProperties.put(BASE_NAMESPACE, baseNamespace);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
    additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);

    final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace);
    supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj"));
    supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj"));
    supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
    supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}
 
Example 5
Source File: DefaultGenerator.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
private void configureOpenAPIInfo() {
    Info info = this.openAPI.getInfo();
    if (info == null) {
        return;
    }
    if (info.getTitle() != null) {
        config.additionalProperties().put("appName", config.escapeText(info.getTitle()));
    }
    if (info.getVersion() != null) {
        config.additionalProperties().put("appVersion", config.escapeText(info.getVersion()));
    } else {
        LOGGER.error("Missing required field info version. Default appVersion set to 1.0.0");
        config.additionalProperties().put("appVersion", "1.0.0");
    }

    if (StringUtils.isEmpty(info.getDescription())) {
        // set a default description if none if provided
        config.additionalProperties().put("appDescription",
                "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
        config.additionalProperties().put("appDescriptionWithNewLines", config.additionalProperties().get("appDescription"));
        config.additionalProperties().put("unescapedAppDescription", "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)");
    } else {
        config.additionalProperties().put("appDescription", config.escapeText(info.getDescription()));
        config.additionalProperties().put("appDescriptionWithNewLines", config.escapeTextWhileAllowingNewLines(info.getDescription()));
        config.additionalProperties().put("unescapedAppDescription", info.getDescription());
    }

    if (info.getContact() != null) {
        Contact contact = info.getContact();
        if (contact.getEmail() != null) {
            config.additionalProperties().put("infoEmail", config.escapeText(contact.getEmail()));
        }
        if (contact.getName() != null) {
            config.additionalProperties().put("infoName", config.escapeText(contact.getName()));
        }
        if (contact.getUrl() != null) {
            config.additionalProperties().put("infoUrl", config.escapeText(contact.getUrl()));
        }
    }

    if (info.getLicense() != null) {
        License license = info.getLicense();
        if (license.getName() != null) {
            config.additionalProperties().put("licenseInfo", config.escapeText(license.getName()));
        }
        if (license.getUrl() != null) {
            config.additionalProperties().put("licenseUrl", config.escapeText(license.getUrl()));
        }
    }

    if (info.getVersion() != null) {
        config.additionalProperties().put("version", config.escapeText(info.getVersion()));
    } else {
        LOGGER.error("Missing required field info version. Default version set to 1.0.0");
        config.additionalProperties().put("version", "1.0.0");
    }

    if (info.getTermsOfService() != null) {
        config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService()));
    }
}