diff --git a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java index be60e5f8af..fb683de4ea 100644 --- a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java +++ b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java @@ -165,7 +165,7 @@ public OpenAPI read(Set> 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); } @@ -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 } @@ -348,7 +346,7 @@ public OpenAPI read(Class cls, Map 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); @@ -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 encoding = new LinkedHashMap<>(); for (Parameter formParam: formParameters) { if (formParam.getExplode() != null || (formParam.getStyle() != null) && Encoding.StyleEnum.fromString(formParam.getStyle().toString()) != null) { @@ -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())) { @@ -730,10 +728,10 @@ protected void applyPathParamsPatterns(Operation operation, Map .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(); } @@ -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 content = Arrays.stream(requestBodyAnnotation.content()).filter(c -> c.mediaType().equals(key)).findFirst(); if (content.isPresent()) { Optional reResolvedSchema = AnnotationsUtils.getSchemaFromAnnotation(content.get().schema(), components, null, config.isOpenAPI31(), parameterSchema); @@ -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); @@ -1016,7 +1014,7 @@ protected Operation parseMethod( callbacks.putAll(currentCallbacks); } } - if (callbacks.size() > 0) { + if (!callbacks.isEmpty()) { operation.setCallbacks(callbacks); } @@ -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); @@ -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) { @@ -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 content = Arrays.stream(response.content()).filter(c -> c.mediaType().equals(key)).findFirst(); if (content.isPresent()) { Optional reResolvedSchema = AnnotationsUtils.getSchemaFromAnnotation(content.get().schema(), components, null, config.isOpenAPI31(), existingSchema); @@ -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; } @@ -1627,7 +1626,7 @@ 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; } @@ -1635,7 +1634,7 @@ protected boolean ignoreOperationPathStrict(String path, String parentPath) { 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; }