Skip to content

Automatically validates API requests against an OpenAPI 3 spec.

License

Notifications You must be signed in to change notification settings

cdimascio/gin-openapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gin-openapi

Automatically validates API requests against an OpenAPI 3 spec.

Usage

package main

import (
	openapi "github.com/cdimascio/gin-openapi/pkg"
	"github.com/gin-gonic/gin"
)

func main() {
    router := gin.Default()
	
    // Add gin-openapi middleware 
    router.Use(openapi.ValidateRequests("spec.yml"))

    // Add routes
    router.POST("/v1/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{ "id": "pong" })
    })

    router.Run(":8080")
}

License MIT