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;
}
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" + "}");
}
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);
}
Aggregations