Code Monkey home page Code Monkey logo

todoapp's Introduction

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.

.
├── api  // controllers
│   └── src
│       ├── main
│       │   ├── java
│       │   ├── resources
│       │   └── spec // openAPI spec. here
│       └── test
│           ├── java
│           └── resources
├── app
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           ├── java
│           └── resources
├── config
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           ├── java
│           └── resources
├── dao
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           ├── java
│           └── resources
├── entities
│   └── src
│       ├── main
│       │   ├── java
│       │   └── resources
│       └── test
│           ├── java
│           └── resources
└── service  // bussiness logic
    └── src
        ├── main
        │   ├── java
        │   └── resources
        └── test
            ├── java
            └── 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

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

todoapp's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.