use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getExternalDocumentation.
public static Optional<ExternalDocumentation> getExternalDocumentation(io.swagger.v3.oas.annotations.ExternalDocumentation externalDocumentation) {
if (externalDocumentation == null) {
return Optional.empty();
}
boolean isEmpty = true;
ExternalDocumentation external = new ExternalDocumentation();
if (StringUtils.isNotBlank(externalDocumentation.description())) {
isEmpty = false;
external.setDescription(externalDocumentation.description());
}
if (StringUtils.isNotBlank(externalDocumentation.url())) {
isEmpty = false;
external.setUrl(externalDocumentation.url());
}
if (externalDocumentation.extensions() != null && externalDocumentation.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(externalDocumentation.extensions());
if (extensions != null) {
extensions.forEach(external::addExtension);
isEmpty = false;
}
}
if (isEmpty) {
return Optional.empty();
}
return Optional.of(external);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getInfo.
public static Optional<Info> getInfo(io.swagger.v3.oas.annotations.info.Info info) {
if (info == null) {
return Optional.empty();
}
boolean isEmpty = true;
Info infoObject = new Info();
if (StringUtils.isNotBlank(info.description())) {
infoObject.setDescription(info.description());
isEmpty = false;
}
if (StringUtils.isNotBlank(info.termsOfService())) {
infoObject.setTermsOfService(info.termsOfService());
isEmpty = false;
}
if (StringUtils.isNotBlank(info.title())) {
infoObject.setTitle(info.title());
isEmpty = false;
}
if (StringUtils.isNotBlank(info.version())) {
infoObject.setVersion(info.version());
isEmpty = false;
}
if (info.extensions() != null && info.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(info.extensions());
if (extensions != null) {
extensions.forEach(infoObject::addExtension);
isEmpty = false;
}
}
if (isEmpty) {
return Optional.empty();
}
getContact(info.contact()).ifPresent(infoObject::setContact);
getLicense(info.license()).ifPresent(infoObject::setLicense);
return Optional.of(infoObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class AnnotationsUtils method getServer.
public static Optional<Server> getServer(io.swagger.v3.oas.annotations.servers.Server server) {
if (server == null) {
return Optional.empty();
}
Server serverObject = new Server();
boolean isEmpty = true;
if (StringUtils.isNotBlank(server.url())) {
serverObject.setUrl(server.url());
isEmpty = false;
}
if (StringUtils.isNotBlank(server.description())) {
serverObject.setDescription(server.description());
isEmpty = false;
}
if (server.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(server.extensions());
if (extensions != null) {
extensions.forEach(serverObject::addExtension);
}
isEmpty = false;
}
if (isEmpty) {
return Optional.empty();
}
io.swagger.v3.oas.annotations.servers.ServerVariable[] serverVariables = server.variables();
ServerVariables serverVariablesObject = new ServerVariables();
for (io.swagger.v3.oas.annotations.servers.ServerVariable serverVariable : serverVariables) {
ServerVariable serverVariableObject = new ServerVariable();
if (StringUtils.isNotBlank(serverVariable.description())) {
serverVariableObject.setDescription(serverVariable.description());
}
if (StringUtils.isNotBlank(serverVariable.defaultValue())) {
serverVariableObject.setDefault(serverVariable.defaultValue());
}
if (serverVariable.allowableValues() != null && serverVariable.allowableValues().length > 0) {
if (StringUtils.isNotBlank(serverVariable.allowableValues()[0])) {
serverVariableObject.setEnum(Arrays.asList(serverVariable.allowableValues()));
}
}
if (serverVariable.extensions() != null && serverVariable.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(serverVariable.extensions());
if (extensions != null) {
extensions.forEach(serverVariableObject::addExtension);
}
}
serverVariablesObject.addServerVariable(serverVariable.name(), serverVariableObject);
}
serverObject.setVariables(serverVariablesObject);
return Optional.of(serverObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class RequestBodyTest method testRequestBodyAnnotationPriority.
@Test(description = "scan class with requesbody annotation")
public void testRequestBodyAnnotationPriority() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(RequestBodyResource.class);
PathItem userPathItem = openAPI.getPaths().get(USER_PATH);
io.swagger.v3.oas.models.parameters.RequestBody getRequestBody = userPathItem.getGet().getRequestBody();
assertNotNull(getRequestBody);
assertEquals(getRequestBody.getDescription(), REQUEST_BODY_IN_ANNOTATION);
io.swagger.v3.oas.models.parameters.RequestBody postRequestBody = userPathItem.getPost().getRequestBody();
assertNotNull(postRequestBody);
assertEquals(postRequestBody.getDescription(), REQUEST_BODY_IN_ANNOTATION);
io.swagger.v3.oas.models.parameters.RequestBody putRequestBody = userPathItem.getPut().getRequestBody();
assertNotNull(putRequestBody);
assertEquals(putRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
io.swagger.v3.oas.models.parameters.RequestBody deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
io.swagger.v3.oas.models.parameters.RequestBody patchRequestBody = userPathItem.getPatch().getRequestBody();
assertNotNull(patchRequestBody);
assertEquals(patchRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserMethod_Param_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_Method_Param_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_Method_Param");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class ParametersTest method testJacksonFeatures.
@Test(description = "JsonUnwrapped, JsonIgnore, JsonValue should be honoured")
public void testJacksonFeatures() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ResourceWithJacksonBean.class);
io.swagger.v3.oas.models.media.Schema o = openAPI.getComponents().getSchemas().get("JacksonBean");
assertEquals(o.getProperties().keySet(), Stream.of("identity", "bean", "code", "message", "precodesuf", "premessagesuf").collect(Collectors.toSet()));
}
Aggregations