Skip to content

Commit

Permalink
fix: compare string using equals instead of ==
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn authored and frantuma committed Sep 21, 2023
1 parent f8c7eb0 commit 9048843
Showing 1 changed file with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public OpenAPI read(Set<Class<?>> classes) {
for (Class<?> cls : sortedClasses) {
if (ReaderListener.class.isAssignableFrom(cls) && !listeners.containsKey(cls)) {
try {
listeners.put(cls, (ReaderListener) cls.newInstance());
listeners.put(cls, (ReaderListener) cls.getDeclaredConstructor().newInstance());
} catch (Exception e) {
LOGGER.error("Failed to create ReaderListener", e);
}
Expand Down Expand Up @@ -259,8 +259,6 @@ protected String resolveApplicationPath() {
}
m = innerApp.getClass().getMethod("getApplication");
}
} catch (NoSuchMethodException e) {
// no inner application found
} catch (Exception e) {
// no inner application found
}
Expand Down Expand Up @@ -348,7 +346,7 @@ public OpenAPI read(Class<?> cls,
Map<String, SecurityScheme> securitySchemeMap = new HashMap<>();
if (StringUtils.isNotBlank(securityScheme.get().key)) {
securitySchemeMap.put(securityScheme.get().key, securityScheme.get().securityScheme);
if (components.getSecuritySchemes() != null && components.getSecuritySchemes().size() != 0) {
if (components.getSecuritySchemes() != null && !components.getSecuritySchemes().isEmpty()) {
components.getSecuritySchemes().putAll(securitySchemeMap);
} else {
components.setSecuritySchemes(securitySchemeMap);
Expand Down Expand Up @@ -584,7 +582,7 @@ public OpenAPI read(Class<?> cls,
}
// if we have form parameters, need to merge them into single schema and use as request body..
if (!formParameters.isEmpty()) {
Schema mergedSchema = new ObjectSchema();
Schema<?> mergedSchema = new ObjectSchema();
Map<String, Encoding> encoding = new LinkedHashMap<>();
for (Parameter formParam: formParameters) {
if (formParam.getExplode() != null || (formParam.getStyle() != null) && Encoding.StyleEnum.fromString(formParam.getStyle().toString()) != null) {
Expand All @@ -597,7 +595,7 @@ public OpenAPI read(Class<?> cls,
}
encoding.put(formParam.getName(), e);
}
mergedSchema.addProperties(formParam.getName(), formParam.getSchema());
mergedSchema.addProperty(formParam.getName(), formParam.getSchema());
if (formParam.getSchema() != null &&
StringUtils.isNotBlank(formParam.getDescription()) &&
StringUtils.isBlank(formParam.getSchema().getDescription())) {
Expand Down Expand Up @@ -730,10 +728,10 @@ protected void applyPathParamsPatterns(Operation operation, Map<String, String>
.filter(p -> p.getSchema() != null)
.filter(p -> StringUtils.isBlank(p.getSchema().getPattern()))
.filter(p -> !Parameter.StyleEnum.MATRIX.equals(p.getStyle()))
.filter(p -> "string" == p.getSchema().getType() || (p.getSchema().getTypes() != null && p.getSchema().getTypes().contains("string")))
.filter(p -> "string".equals(p.getSchema().getType()) || (p.getSchema().getTypes() != null && p.getSchema().getTypes().contains("string")))
.forEach(p -> p.getSchema().setPattern(patternsMap.get(p.getName())));
}
protected Content processContent(Content content, Schema schema, Consumes methodConsumes, Consumes classConsumes) {
protected Content processContent(Content content, Schema<?> schema, Consumes methodConsumes, Consumes classConsumes) {
if (content == null) {
content = new Content();
}
Expand Down Expand Up @@ -785,7 +783,7 @@ protected void processRequestBody(Parameter requestBodyParameter, Operation oper
} else if (mediaType.getSchema() != null && requestBodyAnnotation.useParameterTypeSchema()) {
if (requestBodyParameter.getSchema() != null) {
MediaType newMediaType = clone(mediaType);
Schema parameterSchema = clone(requestBodyParameter.getSchema());
Schema<?> parameterSchema = clone(requestBodyParameter.getSchema());
Optional<io.swagger.v3.oas.annotations.media.Content> content = Arrays.stream(requestBodyAnnotation.content()).filter(c -> c.mediaType().equals(key)).findFirst();
if (content.isPresent()) {
Optional<Schema> reResolvedSchema = AnnotationsUtils.getSchemaFromAnnotation(content.get().schema(), components, null, config.isOpenAPI31(), parameterSchema);
Expand Down Expand Up @@ -863,7 +861,7 @@ private io.swagger.v3.oas.annotations.parameters.RequestBody getRequestBody(List
return null;
}

private void setMediaTypeToContent(Schema schema, Content content, String value) {
private void setMediaTypeToContent(Schema<?> schema, Content content, String value) {
MediaType mediaTypeObject = new MediaType();
mediaTypeObject.setSchema(schema);
content.addMediaType(value, mediaTypeObject);
Expand Down Expand Up @@ -1016,7 +1014,7 @@ protected Operation parseMethod(
callbacks.putAll(currentCallbacks);
}
}
if (callbacks.size() > 0) {
if (!callbacks.isEmpty()) {
operation.setCallbacks(callbacks);
}

Expand Down Expand Up @@ -1202,7 +1200,8 @@ protected Operation parseMethod(
if (apiResponses != null) {
resolveResponseSchemaFromReturnType(
operation,
apiResponses.stream().toArray(io.swagger.v3.oas.annotations.responses.ApiResponse[]::new),
apiResponses.toArray(
new io.swagger.v3.oas.annotations.responses.ApiResponse[0]),
returnTypeSchema,
classProduces,
methodProduces);
Expand Down Expand Up @@ -1250,14 +1249,14 @@ private MediaType clone(MediaType mediaType) {
}
return mediaType;
}
private Schema clone(Schema schema) {
private Schema<?> clone(Schema<?> schema) {
return AnnotationsUtils.clone(schema, config.isOpenAPI31());
}

protected void resolveResponseSchemaFromReturnType(
Operation operation,
io.swagger.v3.oas.annotations.responses.ApiResponse[] responses,
Schema schema,
Schema<?> schema,
Produces classProduces, Produces methodProduces) {
if (responses != null) {
for (io.swagger.v3.oas.annotations.responses.ApiResponse response: responses) {
Expand All @@ -1268,7 +1267,7 @@ protected void resolveResponseSchemaFromReturnType(
if (opResponse.getContent() != null) {
for (String key : opResponse.getContent().keySet()) {
MediaType mediaType = clone(opResponse.getContent().get(key));
Schema existingSchema = clone(schema);
Schema<?> existingSchema = clone(schema);
Optional<io.swagger.v3.oas.annotations.media.Content> content = Arrays.stream(response.content()).filter(c -> c.mediaType().equals(key)).findFirst();
if (content.isPresent()) {
Optional<Schema> reResolvedSchema = AnnotationsUtils.getSchemaFromAnnotation(content.get().schema(), components, null, config.isOpenAPI31(), existingSchema);
Expand Down Expand Up @@ -1550,37 +1549,37 @@ private boolean isEmptyComponents(Components components) {
if (components == null) {
return true;
}
if (components.getSchemas() != null && components.getSchemas().size() > 0) {
if (components.getSchemas() != null && !components.getSchemas().isEmpty()) {
return false;
}
if (components.getSecuritySchemes() != null && components.getSecuritySchemes().size() > 0) {
if (components.getSecuritySchemes() != null && !components.getSecuritySchemes().isEmpty()) {
return false;
}
if (components.getCallbacks() != null && components.getCallbacks().size() > 0) {
if (components.getCallbacks() != null && !components.getCallbacks().isEmpty()) {
return false;
}
if (components.getExamples() != null && components.getExamples().size() > 0) {
if (components.getExamples() != null && !components.getExamples().isEmpty()) {
return false;
}
if (components.getExtensions() != null && components.getExtensions().size() > 0) {
if (components.getExtensions() != null && !components.getExtensions().isEmpty()) {
return false;
}
if (components.getHeaders() != null && components.getHeaders().size() > 0) {
if (components.getHeaders() != null && !components.getHeaders().isEmpty()) {
return false;
}
if (components.getLinks() != null && components.getLinks().size() > 0) {
if (components.getLinks() != null && !components.getLinks().isEmpty()) {
return false;
}
if (components.getParameters() != null && components.getParameters().size() > 0) {
if (components.getParameters() != null && !components.getParameters().isEmpty()) {
return false;
}
if (components.getRequestBodies() != null && components.getRequestBodies().size() > 0) {
if (components.getRequestBodies() != null && !components.getRequestBodies().isEmpty()) {
return false;
}
if (components.getResponses() != null && components.getResponses().size() > 0) {
if (components.getResponses() != null && !components.getResponses().isEmpty()) {
return false;
}
if (components.getPathItems() != null && components.getPathItems().size() > 0) {
if (components.getPathItems() != null && !components.getPathItems().isEmpty()) {
return false;
}

Expand Down Expand Up @@ -1627,15 +1626,15 @@ protected boolean ignoreOperationPathStrict(String path, String parentPath) {
} else if (StringUtils.isBlank(path) && StringUtils.isNotBlank(parentPath)) {
return false;
}
if (parentPath != null && !"".equals(parentPath) && !"/".equals(parentPath)) {
if (parentPath != null && !parentPath.isEmpty() && !"/".equals(parentPath)) {
if (!parentPath.startsWith("/")) {
parentPath = "/" + parentPath;
}
if (parentPath.endsWith("/")) {
parentPath = parentPath.substring(0, parentPath.length() - 1);
}
}
if (path != null && !"".equals(path) && !"/".equals(path)) {
if (path != null && !path.isEmpty() && !"/".equals(path)) {
if (!path.startsWith("/")) {
path = "/" + path;
}
Expand Down

0 comments on commit 9048843

Please sign in to comment.