All Projects → jakecoffman → crud

jakecoffman / crud

Licence: Apache-2.0 license
Swagger/OpenAPI builder and input validation for Go APIs

Programming Languages

go
31211 projects - #10 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to crud

Swiftgger
OpenAPI support for server side Swift projects.
Stars: ✭ 97 (+185.29%)
Mutual labels:  openapi, swagger-ui
Gradle Swagger Generator Plugin
Gradle plugin for OpenAPI YAML validation, code generation and API document publishing
Stars: ✭ 197 (+479.41%)
Mutual labels:  openapi, swagger-ui
Rapipdf
PDF generation from OpenAPI / Swagger Spec
Stars: ✭ 132 (+288.24%)
Mutual labels:  openapi, swagger-ui
Openapi Viewer
Browse and test a REST API described with the OpenAPI 3.0 Specification
Stars: ✭ 82 (+141.18%)
Mutual labels:  openapi, swagger-ui
OpenAPI-Viewer
OpenApi viewer Implemented using Vue
Stars: ✭ 93 (+173.53%)
Mutual labels:  openapi, swagger-ui
L5 Swagger
OpenApi or Swagger integration to Laravel
Stars: ✭ 1,781 (+5138.24%)
Mutual labels:  openapi, swagger-ui
Drf Yasg
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
Stars: ✭ 2,523 (+7320.59%)
Mutual labels:  openapi, swagger-ui
Uvicorn Gunicorn Fastapi Docker
Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 1,014 (+2882.35%)
Mutual labels:  openapi, swagger-ui
Django Rest Swagger
Swagger Documentation Generator for Django REST Framework: deprecated
Stars: ✭ 2,553 (+7408.82%)
Mutual labels:  openapi, swagger-ui
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+8208.82%)
Mutual labels:  openapi, swagger-ui
vim-swagger-preview
A Vim plugin for previewing swagger/openAPI spec in Chrome with swagger-ui.
Stars: ✭ 19 (-44.12%)
Mutual labels:  openapi, swagger-ui
cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (+41.18%)
Mutual labels:  openapi, swagger-ui
Springdoc Openapi
Library for OpenAPI 3 with spring-boot
Stars: ✭ 1,113 (+3173.53%)
Mutual labels:  openapi, swagger-ui
Angular Swagger Ui
An angularJS implementation of Swagger UI
Stars: ✭ 131 (+285.29%)
Mutual labels:  openapi, swagger-ui
Rswag
Seamlessly adds a Swagger to Rails-based API's
Stars: ✭ 1,028 (+2923.53%)
Mutual labels:  openapi, swagger-ui
Express Oas Generator
OpenAPI (Swagger) specification generator for ExpressJS applications
Stars: ✭ 138 (+305.88%)
Mutual labels:  openapi, swagger-ui
Django Ninja
💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
Stars: ✭ 875 (+2473.53%)
Mutual labels:  openapi, swagger-ui
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+116335.29%)
Mutual labels:  openapi, swagger-ui
Restrserve
R web API framework for building high-performance microservices and app backends
Stars: ✭ 207 (+508.82%)
Mutual labels:  openapi, swagger-ui
openapi-viewer
Browse and test a REST API described with the OpenAPI 3.0 Specification
Stars: ✭ 85 (+150%)
Mutual labels:  openapi, swagger-ui

crud

GoDoc Go

A Swagger/OpenAPI builder and validation library for building HTTP/REST APIs.

Heavily inspired by hapi and the hapi-swagger projects.

No additional dependencies besides the router you choose.

Status

Version 1.0 is stable, version 2 will support OpenAPI v3.

Why

Swagger is great, but up until now your options to use swagger are:

  1. Write it by hand and then make your server match your spec.
  2. Write it by hand and generate your server.
  3. Generate it from comments in your code.

None of these options seems like a great idea.

This project takes another approach: make a specification in Go code using nice builders where possible. The swagger is generated from this spec and validation is done before your handler gets called.

This reduces boilerplate that you have to write and gives you nice documentation too!

Examples

Builtin ServeMux not supported

This is disappointing, but the builtin http.ServeMux is not supported because it doesn't support routing by method, and doesn't support path params. This project is NOT a router so it will not try to reinvent these features.

Getting started

Check the example directory under the adapters for a simple example.

Start by getting the package go get github.com/jakecoffman/crud

Then in your main.go:

  1. Create a router with NewRouter, use an adapter from the adapters sub-package or write you own.
  2. Add routes with Add.
  3. Then call Serve.

Routes are specifications that look like this:

crud.Spec{
	Method:      "PATCH",
	Path:        "/widgets/{id}",
	PreHandlers: Auth,
	Handler:     CreateHandler,
	Description: "Adds a widget",
	Tags:        []string{"Widgets"},
	Validate: crud.Validate{
		Path: crud.Object(map[string]crud.Field{
			"id": crud.Number().Required().Description("ID of the widget"),
        	}),
		Body: crud.Object(map[string]crud.Field{
			"owner": crud.String().Required().Example("Bob").Description("Widget owner's name"),
			"quantity": crud.Integer().Min(1).Default(1).Description("The amount requested")
		}),
	},
}

This will add a route /widgets/:id that responds to the PATCH method. It generates swagger and serves it at the root of the web application. It validates that the ID in the path is a number, so you don't have to. It also validates that the body is an object and has an "owner" property that is a string, again so you won't have to.

It mounts the swagger-ui at / and loads up the generated swagger.json:

screenshot

The PreHandlers run before validation, and the Handler runs after validation is successful.

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