项目作者: kapilratnani

项目描述 :
Spring boot sample app with API first approach
高级语言: Java
项目地址: git://github.com/kapilratnani/todoapp.git
创建时间: 2019-10-21T07:22:01Z
项目社区:https://github.com/kapilratnani/todoapp

开源协议:

下载


todoapp

Spring boot sample app with API first approach. Integrates Open API Generator to generate API interfaces and Domain models.

Project Structure

Gradle Multimodule project. All directories at level 1 are gradle modules.

  1. .
  2. ├── api // controllers
  3. └── src
  4. ├── main
  5. ├── java
  6. ├── resources
  7. └── spec // openAPI spec. here
  8. └── test
  9. ├── java
  10. └── resources
  11. ├── app
  12. └── src
  13. ├── main
  14. ├── java
  15. └── resources
  16. └── test
  17. ├── java
  18. └── resources
  19. ├── config
  20. └── src
  21. ├── main
  22. ├── java
  23. └── resources
  24. └── test
  25. ├── java
  26. └── resources
  27. ├── dao
  28. └── src
  29. ├── main
  30. ├── java
  31. └── resources
  32. └── test
  33. ├── java
  34. └── resources
  35. ├── entities
  36. └── src
  37. ├── main
  38. ├── java
  39. └── resources
  40. └── test
  41. ├── java
  42. └── resources
  43. └── service // bussiness logic
  44. └── src
  45. ├── main
  46. ├── java
  47. └── resources
  48. └── test
  49. ├── java
  50. └── resources

OpenAPI Generator

  • OpenAPI generator gradle plugin is integrated in :api gradle module
  • Edit Open API spec in :api/src/main/spec folder and execute codegen gradle task
  • Interfaces and models are generated at :api/build/src/main/java
  • Open API spec is written for two APIs, Todo Entries and Users in separate yaml files. Models are shared between the two APIs.
  • Two separate gradle tasks exists to generate the Todo (generateTodoApi) and User (generateUserApi) APIs.
  • The above tasks are combined using a single codegen task.

Swagger Setup

  • Swagger UI is available at http://localhost:8083/swagger-ui.html, via `io.springfox:springfox-swagger-ui’
  • Swagger API docs at http://localhost:8083/v2/api-docs
  • Swagger Docket config and API info is configured at net.ripper.todoapp.api.config.SwaggerConfigurer
  • Tags are used to group APIs. an additional `@Api(tags=aTag)’ is needed on the Controller implementation for correct grouping.

Flyway DB Migrations

  • Install Flyway cli from http://flywaydb.org
  • Change directory to :db and run flyway -configFiles=flyway-{env}.conf migrate to apply migrations in :db\sql folder
  • Refer flyway documentation on how to create new migrations.

Jacoco and Sonar

  • Use start-sonar.sh script to start a local sonar instance at port 9001
  • Add systemProp.sonar.host.url=http://localhost:9001 to ~/.gradle/gradle.properties
  • Run gradle task test followed by sonarqube
  • Open sonar UI running at http://localhost:9001 to see code quality results

JsonNullable and Hibernate Validator

  • Nullable fields in OpenAPI schema are wrapped in JsonNullable
  • Fields in JSON can be in 3 states
    • Absent (i.e. missing in the request)
    • Present
    • Null (i.e. {“a”:null})
      In case of PATCH request the Absent field is supposed to retain the current value. Present or explicit Null should update the value.
  • Serialization/Deserialization of JsonNullable, Jackson ObjectMapper is configured in net.ripper.todoapp.api.config.JacksonObjectMapperConfigurer
  • Hibernate needs a custom ValueExtractor to extract values and apply constraints. It is configured in net.ripper.todoapp.api.config.ValidationConfigurer

Todo

  • [X] JWT security
  • Unit Tests and Integration tests separation
  • Custom spring templates for OpenAPI generator
  • Config module implementation
  • Complete Docker config
  • Add Caching
  • [X] Integrate Jacoco or sonar for code quality reports
  • [X] Git hooks to format code before code