Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Mar 12, 2024
1 parent d9b8206 commit 8a57f6d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
*/
public class SpringDocSecurityOAuth2Customizer implements GlobalOpenApiCustomizer, ApplicationContextAware {

/**
* The constant REQUEST_MATCHER.
*/
private static final String REQUEST_MATCHER = "requestMatcher";

/**
* The constant LOGGER.
*/
Expand Down Expand Up @@ -170,7 +175,7 @@ private void getOAuth2AuthorizationServerMetadataEndpoint(OpenAPI openAPI, Secur
buildApiResponsesOnSuccess(apiResponses, AnnotationsUtils.resolveSchemaFromType(SpringDocOAuth2AuthorizationServerMetadata.class, openAPI.getComponents(), null, openapi31));
buildApiResponsesOnInternalServerError(apiResponses);
Operation operation = buildOperation(apiResponses);
buildPath(oAuth2EndpointFilter, "requestMatcher", openAPI, operation, HttpMethod.GET);
buildPath(oAuth2EndpointFilter, REQUEST_MATCHER, openAPI, operation, HttpMethod.GET);
}
}

Expand Down Expand Up @@ -198,7 +203,7 @@ private void getNimbusJwkSetEndpoint(OpenAPI openAPI, SecurityFilterChain securi

Operation operation = buildOperation(apiResponses);
operation.responses(apiResponses);
buildPath(oAuth2EndpointFilter, "requestMatcher", openAPI, operation, HttpMethod.GET);
buildPath(oAuth2EndpointFilter, REQUEST_MATCHER, openAPI, operation, HttpMethod.GET);
}
}

Expand Down Expand Up @@ -291,7 +296,7 @@ private void getOidcProviderConfigurationEndpoint(OpenAPI openAPI, SecurityFilte
buildApiResponsesOnSuccess(apiResponses, AnnotationsUtils.resolveSchemaFromType(SpringDocOidcProviderConfiguration.class, openAPI.getComponents(), null, openapi31));
buildApiResponsesOnInternalServerError(apiResponses);
Operation operation = buildOperation(apiResponses);
buildPath(oAuth2EndpointFilter, "requestMatcher", openAPI, operation, HttpMethod.GET);
buildPath(oAuth2EndpointFilter, REQUEST_MATCHER, openAPI, operation, HttpMethod.GET);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void setComponentsProperties(OpenAPI openApi) {
for (Schema componentSchema : components.getSchemas().values()) {
// set component description
String schemaPropertyPrefix = MessageFormat.format("components.schemas.{0}", componentSchema.getName());
resolveString(componentSchema::setDescription, schemaPropertyPrefix + ".description");
resolveString(componentSchema::setDescription, schemaPropertyPrefix + DESCRIPTION);
Map<String, Schema> properties = componentSchema.getProperties();

if (CollectionUtils.isEmpty(properties)) {
Expand All @@ -190,7 +190,7 @@ private void setComponentsProperties(OpenAPI openApi) {
String propertyNode = MessageFormat.format("components.schemas.{0}.properties.{1}",
componentSchema.getName(), propSchema.getName());

resolveString(propSchema::setDescription, propertyNode + ".description");
resolveString(propSchema::setDescription, propertyNode + DESCRIPTION);
resolveString(propSchema::setExample, propertyNode + ".example");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Builder {
/**
* The Content schem.
*/
private Schema contentSchem = org.springdoc.core.fn.builders.schema.Builder.schemaBuilder().build();
private Schema contentSchema = org.springdoc.core.fn.builders.schema.Builder.schemaBuilder().build();

/**
* The Property names.
Expand Down Expand Up @@ -285,7 +285,7 @@ public DependentSchema[] dependentSchemas() {

@Override
public Schema contentSchema() {
return contentSchem;
return contentSchema;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,18 @@ private List<HandlerMapping> getHandlerMappingList() {
private void findSearchResourceMappings(OpenAPI openAPI, List<RouterOperation> routerOperationList, List<HandlerMapping> handlerMappingList,
DataRestRepository dataRestRepository, ResourceMetadata resourceMetadata) {
for (HandlerMapping handlerMapping : handlerMappingList) {
if (handlerMapping instanceof RepositoryRestHandlerMapping) {
RepositoryRestHandlerMapping repositoryRestHandlerMapping = (RepositoryRestHandlerMapping) handlerMapping;
if (handlerMapping instanceof RepositoryRestHandlerMapping repositoryRestHandlerMapping) {
Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = repositoryRestHandlerMapping.getHandlerMethods();
Map<RequestMappingInfo, HandlerMethod> handlerMethodMapFiltered = handlerMethodMap.entrySet().stream()
.filter(requestMappingInfoHandlerMethodEntry -> REPOSITORY_SERACH_CONTROLLER.equals(requestMappingInfoHandlerMethodEntry
.getValue().getBeanType().getName()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1));
ResourceMetadata metadata = associations.getMetadataFor(dataRestRepository.getDomainType());
SearchResourceMappings searchResourceMappings = metadata.getSearchResourceMappings();
if (searchResourceMappings.isExported()) {
findSearchControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI, searchResourceMappings);
if(metadata!=null && metadata.isExported()) {
SearchResourceMappings searchResourceMappings = metadata.getSearchResourceMappings();
if (searchResourceMappings.isExported()) {
findSearchControllers(routerOperationList, handlerMethodMapFiltered, resourceMetadata, dataRestRepository, openAPI, searchResourceMappings);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,19 +767,21 @@ else if (methodParameter.getParameterAnnotation(org.springframework.web.bind.ann
private boolean checkOperationRequestBody(MethodParameter methodParameter) {
if (AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getMethod()), io.swagger.v3.oas.annotations.Operation.class) != null) {
io.swagger.v3.oas.annotations.Operation operation = AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getMethod()), io.swagger.v3.oas.annotations.Operation.class);
io.swagger.v3.oas.annotations.parameters.RequestBody requestBody = operation.requestBody();
if (StringUtils.isNotBlank(requestBody.description()))
return true;
else if (StringUtils.isNotBlank(requestBody.ref()))
return true;
else if (requestBody.required())
return true;
else if (requestBody.useParameterTypeSchema())
return true;
else if (requestBody.content().length > 0)
return true;
else
return requestBody.extensions().length > 0;
if(operation!=null){
io.swagger.v3.oas.annotations.parameters.RequestBody requestBody = operation.requestBody();
if (StringUtils.isNotBlank(requestBody.description()))
return true;
else if (StringUtils.isNotBlank(requestBody.ref()))
return true;
else if (requestBody.required())
return true;
else if (requestBody.useParameterTypeSchema())
return true;
else if (requestBody.content().length > 0)
return true;
else
return requestBody.extensions().length > 0;
}
}
return false;
}
Expand Down

0 comments on commit 8a57f6d

Please sign in to comment.