All Projects → codecentric → Hikaku

codecentric / Hikaku

Licence: apache-2.0
A library that tests if the implementation of a REST-API meets its specification.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Hikaku

Gemini
Model Driven REST framework to automatically generate CRUD APIs
Stars: ✭ 138 (-10.39%)
Mutual labels:  rest-api, rest, openapi, spring, spring-mvc
Proteus
Lean, mean, and incredibly fast JVM framework for web and microservice development.
Stars: ✭ 178 (+15.58%)
Mutual labels:  rest-api, rest, openapi, restful-api, jax-rs
Spring Petclinic Rest
REST version of the Spring Petclinic sample application
Stars: ✭ 257 (+66.88%)
Mutual labels:  rest-api, rest, spring, spring-mvc
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+6805.19%)
Mutual labels:  rest-api, rest, openapi, restful-api
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+212.99%)
Mutual labels:  rest-api, rest, restful-api, spring
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (-1.95%)
Mutual labels:  rest-api, openapi, restful-api
Codeigniter Jwt Sample
CodeIgniter JWT Sample
Stars: ✭ 144 (-6.49%)
Mutual labels:  rest-api, rest, restful-api
Openapi Spring Webflux Validator
🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Stars: ✭ 67 (-56.49%)
Mutual labels:  rest, openapi, spring
Appkernel
API development made easy: a smart Python 3 API framework
Stars: ✭ 152 (-1.3%)
Mutual labels:  rest-api, rest, restful-api
Dropwizard
A damn simple library for building production-ready RESTful web services.
Stars: ✭ 8,078 (+5145.45%)
Mutual labels:  rest, jax-rs, dropwizard
Restfm
RESTful web services for FileMaker server.
Stars: ✭ 76 (-50.65%)
Mutual labels:  rest-api, rest, restful-api
Automatic Api
A list of software that turns your database into a REST/GraphQL API
Stars: ✭ 1,583 (+927.92%)
Mutual labels:  rest-api, rest, restful-api
Javadevjournal
Source code for the tutorials published on the Javadevjournal site.
Stars: ✭ 141 (-8.44%)
Mutual labels:  rest-api, rest, spring-mvc
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-63.64%)
Mutual labels:  rest-api, rest, restful-api
Calm
It is always Calm before a Tornado!
Stars: ✭ 50 (-67.53%)
Mutual labels:  rest-api, rest, restful-api
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-45.45%)
Mutual labels:  rest-api, rest, restful-api
Sandman2
Automatically generate a RESTful API service for your legacy database. No code required!
Stars: ✭ 1,765 (+1046.1%)
Mutual labels:  rest-api, rest, restful-api
Jersey Jwt
Example of REST API with JWT authentication using Jersey, Jackson, Undertow, Weld, Hibernate and Arquillian.
Stars: ✭ 131 (-14.94%)
Mutual labels:  rest-api, rest, jax-rs
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-5.19%)
Mutual labels:  rest-api, rest, restful-api
Swagger Core
Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
Stars: ✭ 6,898 (+4379.22%)
Mutual labels:  rest-api, rest, openapi

hikaku

Build Status Maven Central Version

Hikaku (比較) is japanese and means "comparison". This library tests if a REST-API implementation meets its specification.

If you create your REST-API contract-first without using any type of generation, you have to make sure that specification and implementation don't diverge. The aim of this project is to meet this need and offer a mechanism to check specification and implementation for equality without having to create requests which are fired against a mock server. So this library won't check the behavior of the API, but the structural correctness. Please see also the section limitations

Currently supported

Please refer to the list of all features. To check the feature support for each converter. It is possible that not every converter supports every feature. Only the intersection of the features of two EndpointConverters is used for the matching. Please keep that in mind regarding the equality of implementation and specification.

Usage

Setting up a test with hikaku is very simple. You just instantiate the Hikaku class and provide an EndpointConverter for the specification and another one for the implementation. Optionally, you can also pass an instance of HikakuConfig. Check the list of options and default values of the config. Then you call match() on the Hikaku class. The match result is sent to one or multiple Reporter. If the test fails kotlin's DefaultAsserter.fail() method is called.

Example

There is an artifact for each converter. So we need one dependency for the specification and one for the implementation. In this example our project consists of an OpenAPI specification and a Spring implementation. The specification does not contain the /error endpoints created by spring, so we want to omit those. First add the dependencies for the converters, that we want to use. In this case hikaku-openapi and hikaku-spring.

dependencies {
    testImplementation "de.codecentric.hikaku:hikaku-openapi:$hikakuVersion"
    testImplementation "de.codecentric.hikaku:hikaku-spring:$hikakuVersion"
}

Kotlin

And now we can create the test case:

@SpringBootTest
class SpecificationTest {

    @Autowired
    private lateinit var springContext: ApplicationContext

    @Test
    fun `specification matches implementation`() {
        Hikaku(
                specification = OpenApiConverter(Paths.get("openapi.yaml")),
                implementation = SpringConverter(springContext),
                config = HikakuConfig(
                        filters = listOf(SpringConverter.IGNORE_ERROR_ENDPOINT)
                )
        )
        .match()
    }
}

Java

Same example in Java:

@SpringBootTest
public class SpecificationTest {

  @Autowired
  private ApplicationContext springContext;

  @Test
  public void specification_matches_implementation() {
    List<Function1<Endpoint, Boolean>> filters = new ArrayList<>();
    filters.add(SpringConverter.IGNORE_ERROR_ENDPOINT);

    List<Reporter> reporters = new ArrayList<>();
    reporters.add(new CommandLineReporter());

    new Hikaku(
            new OpenApiConverter(Paths.get("openapi.json")),
            new SpringConverter(springContext),
            new HikakuConfig(
                    reporters,
                    filters
            )
    )
    .match();
  }
}

Limitations

Hikaku checks the implementation with static code analysis. So everything that is highly dynamic is not covered by hikaku. There might be other libraries and frameworks that can cover these aspects by checking the behavior.

http status codes

For implementations the status codes are very dynamic. There are various ways to set a http status. For example using a ResponseEntity object in spring or using additional filters and so on. That's why hikaku does not support http status codes.

Request and response object

For implementations both request and response objects are highly dynamic. For response objects there might be a generic ResponseEntity as well or interfaces with different implementations can be used. In both cases (request and response) the objects can be altered by a serialization library and there a lot of different libs out there. That's why hikaku neither supports request nor response objects.

More Info

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].