GithubHelp home page GithubHelp logo

koriit / openapi-matcher Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 149 KB

OpenApi matcher for kotlin, allows to compare 2 specifications against each other.

License: MIT License

Kotlin 100.00%
kotlin validation openapi3 openapi-validation

openapi-matcher's Introduction

OpenAPI Matcher

Build CodeFactor ktlint

Maven Central Kotlin GitHub

Warning
From version 0.7.0 all package names have been renamed to match new artifact group id.

OpenAPI matcher for Kotlin allows comparing 2 specifications against each other.

Warning
This library in Work In Progress. It doesn’t support all elements of OpenAPI specification yet. The support scope can be checked individually for every OpenAPI specification object in the korrit.kotlin.openapi.model package.

Reading OpenAPI

This library includes an OpenAPI reader that allows parsing your OpenAPI specification in YAML format into an in-memory object that can be used in a matcher.

val doc: OpenAPI = OpenAPIReader().load({}.javaClass.getResourceAsStream("/openapi.yaml"))
Note
Unsupported elements are ignored.

Validating OpenAPI

Once you have 2 OpenAPI objects you can match them checking for any significant differences.

A significant difference is understood as a divergence that leads to or may lead to a compatibility break.

The general idea is to validate your OpenAPI specification against your code instead of spec/code generation.

val source: OpenAPI = ... // Analyze your code

LOG.info("Reading OpenAPI spec...")
val doc: OpenAPI = OpenAPIReader().load({}.javaClass.getResourceAsStream("/openapi.yaml"))

LOG.info("Validating spec...")
val errors = OpenAPIMatcher().match(doc, source)

if (errors.isNotEmpty()) {
    LOG.info("Result of code analysis:\n{}", source)

    errors.forEach {
        LOG.error(it)
    }

    fail("There are ${errors.size} validation errors!")
} else {
    LOG.info("OK!")
}

openapi-matcher's People

Contributors

koriit avatar

Watchers

 avatar  avatar

openapi-matcher's Issues

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.