Generating Code with OpenAPI
In this chapter, we will start the development of a completely new API called Order Management that will interact with the Product API developed in Chapter 2 and evolved in Chapter 3.
In the previous chapter, the Product API was developed following the code-first approach, wherein the API was implemented before the documentation.
In this chapter, we will adopt a specification-first approach, also known as API-first, wherein we will have the specification of the whole API done first, and then have the API implemented.
Firstly, we will build the OpenAPI specification for the Order Management API, declaring the paths, methods, and request and response schemas (some of them using polymorphism) for it.
Then, we will use OpenAPI tools to generate Java code stubs from the API specification. This generated code speeds up the implementation process, reduces manual maintenance of boilerplate code, and, most importantly, makes it easier to maintain...