use of io.swagger.v3.oas.models.security 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.security 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.security 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()));
}
use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.
the class ParametersTest method scanClassAndFieldLevelAnnotations.
@Test(description = "scan class level and field level annotations")
public void scanClassAndFieldLevelAnnotations() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ResourceWithKnownInjections.class);
List<io.swagger.v3.oas.models.parameters.Parameter> resourceParameters = openAPI.getPaths().get("/resource/{id}").getGet().getParameters();
assertNotNull(resourceParameters);
assertEquals(resourceParameters.size(), 3);
assertEquals(resourceParameters.get(0).getName(), "id");
assertEquals(resourceParameters.get(1).getName(), "fieldParam");
assertEquals(resourceParameters.get(2).getName(), "methodParam");
}
use of io.swagger.v3.oas.models.security in project swagger-core by swagger-api.
the class OperationParser method getRequestBody.
public static Optional<RequestBody> getRequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody requestBody, Consumes classConsumes, Consumes methodConsumes, Components components, JsonView jsonViewAnnotation) {
if (requestBody == null) {
return Optional.empty();
}
RequestBody requestBodyObject = new RequestBody();
boolean isEmpty = true;
if (StringUtils.isNotBlank(requestBody.ref())) {
requestBodyObject.set$ref(requestBody.ref());
return Optional.of(requestBodyObject);
}
if (StringUtils.isNotBlank(requestBody.description())) {
requestBodyObject.setDescription(requestBody.description());
isEmpty = false;
}
if (requestBody.required()) {
requestBodyObject.setRequired(requestBody.required());
isEmpty = false;
}
if (requestBody.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(requestBody.extensions());
if (extensions != null) {
extensions.forEach(requestBodyObject::addExtension);
}
isEmpty = false;
}
if (requestBody.content().length > 0) {
isEmpty = false;
}
if (isEmpty) {
return Optional.empty();
}
AnnotationsUtils.getContent(requestBody.content(), classConsumes == null ? new String[0] : classConsumes.value(), methodConsumes == null ? new String[0] : methodConsumes.value(), null, components, jsonViewAnnotation).ifPresent(requestBodyObject::setContent);
return Optional.of(requestBodyObject);
}
Aggregations