Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spec.go to add Title properties #108

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go
go:
- 1.7.3
- tip
- "1.10.4"
go_import_path: frinka/dapperdox
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
7 changes: 5 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,7 +21,8 @@ import (
"reflect"
"strings"

"github.com/dapperdox/dapperdox/logger"
"github.com/frinka/dapperdox/logger"

"github.com/ian-kent/gofigure"
)

Expand All @@ -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"`
Expand All @@ -56,6 +58,7 @@ func Get() (*config, error) {
cfg = &config{
BindAddr: "localhost:3123",
SpecDir: "",
SpecURL: "",
DefaultAssetsDir: "assets",
LogLevel: "info",
SiteURL: "http://localhost:3123/",
Expand Down
2 changes: 1 addition & 1 deletion createReleaseTable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions handlers/guides/guides.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
10 changes: 5 additions & 5 deletions handlers/home/home.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)

Expand Down
8 changes: 4 additions & 4 deletions handlers/reference/reference.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions handlers/specs/specs.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)

Expand Down
10 changes: 5 additions & 5 deletions handlers/static/static.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions handlers/timeout/timeout.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
35 changes: 21 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions network/network.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,14 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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 {
Expand Down
10 changes: 6 additions & 4 deletions render/asset/asset.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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{}
Expand Down
12 changes: 6 additions & 6 deletions render/render.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
)
Expand Down
42 changes: 39 additions & 3 deletions spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading