All Projects → faabiosr → openapi-assert

faabiosr / openapi-assert

Licence: MIT License
Asserting data against OpenAPI docs.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to openapi-assert

kompendium
Ktor OpenAPI Spec Generator
Stars: ✭ 46 (+170.59%)
Mutual labels:  swagger, openapi
Api
The Up Banking API Specification
Stars: ✭ 248 (+1358.82%)
Mutual labels:  swagger, openapi
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+20182.35%)
Mutual labels:  swagger, openapi
Openapi Codegen
OpenAPI 3.0 CodeGen plus Node.js minus the Java and emojis
Stars: ✭ 224 (+1217.65%)
Mutual labels:  swagger, openapi
api
🚀 Automatic SDK generation from an OpenAPI definition
Stars: ✭ 127 (+647.06%)
Mutual labels:  swagger, openapi
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+16517.65%)
Mutual labels:  swagger, openapi
Full Stack Fastapi Couchbase
Full stack, modern web application generator. Using FastAPI, Couchbase as database, Docker, automatic HTTPS and more.
Stars: ✭ 243 (+1329.41%)
Mutual labels:  swagger, openapi
Redoc
📘 OpenAPI/Swagger-generated API Reference Documentation
Stars: ✭ 15,935 (+93635.29%)
Mutual labels:  swagger, openapi
fhir-fuel.github.io
Place to prepare proposal to FHIR about JSON, JSON-Schema, Swagger/OpenAPI, JSON native databases and other JSON-frendly formats (yaml, edn, avro, protobuf etc) and technologies
Stars: ✭ 20 (+17.65%)
Mutual labels:  swagger, openapi
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+16982.35%)
Mutual labels:  swagger, openapi
Openapi Comment Parser
⚓️ JSDoc Comments for the OpenAPI Specification
Stars: ✭ 221 (+1200%)
Mutual labels:  swagger, openapi
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (+105.88%)
Mutual labels:  swagger, openapi
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (+1170.59%)
Mutual labels:  swagger, openapi
Spot
Spot is a concise, developer-friendly way to describe your API contract.
Stars: ✭ 230 (+1252.94%)
Mutual labels:  swagger, openapi
Openapi Diff
Utility for comparing two OpenAPI specifications.
Stars: ✭ 208 (+1123.53%)
Mutual labels:  swagger, openapi
Grpc Swagger
Debugging gRPC application with swagger-ui.
Stars: ✭ 242 (+1323.53%)
Mutual labels:  swagger, openapi
Swaggerprovider
F# generative Type Provider for Swagger
Stars: ✭ 201 (+1082.35%)
Mutual labels:  swagger, openapi
Openapi Directory
🌐 Wikipedia for Web APIs. Directory of REST API definitions in OpenAPI 2.0/3.x format
Stars: ✭ 2,635 (+15400%)
Mutual labels:  swagger, openapi
Shins
Shins development continues at
Stars: ✭ 250 (+1370.59%)
Mutual labels:  swagger, openapi
shipengine-openapi
The official OpenAPI 3.0 definitions for ShipEngine™
Stars: ✭ 13 (-23.53%)
Mutual labels:  swagger, openapi

OpenAPI - Assert

Codecov branch GoDoc Go Report Card License

Description

openapi-assert is a Go package that provides a affordable way to validate http requests and responses data throught OpenAPI Schema Specification (Swagger) and the project was inspired by PHP Swagger Assertions. It has the following features:

  • Assert request and response media types
  • Assert request and response headers
  • Assert request query strings
  • Assert request and response body.
  • Assert the entire http request and response object.

Requirements

OpenAPI Assert requires Go 1.11 or later.

Instalation

Use go get.

$ go get github.com/faabiosr/openapi-assert

Then import the package into your own code:

import "github.com/faabiosr/openapi-assert"

Usage

The package provides methods that allow you to assert raw data using swagger files.

See it in action:

package main

import (
    assert "github.com/faabiosr/openapi-assert"
    "log"
    "net/http"
)

func main() {
    doc, err := assert.LoadFromURI("http://petstore.swagger.io/v2/swagger.json")

    if err != nil {
        log.Fatal(err)
    }

    assert := assert.New(doc)

    log.Println(
        assert.RequestMediaType("text/html", "/pet", http.MethodPost),
    )

    log.Println(
        assert.RequestMediaType("image/gif", "/v2/pet", http.MethodPost),
    )
}

Asserting http request object using the swagger schema file:

package main

import (
	"fmt"
	assert "github.com/faabiosr/openapi-assert"
	"log"
	"net/http"
)

func main() {
	doc, err := assert.LoadFromURI("http://petstore.swagger.io/v2/swagger.json")

	if err != nil {
		log.Fatal(err)
	}

	assert := assert.New(doc)

	http.HandleFunc("/v2/pet", func(w http.ResponseWriter, r *http.Request) {
		err := assert.Request(r)

		fmt.Fprint(w, err)
	})

	log.Fatal(
		http.ListenAndServe("127.0.0.1:9000", nil),
	)
}

Asserting http response object using the swagger schema file:

package main

import (
	assert "github.com/faabiosr/openapi-assert"
	"log"
	"net/http"
)

func main() {
	doc, err := assert.LoadFromURI("http://petstore.swagger.io/v2/swagger.json")

	if err != nil {
		log.Fatal(err)
	}

	assert := assert.New(doc)

	res, err := http.Get("https://petstore.swagger.io/v2/pet/111111422")

	if err != nil {
		log.Fatal(err)
	}

	log.Println(assert.Response(res))
}

Examples

Development

Requirements

Makefile

# Clean up
$ make clean

# Download project dependencies
$ make configure

# Run tests and generates html coverage file
$ make cover

# Format all go files
$ make fmt

# GolangCI-Lint
$ make lint

# Run tests
$make test

License

This project is released under the MIT licence. See LICENSE for more details.

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].