cdimascio / openapi-spring-webflux-validator

🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Other
97 stars 13 forks source link

NoSuchMethodError ServerResponse.status(org.springframework.http.HttpStatus) #37

Closed pzienowicz closed 1 year ago

pzienowicz commented 1 year ago

Hi @cdimascio ! Please take a look into Validator class, in line 30 i 44 it uses status function from ServerResponse. In spring 6 there is no status(HttpStatus status) function, you need to use status(HttpStatusCode status) instead. Can you fix it?

Full error log: java.lang.NoSuchMethodError: 'org.springframework.web.reactive.function.server.ServerResponse$BodyBuilder org.springframework.web.reactive.function.server.ServerResponse.status(org.springframework.http.HttpStatus)'

cdimascio commented 1 year ago

Yes. It can be fixed. Can you post a PR with the proposed change. It will be super helpful

cdimascio commented 1 year ago

this should be fixed in 4.2.0. Note that no change to the code was required. I was mistakenly still building against spring 5 not 6.

pzienowicz commented 1 year ago

Sorry, but code change is required in this case. As I mentioned, in sprint 6 there is no status(HttpStatus status) function, please check documentation: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/function/server/ServerResponse.html

But code from Validator still uses this function that was existing in spring 5: https://docs.spring.io/spring-framework/docs/5.3.24/javadoc-api/org/springframework/web/reactive/function/server/ServerResponse.html

Do you have any tests that cover it?

cdimascio commented 1 year ago

There are multiple existing tests that test this code path Note that HttpStatus implements HttpStatusCode, hence it is still valid to pass an instance of HttpStatus as an arg

Here is a screenshot within debugger showing this code path as driven by one of the existing unit tests tests. As you can see, an HttpStatus is passed into the ServerResponse.status(HttpStatusCode status) method that you describe above successfully (no issue)

image
cdimascio commented 1 year ago

Have you tried v4.2.0. I suspect the issue you're encountering is due to the fact that v4.0 and v4.1 were (incorrectly) compiled against spring boot 2 instead of 3. 4.2.0 corrects that

pzienowicz commented 1 year ago

You are right, now all good, thanks!