Search in sources :

Example 11 with License

use of io.swagger.v3.oas.models.info.License in project swagger-parser by swagger-api.

the class SwaggerConverter method convert.

private License convert(io.swagger.models.License v2License) {
    if (v2License == null) {
        return null;
    }
    License license = new License();
    license.setExtensions(convert(v2License.getVendorExtensions()));
    license.setName(v2License.getName());
    license.setUrl(v2License.getUrl());
    return license;
}
Also used : License(io.swagger.v3.oas.models.info.License)

Example 12 with License

use of io.swagger.v3.oas.models.info.License in project swagger-core by swagger-api.

the class OpenAPI3_1SerializationTest method testInfoSerialization.

@Test
public void testInfoSerialization() {
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").info(new Info().title("Title test").description("This is a description for test").summary("Test Summary").version("1.0.0").termsOfService("https://test.term.of.services").contact(new Contact().name("Test Contact").url("https://test.contact.url").email("test@email.com")).license(new License().name("test license").url("https://test.license.com").identifier("swagger")));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "info:\n" + "  title: Title test\n" + "  description: This is a description for test\n" + "  summary: Test Summary\n" + "  termsOfService: https://test.term.of.services\n" + "  contact:\n" + "    name: Test Contact\n" + "    url: https://test.contact.url\n" + "    email: test@email.com\n" + "  license:\n" + "    name: test license\n" + "    url: https://test.license.com\n" + "    identifier: swagger\n" + "  version: 1.0.0");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"info\" : {\n" + "    \"title\" : \"Title test\",\n" + "    \"description\" : \"This is a description for test\",\n" + "    \"summary\" : \"Test Summary\",\n" + "    \"termsOfService\" : \"https://test.term.of.services\",\n" + "    \"contact\" : {\n" + "      \"name\" : \"Test Contact\",\n" + "      \"url\" : \"https://test.contact.url\",\n" + "      \"email\" : \"test@email.com\"\n" + "    },\n" + "    \"license\" : {\n" + "      \"name\" : \"test license\",\n" + "      \"url\" : \"https://test.license.com\",\n" + "      \"identifier\" : \"swagger\"\n" + "    },\n" + "    \"version\" : \"1.0.0\"\n" + "  }\n" + "}");
    openAPI.setOpenapi("3.0.3");
    SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + "info:\n" + "  title: Title test\n" + "  description: This is a description for test\n" + "  termsOfService: https://test.term.of.services\n" + "  contact:\n" + "    name: Test Contact\n" + "    url: https://test.contact.url\n" + "    email: test@email.com\n" + "  license:\n" + "    name: test license\n" + "    url: https://test.license.com\n" + "  version: 1.0.0");
    SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + "  \"openapi\" : \"3.0.3\",\n" + "  \"info\" : {\n" + "    \"title\" : \"Title test\",\n" + "    \"description\" : \"This is a description for test\",\n" + "    \"termsOfService\" : \"https://test.term.of.services\",\n" + "    \"contact\" : {\n" + "      \"name\" : \"Test Contact\",\n" + "      \"url\" : \"https://test.contact.url\",\n" + "      \"email\" : \"test@email.com\"\n" + "    },\n" + "    \"license\" : {\n" + "      \"name\" : \"test license\",\n" + "      \"url\" : \"https://test.license.com\"\n" + "    },\n" + "    \"version\" : \"1.0.0\"\n" + "  }\n" + "}");
}
Also used : License(io.swagger.v3.oas.models.info.License) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Contact(io.swagger.v3.oas.models.info.Contact) Test(org.testng.annotations.Test)

Example 13 with License

use of io.swagger.v3.oas.models.info.License in project swagger-core by swagger-api.

the class AnnotationsUtils method getLicense.

public static Optional<License> getLicense(io.swagger.v3.oas.annotations.info.License license) {
    if (license == null) {
        return Optional.empty();
    }
    License licenseObject = new License();
    boolean isEmpty = true;
    if (StringUtils.isNotBlank(license.name())) {
        licenseObject.setName(license.name());
        isEmpty = false;
    }
    if (StringUtils.isNotBlank(license.url())) {
        licenseObject.setUrl(license.url());
        isEmpty = false;
    }
    if (license.extensions() != null && license.extensions().length > 0) {
        Map<String, Object> extensions = AnnotationsUtils.getExtensions(license.extensions());
        if (extensions != null) {
            extensions.forEach(licenseObject::addExtension);
            isEmpty = false;
        }
    }
    if (isEmpty) {
        return Optional.empty();
    }
    return Optional.of(licenseObject);
}
Also used : License(io.swagger.v3.oas.models.info.License) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject)

Aggregations

License (io.swagger.v3.oas.models.info.License)8 Contact (io.swagger.v3.oas.models.info.Contact)5 Info (io.swagger.v3.oas.models.info.Info)5 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)5 OpenAPI (io.swagger.v3.oas.models.OpenAPI)4 Test (org.testng.annotations.Test)4 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)3 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Json (io.swagger.v3.core.util.Json)1 OpenApiResource (io.swagger.v3.jaxrs2.integration.resources.OpenApiResource)1 ExampleObject (io.swagger.v3.oas.annotations.media.ExampleObject)1 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)1 io.swagger.v3.oas.models.security (io.swagger.v3.oas.models.security)1 SecurityRequirement (io.swagger.v3.oas.models.security.SecurityRequirement)1 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)1 In (io.swagger.v3.oas.models.security.SecurityScheme.In)1