Many have written API’s and then genereated Swagger documentation based on the annotated code.
This is not what I am talking about. The idea is that you design the API you (your customer) will need, and describe it using Open API 3.0 Specification. Once your API is specified, you generate the interfaces and stubs to mock the endpoints and then implement them.
JHipster has provided a method for API-First development by integrating swagger-codegen into the project.
The quick version of the steps to API-First development with JHipster are:
src/main/resources/swagger/api.yml
./gradlew openApiGenerate
(or just start the project)${buildDirectory}/generated-sources/openapi/src/main/java/${package}/web/api/
@Service
classes which implement the generate interfaces looking something like:package com.my.api
...
@Service
public class MappingsApiImpl implements MappingsApiDelegate {
public ResponseEntity<APIMappedEntity> getMappings(String mappingType) {
...
return ResponseEntity.ok(apiMappedEntity);
}
}
The apiMappedEntity
Objects were also generated out of the OpenAPI specification of the response objects.
Once you generate the code, the APIs also show up in the JHipster generated Swagger Documentation.
If you made it this far, you may as well follow me: Follow @chfgrillofficer