use of io.swagger.v3.oas.models.media 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.media 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);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class SecurityParser method getOAuthFlows.
public static Optional<OAuthFlows> getOAuthFlows(io.swagger.v3.oas.annotations.security.OAuthFlows oAuthFlows) {
if (isEmpty(oAuthFlows)) {
return Optional.empty();
}
OAuthFlows oAuthFlowsObject = new OAuthFlows();
if (oAuthFlows.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(oAuthFlows.extensions());
if (extensions != null) {
extensions.forEach(oAuthFlowsObject::addExtension);
}
}
getOAuthFlow(oAuthFlows.authorizationCode()).ifPresent(oAuthFlowsObject::setAuthorizationCode);
getOAuthFlow(oAuthFlows.clientCredentials()).ifPresent(oAuthFlowsObject::setClientCredentials);
getOAuthFlow(oAuthFlows.implicit()).ifPresent(oAuthFlowsObject::setImplicit);
getOAuthFlow(oAuthFlows.password()).ifPresent(oAuthFlowsObject::setPassword);
return Optional.of(oAuthFlowsObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class SecurityParser method getOAuthFlow.
public static Optional<OAuthFlow> getOAuthFlow(io.swagger.v3.oas.annotations.security.OAuthFlow oAuthFlow) {
if (isEmpty(oAuthFlow)) {
return Optional.empty();
}
OAuthFlow oAuthFlowObject = new OAuthFlow();
if (StringUtils.isNotBlank(oAuthFlow.authorizationUrl())) {
oAuthFlowObject.setAuthorizationUrl(oAuthFlow.authorizationUrl());
}
if (StringUtils.isNotBlank(oAuthFlow.refreshUrl())) {
oAuthFlowObject.setRefreshUrl(oAuthFlow.refreshUrl());
}
if (StringUtils.isNotBlank(oAuthFlow.tokenUrl())) {
oAuthFlowObject.setTokenUrl(oAuthFlow.tokenUrl());
}
if (oAuthFlow.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(oAuthFlow.extensions());
if (extensions != null) {
extensions.forEach(oAuthFlowObject::addExtension);
}
}
getScopes(oAuthFlow.scopes()).ifPresent(oAuthFlowObject::setScopes);
return Optional.of(oAuthFlowObject);
}
use of io.swagger.v3.oas.models.media in project swagger-core by swagger-api.
the class SecurityParser method getSecurityScheme.
public static Optional<SecuritySchemePair> getSecurityScheme(io.swagger.v3.oas.annotations.security.SecurityScheme securityScheme) {
if (securityScheme == null) {
return Optional.empty();
}
String key = null;
SecurityScheme securitySchemeObject = new SecurityScheme();
if (StringUtils.isNotBlank(securityScheme.in().toString())) {
securitySchemeObject.setIn(getIn(securityScheme.in().toString()));
}
if (StringUtils.isNotBlank(securityScheme.type().toString())) {
securitySchemeObject.setType(getType(securityScheme.type().toString()));
}
if (StringUtils.isNotBlank(securityScheme.openIdConnectUrl())) {
securitySchemeObject.setOpenIdConnectUrl(securityScheme.openIdConnectUrl());
}
if (StringUtils.isNotBlank(securityScheme.scheme())) {
securitySchemeObject.setScheme(securityScheme.scheme());
}
if (StringUtils.isNotBlank(securityScheme.bearerFormat())) {
securitySchemeObject.setBearerFormat(securityScheme.bearerFormat());
}
if (StringUtils.isNotBlank(securityScheme.description())) {
securitySchemeObject.setDescription(securityScheme.description());
}
if (StringUtils.isNotBlank(securityScheme.paramName())) {
securitySchemeObject.setName(securityScheme.paramName());
}
if (StringUtils.isNotBlank(securityScheme.ref())) {
securitySchemeObject.set$ref(securityScheme.ref());
}
if (StringUtils.isNotBlank(securityScheme.name())) {
key = securityScheme.name();
}
if (securityScheme.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(securityScheme.extensions());
if (extensions != null) {
extensions.forEach(securitySchemeObject::addExtension);
}
}
getOAuthFlows(securityScheme.flows()).ifPresent(securitySchemeObject::setFlows);
SecuritySchemePair result = new SecuritySchemePair();
result.key = key;
result.securityScheme = securitySchemeObject;
return Optional.of(result);
}
Aggregations