Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution of "Extend BookRestController" doesn't comply with OpenAPI Spec #74

Open
rweisleder opened this issue Aug 8, 2023 · 2 comments
Labels
improvement refactoring task Anything related to course tasks

Comments

@rweisleder
Copy link

With task "Extend BookRestController", the attendees are supposed to add a new mapping, so that the following mappings are present in the BookRestController afterwards:

@GetMapping
public List<Book> getAllBooks() {
    // ...
}

@GetMapping("/{isbn}")
public Book getSingleBook(@PathVariable String isbn) throws Exception {
    // ...
}

@GetMapping(params = "author")
public Book searchBookByAuthor(@RequestParam String author) throws Exception {
    // ...
}

This means that for GET requests with path "/book" there are 2 mappings available now. For Spring this is not a problem. But if we add Springdoc/Swagger later, it gives a weird result:
image

For "GET /book" we have only one operation where the query parameter author is required and which returns only one Book object. The operation getAllBooks returning multiple books does not appear anymore. (Attendees also ask every time why searchBookByAuthor returns only one book and not multiple.)

From my point of view, our BookRestController is no longer OpenAPI conform, because there only one operation may be defined per path and method, see Specification. I suggest to move searchBookByAuthor to another path.

@BjoernKW BjoernKW added improvement task Anything related to course tasks refactoring labels Aug 8, 2023
@BjoernKW
Copy link
Collaborator

BjoernKW commented Aug 8, 2023

Yes, this is correct. BookRestController doesn't comply withe the OpenAPI specification. However, adding another path probably would make the code more complex.

Could you maybe provide a pull request implementing the structure you have in mind?

@bkratz
Copy link
Collaborator

bkratz commented Aug 12, 2023

Ich antworte einfach mal in Deutsch 😄
Die "billigste" Lösung wäre wahrscheinlich, @RequestParam(required=false) zu verwenden. Dann darf man aber auch keine Validatoren wie @NotNull oder @notblank verwenden.

@BjoernKW BjoernKW changed the title Solution of "Extend BookRestController" not conform to OpenAPI Spec Solution of "Extend BookRestController" doesn't comply with OpenAPI Spec Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement refactoring task Anything related to course tasks
Projects
None yet
Development

No branches or pull requests

3 participants