openape

package module
v0.0.0-...-990120d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2018 License: GPL-3.0 Imports: 9 Imported by: 1

README

OpenAPE

Build Status Go Report Card GoDoc

OpenAPE is designed to be a server extension of the OpenAPI specification, reading in a Swagger file and a config and OpenAPE will do all the code monkey stuff for you: building the routes, adding the models to a database, validation etc.

Much of web development consists of creating and maintaining an API that is marginally different from the last one? Swagger and OpenAPI has made this much easier with code generation tools and frameworks such as Loopback. Almost all models created require the basic HTTP verbs and supported actions (PUT, DELETE etc) but most existing tools only generate method stubs still requiring addition code from developers this aims to solve that.


Contributing

PRs are welcome, this is a super early version and is far from perfect.

If you are a beginner, check out the labelled open issues.


Requirements

  • Postgres (remote or local)
  • Go
  • A config file (example can be found in the config folder

GET STARTED

  1. go get github.com/encima/openape
  2.  package main
    
     import (
         "github.com/encima/openape"
     )
    
     func main() {
         openape.NewServer("PATH/TO/CONFIG")
     }
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(path string)

LoadConfig loads config file using Viper package

func RootHandler

func RootHandler(w http.ResponseWriter, r *http.Request)

RootHandler responds to / request

Types

type OpenApe

type OpenApe struct {
	// contains filtered or unexported fields
}

OpenApe object to hold objects related to the server

func NewServer

func NewServer(configPath string) OpenApe

NewServer sets up the

func (*OpenApe) APIAuthHandler

func (oape *OpenApe) APIAuthHandler(next http.Handler) http.Handler

APIAuthHandler matches API key with user details stored

func (*OpenApe) AddRoute

func (oape *OpenApe) AddRoute(path string, method string, model string)

AddRoute takes a path and a method to create a route handler for a Mux router instance

func (*OpenApe) GetModelFromPath

func (oape *OpenApe) GetModelFromPath(path string) string

GetModelFromPath identifies which routes maps to which models identified in the Schemas of the spec

func (*OpenApe) MapModels

func (oape *OpenApe) MapModels(models map[string]*openapi3.SchemaRef)

MapModels reads the models from the provided swagger file and creates the correspdonding tables in Postgres

func (*OpenApe) MapRoutes

func (oape *OpenApe) MapRoutes(paths map[string]*openapi3.PathItem)

MapRoutes iterates the paths laid out in the swagger file and adds them to the router

func (*OpenApe) RunServer

func (oape *OpenApe) RunServer()

RunServer starts the openapi server on the specified port

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL