Step 3: Implement #4
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here we create a new class that will contain our implementations of the various API methods. This class will live alongside the existing
PetsApiDelegateclass in the demo project.Use Java 8
We use Java 8 features in our implementation, but the project is configured to Use Java 7.
Update
pom.xmlof the generated project:<java.version>1.8</java.version>.As
pom.xmlis now manually modified, to prevent overriding it with codegen, we need to add it to the.openapi-generator-ignorefile.Note: if you do not see

.openapi-geneator-ignorein your project, you need to disable the.* resourcesfilter here:After making these changes, right-click on the generated project and select
Maven -> Update project...to activate the change to Java 8.New
PetsApiDelegateImplClassFor simplicity, I am using a simple HashMap instead of a database.
Create this class, named
PetsApiDelegateImpl, alongside thePetsApiDelegategenerated class:You can use the usual "Organize Imports" feature after creating this file to add the necessary imports, after which you should see a clean build. (Choose
java.util.Listandcom.google.common.collect.Mapsfor those classes.)The result of step 3 is on branch
step_2b.Now, you can run the API locally using
mvn spring-boot:run. You can create a new pet and view it, you can also view all pets. To exercise the API, you can use a utility likecurlor open the service in Swagger-UI at http://localhost:8080 and use its Try It Out feature.