Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peltoche/oaichecker
Test your OpenAPI specs and your server API at the same time
https://github.com/peltoche/oaichecker
openapi openapi-validation swagger swagger-validator
Last synced: about 1 month ago
JSON representation
Test your OpenAPI specs and your server API at the same time
- Host: GitHub
- URL: https://github.com/peltoche/oaichecker
- Owner: Peltoche
- License: apache-2.0
- Created: 2018-09-30T10:08:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-13T13:54:40.000Z (about 6 years ago)
- Last Synced: 2024-06-20T06:42:58.438Z (5 months ago)
- Topics: openapi, openapi-validation, swagger, swagger-validator
- Language: Go
- Homepage:
- Size: 93.8 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/Peltoche/oaichecker/master/LICENSE)
[![Build Status](https://travis-ci.org/Peltoche/oaichecker.svg?branch=master)](https://travis-ci.org/Peltoche/oaichecker)
[![GoDoc](https://godoc.org/github.com/Peltoche/oaichecker?status.svg)](http://godoc.org/github.com/Peltoche/oaichecker)
[![codecov](https://codecov.io/gh/Peltoche/oaichecker/branch/master/graph/badge.svg)](https://codecov.io/gh/Peltoche/oaichecker)
[![GolangCI](https://golangci.com/badges/github.com/Peltoche/oaichecker.svg)](https://golangci.com)
[![Go Report Card](https://goreportcard.com/badge/github.com/Peltoche/oaichecker)](https://goreportcard.com/report/github.com/Peltoche/oaichecker)# OpenAPI Checker
Run you server tests and at the same time check if you tests match with you OpenAPI specs.
## Why?
As a developper I often forget to change the specs after a server modification and
so my API documentation is always deprecated after 2 commits. In order to fix that
I have written a little lib which takes you tests HTTP request/responses an
matches them against your API specs. If you request doesn't matchs the specs,
you request will fail and so you test also fail.## How?
This lib permits you to generate an http.RoundTripper which can be easily
integrated inside you http.Client from you already existing tests.## Example
```go
import (
"github.com/stretchr/testify/assert"
"github.com/Peltoche/oaichecker"
)var client http.Client
func init() {
// Loads the specs file.
//
// It contains only a the specs for the endpoint 'GET /pets'.
specs, err := oaichecker.NewSpecsFromFile("./dataset/petstore_minimal.json")
if err != nil {
panic(err)
}// Create a client which the custom transport
client = http.Client{
Transport: oaichecker.NewTransport(specs),
}
}func Test_Posting_a_valid_pet(t *testing.T) {
// Make the requests as usual.
//
// In this case the request is valid but the specs are not followed because
// the endpoint 'POST /v2/pet' is not defined inside the specs, only 'GET /pets'.
_, err := client.Post("http://petstore.swagger.io/v2/pet", "application/json", strings.NewReader(`{
"name": "doggie",
"photoUrls": ["some-url"]}`))// This assert should success but as the specs are not followed, `req` is
// nil and `err` contains the following message:
//
// "Post http://petstore.swagger.io/v2/pet: operation not defined inside the specs"
assert.NoError(t, err)
}
```