Integration created

How to use OpenAPI first approach


OpenAPI first approach consists of the following steps:

Create OpenAPI specification

OpenAPI specification is a file that describes your API. It is a contract between your API and your clients. It is a good practice to create OpenAPI specification before you start implementing your API. It will help you to understand what your API should do and how it should look like. It will also help you to understand what your clients expect from your API. You can use Swagger Editor to create OpenAPI specification.

For example, let’s create an OpenAPI specification for a simple API that returns credit card types.

        - Common
      summary: Get credit card types
      description: Get credit card types
      operationId: getCreditCardTypes
          description: OK
                type: array
                  $ref: '#/components/schemas/ValueLabel'

This specification describes an endpoint that returns credit card types. It returns an array of ValueLabel objects. ValueLabel object has two properties: value and label.

Generate server stubs

Server stubs are generated thanks to pom.xml file. You can find pom.xml file in the root of the project. It contains the following plugin:


This plugin generates server stubs. It generates interfaces for controllers and models DTO (Data Transfer Objects). You can find generated files in the src/main/java/co/icreated/portal/api folder.

That’s it. You have created OpenAPI specification and generated server stubs. Now you can implement business logic by implementing generated interfaces.

Implement business logic

You can implement business logic by implementing generated interfaces. For example, let’s implement getCreditCardTypes method.

  public ResponseEntity<List<ValueLabelDto>> getCreditCardTypes() {
    List<ValueLabelDto> creditCardTypes = new ArrayList<>();
    creditCardTypes.add(new ValueLabelDto("VISA", "VISA"));
    creditCardTypes.add(new ValueLabelDto("MASTERCARD", "MASTERCARD"));
    creditCardTypes.add(new ValueLabelDto("AMEX", "AMEX"));
    return ResponseEntity.ok(creditCardTypes);