diff --git a/.travis.yml b/.travis.yml index 503b986..1d253c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: go go: - - 1.7.3 - - tip + - "1.10.4" +go_import_path: frinka/dapperdox diff --git a/README.md b/README.md index 67c91f6..4496123 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# DapperDox   [![Build Status](https://travis-ci.org/DapperDox/dapperdox.svg?branch=master)](https://travis-ci.org/DapperDox/dapperdox) [![Download](https://img.shields.io/badge/release-v1.1.1-green.svg) ](https://github.com/DapperDox/dapperdox/releases/tag/v1.1.1) +# DapperDox   [![Build Status](https://travis-ci.org/frinka/dapperdox.svg?branch=master)](https://travis-ci.org/frinka/dapperdox) [![Download](https://img.shields.io/badge/release-v1.2.3green.svg) ](https://github.com/frinka/dapperdox/releases/tag/v1.2.3) ### Beautiful, integrated, OpenAPI documentation. diff --git a/config/config.go b/config/config.go index 4a06920..d047d89 100644 --- a/config/config.go +++ b/config/config.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,8 @@ import ( "reflect" "strings" - "github.com/dapperdox/dapperdox/logger" + "github.com/frinka/dapperdox/logger" + "github.com/ian-kent/gofigure" ) @@ -32,6 +33,7 @@ type config struct { DefaultAssetsDir string `env:"DEFAULT_ASSETS_DIR" flag:"default-assets-dir" flagDesc:"Default assets."` SpecDir string `env:"SPEC_DIR" flag:"spec-dir" flagDesc:"OpenAPI specification (swagger) directory"` SpecFilename []string `env:"SPEC_FILENAME" flag:"spec-filename" flagDesc:"The filename of the OpenAPI specification file within the spec-dir. May be multiply defined. Defaults to spec/swagger.json"` + SpecURL string `env:"SPEC_URL" flag:"spec-url" flagDesc:"OpenAPI specification (swagger) server url"` Theme string `env:"THEME" flag:"theme" flagDesc:"Theme to render documentation"` ThemeDir string `env:"THEME_DIR" flag:"theme-dir" flagDesc:"Directory containing installed themes"` LogLevel string `env:"LOGLEVEL" flag:"log-level" flagDesc:"Log level"` @@ -56,6 +58,7 @@ func Get() (*config, error) { cfg = &config{ BindAddr: "localhost:3123", SpecDir: "", + SpecURL: "", DefaultAssetsDir: "assets", LogLevel: "info", SiteURL: "http://localhost:3123/", diff --git a/createReleaseTable.sh b/createReleaseTable.sh index dc46b6e..ecf8b38 100755 --- a/createReleaseTable.sh +++ b/createReleaseTable.sh @@ -23,5 +23,5 @@ do TARG=`echo $i | cut -d'.' -f4` OS=`echo $TARG | cut -d'-' -f1` ARCH=`echo $TARG | cut -d'-' -f2` - echo "[$i](https://github.com/DapperDox/dapperdox/releases/download/v$VERSION/$i) | ${OS} | ${ARCH} | ${SIZE} | ${SUM} |" + echo "[$i](https://github.com/frinka/dapperdox/releases/download/v$VERSION/$i) | ${OS} | ${ARCH} | ${SIZE} | ${SUM} |" done diff --git a/handlers/guides/guides.go b/handlers/guides/guides.go index 89466ab..2d164b5 100644 --- a/handlers/guides/guides.go +++ b/handlers/guides/guides.go @@ -25,11 +25,11 @@ import ( "sort" "strings" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/navigation" - "github.com/dapperdox/dapperdox/render" - "github.com/dapperdox/dapperdox/render/asset" - "github.com/dapperdox/dapperdox/spec" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/navigation" + "github.com/frinka/dapperdox/render" + "github.com/frinka/dapperdox/render/asset" + "github.com/frinka/dapperdox/spec" "github.com/gorilla/pat" ) diff --git a/handlers/home/home.go b/handlers/home/home.go index 722a780..414d0dd 100644 --- a/handlers/home/home.go +++ b/handlers/home/home.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,10 +20,10 @@ package home import ( "net/http" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/render" - "github.com/dapperdox/dapperdox/spec" + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/render" + "github.com/frinka/dapperdox/spec" "github.com/gorilla/pat" ) diff --git a/handlers/reference/reference.go b/handlers/reference/reference.go index f321058..ca0d7fd 100644 --- a/handlers/reference/reference.go +++ b/handlers/reference/reference.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,9 +21,9 @@ import ( "net/http" //"github.com/davecgh/go-spew/spew" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/render" - "github.com/dapperdox/dapperdox/spec" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/render" + "github.com/frinka/dapperdox/spec" "github.com/gorilla/pat" ) diff --git a/handlers/specs/specs.go b/handlers/specs/specs.go index c914b95..a9521a9 100644 --- a/handlers/specs/specs.go +++ b/handlers/specs/specs.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,8 +24,8 @@ import ( "path/filepath" "strings" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" "github.com/gorilla/pat" ) diff --git a/handlers/static/static.go b/handlers/static/static.go index a6ca440..8d0ab5d 100644 --- a/handlers/static/static.go +++ b/handlers/static/static.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,10 +23,10 @@ import ( "path/filepath" "strings" - //"github.com/dapperdox/dapperdox/assets" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/render" - "github.com/dapperdox/dapperdox/render/asset" + //"dapperdox/assets" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/render" + "github.com/frinka/dapperdox/render/asset" "github.com/gorilla/pat" ) diff --git a/handlers/timeout/timeout.go b/handlers/timeout/timeout.go index 046a30a..5a1ed21 100644 --- a/handlers/timeout/timeout.go +++ b/handlers/timeout/timeout.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ import ( "sync" "time" - "github.com/dapperdox/dapperdox/logger" + "github.com/frinka/dapperdox/logger" ) // Handler returns a Handler that runs h with the given time limit. diff --git a/main.go b/main.go index 6bf9db0..3cb44a8 100644 --- a/main.go +++ b/main.go @@ -25,24 +25,26 @@ import ( "sync" "time" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/handlers/guides" - "github.com/dapperdox/dapperdox/handlers/home" - "github.com/dapperdox/dapperdox/handlers/reference" - "github.com/dapperdox/dapperdox/handlers/specs" - "github.com/dapperdox/dapperdox/handlers/static" - "github.com/dapperdox/dapperdox/handlers/timeout" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/network" - "github.com/dapperdox/dapperdox/proxy" - "github.com/dapperdox/dapperdox/render" - "github.com/dapperdox/dapperdox/spec" + "github.com/frinka/dapperdox/spec" + + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/handlers/guides" + "github.com/frinka/dapperdox/handlers/home" + "github.com/frinka/dapperdox/handlers/reference" + "github.com/frinka/dapperdox/handlers/specs" + "github.com/frinka/dapperdox/handlers/static" + "github.com/frinka/dapperdox/handlers/timeout" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/network" + "github.com/frinka/dapperdox/proxy" + "github.com/frinka/dapperdox/render" + "github.com/gorilla/pat" "github.com/justinas/alice" "github.com/justinas/nosurf" ) -var VERSION string = "1.2.1" +var VERSION string = "1.2.3" var tlsEnabled bool // --------------------------------------------------------------------------- @@ -94,7 +96,12 @@ func main() { specs.Register(router) spec.LoadStatusCodes() - err = spec.LoadSpecifications(cfg.BindAddr, true) + if cfg.SpecURL != "" { + err = spec.LoadSpecification(cfg.SpecURL) + } else { + err = spec.LoadSpecifications(cfg.BindAddr, true) + } + if err != nil { logger.Errorf(nil, "Load specification error: %s", err) os.Exit(1) diff --git a/network/network.go b/network/network.go index dc9a440..0f1164e 100644 --- a/network/network.go +++ b/network/network.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,9 +20,10 @@ package network import ( "crypto/tls" "errors" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" "net" + + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" ) func GetListener(tlsEnabled *bool) (net.Listener, error) { diff --git a/proxy/proxy.go b/proxy/proxy.go index 04d01f9..4efb510 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,14 +18,15 @@ along with this program. If not, see . package proxy import ( - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" - "github.com/gorilla/pat" "net/http" "net/http/httputil" "net/url" "strings" "time" + + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" + "github.com/gorilla/pat" ) type responseCapture struct { diff --git a/render/asset/asset.go b/render/asset/asset.go index 51fc372..eb17c22 100644 --- a/render/asset/asset.go +++ b/render/asset/asset.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,15 +28,17 @@ import ( "bytes" "fmt" "regexp" + //"github.com/davecgh/go-spew/spew" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" - "github.com/shurcooL/github_flavored_markdown" "io/ioutil" "os" "path/filepath" "strings" "unicode" + + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" + "github.com/shurcooL/github_flavored_markdown" ) var _bindata = map[string][]byte{} diff --git a/render/render.go b/render/render.go index 09555ea..8a7af88 100644 --- a/render/render.go +++ b/render/render.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,11 +25,11 @@ import ( "strings" //"github.com/davecgh/go-spew/spew" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" - "github.com/dapperdox/dapperdox/navigation" - "github.com/dapperdox/dapperdox/render/asset" - "github.com/dapperdox/dapperdox/spec" + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" + "github.com/frinka/dapperdox/navigation" + "github.com/frinka/dapperdox/render/asset" + "github.com/frinka/dapperdox/spec" "github.com/ian-kent/htmlform" "github.com/unrolled/render" ) diff --git a/spec/spec.go b/spec/spec.go index da38f08..98cc26e 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -27,8 +27,10 @@ import ( "sort" "strings" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" + "github.com/frinka/dapperdox/config" + + "github.com/frinka/dapperdox/logger" + //"github.com/davecgh/go-spew/spew" "github.com/go-openapi/loads" "github.com/go-openapi/spec" @@ -293,6 +295,30 @@ func LoadSpecifications(specHost string, collapse bool) error { return nil } +// +++++++++++++++++++++++++++++++++++++++++++++ +// Load spec from a url +func LoadSpecification(specUrl string) error { + if APISuite == nil { + APISuite = make(map[string]*APISpecification) + } + + var ok bool + var specification *APISpecification + + if specification, ok = APISuite[""]; !ok { + specification = &APISpecification{} + } + + var err = specification.Load(specUrl, "") + if err != nil { + return err + } + + APISuite[specification.ID] = specification + + return nil +} + // ----------------------------------------------------------------------------- // Load loads API specs from the supplied host (usually local!) func (c *APISpecification) Load(specLocation string, specHost string) error { @@ -1396,8 +1422,18 @@ func loadSpec(url string) (*loads.Document, error) { return nil, err } + // Because Title is required for resources but optional in the Open API spec, add the Title here for any definitions missing one + definitions := document.Spec().Definitions + for name, definition := range definitions { + if definition.Title == "" { + definition.Title = name + definitions[name] = definition + logger.Tracef(nil, "Definition for %s missing Title, setting Title to \"%s\"", name, definition.Title) + } + } + //options := &spec.ExpandOptions{ - // RelativeBase: "/Users/csmith1/src/go/src/github.com/dapperdox/dapperdox-demo/specifications", + // RelativeBase: "/Users/csmith1/src/go/src/dapperdox-demo/specifications", //} // TODO Allow relative references https://github.com/go-openapi/spec/issues/14 diff --git a/spec/statuscodes.go b/spec/statuscodes.go index d6dcc38..5821df1 100644 --- a/spec/statuscodes.go +++ b/spec/statuscodes.go @@ -1,5 +1,5 @@ /* -Copyright (C) 2016-2017 dapperdox.com +Copyright (C) 2016-2017 dapperdox.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,11 +19,12 @@ package spec import ( "bufio" - "github.com/dapperdox/dapperdox/config" - "github.com/dapperdox/dapperdox/logger" "os" "regexp" "strconv" + + "github.com/frinka/dapperdox/config" + "github.com/frinka/dapperdox/logger" ) var statusMapSplit = regexp.MustCompile(",")