You've already forked golang-base-project
@ -2,15 +2,6 @@ package main
|
|||||||
|
|
||||||
import baseproject "github.com/uberswe/golang-base-project"
|
import baseproject "github.com/uberswe/golang-base-project"
|
||||||
|
|
||||||
// @title Golang Base Project
|
|
||||||
// @version 1.0
|
|
||||||
// @description A minimal golang project with user authentication ready out of the box. All frontend assets should be less than 50 kB on every page load.
|
|
||||||
|
|
||||||
// @contact.name Markus Tenghamn
|
|
||||||
// @contact.email m@rkus.io
|
|
||||||
|
|
||||||
// @license.name ISC License
|
|
||||||
// @license.url https://github.com/uberswe/golang-base-project/blob/main/LICENSE
|
|
||||||
func main() {
|
func main() {
|
||||||
baseproject.Run()
|
baseproject.Run()
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,5 @@ type Config struct {
|
|||||||
SMTPPort string
|
SMTPPort string
|
||||||
SMTPSender string
|
SMTPSender string
|
||||||
RequestsPerMinute int
|
RequestsPerMinute int
|
||||||
|
CacheParameter string
|
||||||
}
|
}
|
||||||
|
2
dist/assets/css/main.css
vendored
2
dist/assets/css/main.css
vendored
File diff suppressed because one or more lines are too long
12
dist/templates/head.html
vendored
12
dist/templates/head.html
vendored
@ -9,16 +9,16 @@
|
|||||||
|
|
||||||
<link rel="canonical" href="https://golangbase.com">
|
<link rel="canonical" href="https://golangbase.com">
|
||||||
|
|
||||||
<link rel="apple-touch-icon" href="/assets/images/apple-touch-icon.png"
|
<link rel="apple-touch-icon" href="/assets/images/apple-touch-icon.png?c={{ .CacheParameter }}"
|
||||||
sizes="180x180">
|
sizes="180x180">
|
||||||
<link rel="icon" href="/assets/images/favicon-32x32.png" sizes="32x32"
|
<link rel="icon" href="/assets/images/favicon-32x32.png?c={{ .CacheParameter }}" sizes="32x32"
|
||||||
type="image/png">
|
type="image/png">
|
||||||
<link rel="icon" href="/assets/images/favicon-16x16.png" sizes="16x16"
|
<link rel="icon" href="/assets/images/favicon-16x16.png?c={{ .CacheParameter }}" sizes="16x16"
|
||||||
type="image/png">
|
type="image/png">
|
||||||
<link rel="manifest" href="/assets/images/site.webmanifest">
|
<link rel="manifest" href="/assets/images/site.webmanifest?c={{ .CacheParameter }}">
|
||||||
<link rel="icon" href="/assets/images/favicon.ico">
|
<link rel="icon" href="/assets/images/favicon.ico?c={{ .CacheParameter }}">
|
||||||
<meta name="theme-color" content="#2E61B8">
|
<meta name="theme-color" content="#2E61B8">
|
||||||
<link href="/assets/css/main.css" rel="stylesheet">
|
<link href="/assets/css/main.css?c={{ .CacheParameter }}" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="d-flex flex-column h-100">
|
<body class="d-flex flex-column h-100">
|
@ -31,6 +31,7 @@ services:
|
|||||||
- SMTP_SENDER=
|
- SMTP_SENDER=
|
||||||
- STRICT_TRANSPORT_SECURITY=false
|
- STRICT_TRANSPORT_SECURITY=false
|
||||||
- REQUESTS_PER_MINUTE=5
|
- REQUESTS_PER_MINUTE=5
|
||||||
|
- CACHE_PARAMETER=
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
ports:
|
ports:
|
||||||
|
11
env.go
11
env.go
@ -1,6 +1,7 @@
|
|||||||
package baseproject
|
package baseproject
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/securecookie"
|
||||||
"github.com/uberswe/golang-base-project/config"
|
"github.com/uberswe/golang-base-project/config"
|
||||||
"github.com/uberswe/golang-base-project/util"
|
"github.com/uberswe/golang-base-project/util"
|
||||||
"log"
|
"log"
|
||||||
@ -19,8 +20,8 @@ func loadEnvVariables() (c config.Config) {
|
|||||||
c.BaseURL = os.Getenv("BASE_URL")
|
c.BaseURL = os.Getenv("BASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
// A random secret will be generated when the application starts if no secret is provided. It is highly recommended to provide a secret.
|
// A random secret will be generated when the application starts if no secret is provided. It is highly recommended providing a secret.
|
||||||
c.CookieSecret = util.GenerateULID()
|
c.CookieSecret = string(securecookie.GenerateRandomKey(64))
|
||||||
if os.Getenv("COOKIE_SECRET") != "" {
|
if os.Getenv("COOKIE_SECRET") != "" {
|
||||||
c.CookieSecret = os.Getenv("COOKIE_SECRET")
|
c.CookieSecret = os.Getenv("COOKIE_SECRET")
|
||||||
}
|
}
|
||||||
@ -70,5 +71,11 @@ func loadEnvVariables() (c config.Config) {
|
|||||||
}
|
}
|
||||||
c.RequestsPerMinute = i
|
c.RequestsPerMinute = i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CacheParameter is added to the end of static file urls to prevent caching old versions
|
||||||
|
c.CacheParameter = util.RandomString(10)
|
||||||
|
if os.Getenv("CACHE_PARAMETER") != "" {
|
||||||
|
c.CacheParameter = os.Getenv("CACHE_PARAMETER")
|
||||||
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
8
go.mod
8
go.mod
@ -5,11 +5,15 @@ go 1.16
|
|||||||
require (
|
require (
|
||||||
github.com/gin-contrib/sessions v0.0.4
|
github.com/gin-contrib/sessions v0.0.4
|
||||||
github.com/gin-gonic/gin v1.7.7
|
github.com/gin-gonic/gin v1.7.7
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1
|
||||||
|
github.com/gorilla/securecookie v1.1.1
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
github.com/oklog/ulid/v2 v2.0.2
|
github.com/oklog/ulid/v2 v2.0.2
|
||||||
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2
|
|
||||||
github.com/swaggo/gin-swagger v1.3.3
|
|
||||||
github.com/ulule/limiter/v3 v3.9.0
|
github.com/ulule/limiter/v3 v3.9.0
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
||||||
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
|
||||||
gorm.io/driver/mysql v1.2.1
|
gorm.io/driver/mysql v1.2.1
|
||||||
gorm.io/driver/postgres v1.2.3
|
gorm.io/driver/postgres v1.2.3
|
||||||
gorm.io/driver/sqlite v1.2.6
|
gorm.io/driver/sqlite v1.2.6
|
||||||
|
49
go.sum
49
go.sum
@ -1,12 +1,6 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
|
||||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
|
||||||
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
|
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
|
||||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
|
||||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||||
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
|
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
|
||||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
|
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
|
||||||
@ -17,7 +11,6 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
|
|||||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
||||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -26,37 +19,22 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
|
||||||
github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k=
|
|
||||||
github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc=
|
|
||||||
github.com/gin-contrib/sessions v0.0.4 h1:gq4fNa1Zmp564iHP5G6EBuktilEos8VKhe2sza1KMgo=
|
github.com/gin-contrib/sessions v0.0.4 h1:gq4fNa1Zmp564iHP5G6EBuktilEos8VKhe2sza1KMgo=
|
||||||
github.com/gin-contrib/sessions v0.0.4/go.mod h1:pQ3sIyviBBGcxgyR8mkeJuXbeV3h3NYmhJADQTq5+Vo=
|
github.com/gin-contrib/sessions v0.0.4/go.mod h1:pQ3sIyviBBGcxgyR8mkeJuXbeV3h3NYmhJADQTq5+Vo=
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
|
||||||
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||||
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
||||||
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
||||||
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
|
||||||
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
|
|
||||||
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
|
|
||||||
github.com/go-openapi/spec v0.20.3 h1:uH9RQ6vdyPSs2pSy9fL8QPspDF2AMIMPtmK5coSSjtQ=
|
|
||||||
github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg=
|
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
|
||||||
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
|
||||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
|
||||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
|
||||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||||
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
||||||
@ -149,8 +127,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
|
|||||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
|
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
|
||||||
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
|
||||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b/go.mod h1:g2nVr8KZVXJSS97Jo8pJ0jgq29P6H7dG0oplUA86MQw=
|
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b/go.mod h1:g2nVr8KZVXJSS97Jo8pJ0jgq29P6H7dG0oplUA86MQw=
|
||||||
@ -172,10 +148,6 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|||||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
|
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
|
||||||
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
|
||||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
@ -212,12 +184,10 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
|
|||||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
||||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
@ -227,23 +197,14 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
|
|
||||||
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM=
|
|
||||||
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w=
|
|
||||||
github.com/swaggo/gin-swagger v1.3.3 h1:XHyYmeNVFG5PbyWHG4jXtxOm2P4kiZapDCWsyDDiQ/I=
|
|
||||||
github.com/swaggo/gin-swagger v1.3.3/go.mod h1:ymsZuGpbbu+S7ZoQ49QPpZoDBj6uqhb8WizgQPVgWl0=
|
|
||||||
github.com/swaggo/swag v1.7.4 h1:up+ixy8yOqJKiFcuhMgkuYuF4xnevuhnFAXXF8OSfNg=
|
|
||||||
github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
|
|
||||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
github.com/ulule/limiter/v3 v3.9.0 h1:ebASTkd6QNNUGhuDrWqImMpsg9GtItgNgxF3nKao58Q=
|
github.com/ulule/limiter/v3 v3.9.0 h1:ebASTkd6QNNUGhuDrWqImMpsg9GtItgNgxF3nKao58Q=
|
||||||
github.com/ulule/limiter/v3 v3.9.0/go.mod h1:icWc7rrF3T07dj59AhU4+HqKh0uWeh1wKct31wmcoF0=
|
github.com/ulule/limiter/v3 v3.9.0/go.mod h1:icWc7rrF3T07dj59AhU4+HqKh0uWeh1wKct31wmcoF0=
|
||||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.31.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
github.com/valyala/fasthttp v1.31.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
@ -275,22 +236,17 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
|||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
|
|
||||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -312,7 +268,6 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||||
@ -323,7 +278,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
@ -337,8 +291,6 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
|
|
||||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@ -364,7 +316,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
|
|||||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
14
main.go
14
main.go
@ -5,20 +5,23 @@ import (
|
|||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-contrib/sessions/cookie"
|
"github.com/gin-contrib/sessions/cookie"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
swaggerFiles "github.com/swaggo/files"
|
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
|
||||||
"github.com/uberswe/golang-base-project/middleware"
|
"github.com/uberswe/golang-base-project/middleware"
|
||||||
"github.com/uberswe/golang-base-project/routes"
|
"github.com/uberswe/golang-base-project/routes"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed dist/*
|
//go:embed dist/*
|
||||||
var staticFS embed.FS
|
var staticFS embed.FS
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
// When generating random strings we need to provide a seed otherwise we always get the same strings the next time our application starts
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
var t *template.Template
|
var t *template.Template
|
||||||
conf := loadEnvVariables()
|
conf := loadEnvVariables()
|
||||||
|
|
||||||
@ -26,7 +29,6 @@ func Run() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Println(db)
|
|
||||||
|
|
||||||
err = migrateDatabase(db)
|
err = migrateDatabase(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -50,7 +52,10 @@ func Run() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.StaticFS("/assets", http.FS(subFS))
|
assets := r.Group("/assets")
|
||||||
|
assets.Use(middleware.Cache())
|
||||||
|
|
||||||
|
assets.StaticFS("/", http.FS(subFS))
|
||||||
|
|
||||||
r.Use(middleware.Session(db))
|
r.Use(middleware.Session(db))
|
||||||
r.Use(middleware.General())
|
r.Use(middleware.General())
|
||||||
@ -60,7 +65,6 @@ func Run() {
|
|||||||
r.GET("/", controller.Index)
|
r.GET("/", controller.Index)
|
||||||
r.GET("/search", controller.Search)
|
r.GET("/search", controller.Search)
|
||||||
r.POST("/search", controller.Search)
|
r.POST("/search", controller.Search)
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
||||||
r.NoRoute(controller.NoRoute)
|
r.NoRoute(controller.NoRoute)
|
||||||
|
|
||||||
noAuth := r.Group("/")
|
noAuth := r.Group("/")
|
||||||
|
10
middleware/cache.go
Normal file
10
middleware/cache.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func Cache() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Header("Cache-Control", "public, max-age=60")
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@ func Session(db *gorm.DB) gin.HandlerFunc {
|
|||||||
Identifier: sessionIdentifier,
|
Identifier: sessionIdentifier,
|
||||||
}
|
}
|
||||||
res := db.Where(&ses).First(&ses)
|
res := db.Where(&ses).First(&ses)
|
||||||
if res.Error == nil {
|
if res.Error == nil && !ses.HasExpired() {
|
||||||
c.Set(UserIDKey, ses.UserID)
|
c.Set(UserIDKey, ses.UserID)
|
||||||
} else {
|
} else {
|
||||||
log.Println(res.Error)
|
log.Println(res.Error)
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Identifier string
|
Identifier string
|
||||||
UserID uint
|
UserID uint
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Session) HasExpired() bool {
|
||||||
|
return s.ExpiresAt.Before(time.Now())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Token struct {
|
type Token struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
@ -8,6 +11,11 @@ type Token struct {
|
|||||||
Type string
|
Type string
|
||||||
ModelID int
|
ModelID int
|
||||||
ModelType string
|
ModelType string
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t Token) HasExpired() bool {
|
||||||
|
return t.ExpiresAt.Before(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
1460
package-lock.json
generated
1460
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "golang-base-project",
|
"name": "golang-base-project",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A base project with a golang backend ready to handle user authentication.",
|
"description": "A base project with a Golang backend ready to handle user authentication.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -16,12 +16,11 @@
|
|||||||
"css-loader": "^6.5.1",
|
"css-loader": "^6.5.1",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
"mini-css-extract-plugin": "^2.4.5",
|
"mini-css-extract-plugin": "^2.4.5",
|
||||||
"node-sass": "^6.0.1",
|
|
||||||
"postcss": "^8.4.4",
|
"postcss": "^8.4.4",
|
||||||
"postcss-loader": "^6.2.1",
|
"postcss-loader": "^6.2.1",
|
||||||
"postcss-normalize": "^10.0.1",
|
"postcss-normalize": "^10.0.1",
|
||||||
"purgecss-webpack-plugin": "^4.1.3",
|
"purgecss-webpack-plugin": "^4.1.3",
|
||||||
"sass": "^1.44.0",
|
"sass": "^1.45.0",
|
||||||
"sass-loader": "^12.3.0",
|
"sass-loader": "^12.3.0",
|
||||||
"webpack": "^5.64.4",
|
"webpack": "^5.64.4",
|
||||||
"webpack-cli": "^4.9.1"
|
"webpack-cli": "^4.9.1"
|
||||||
|
@ -14,6 +14,7 @@ func (controller Controller) Activate(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Activate",
|
Title: "Activate",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
token := c.Param("token")
|
token := c.Param("token")
|
||||||
activationToken := models.Token{
|
activationToken := models.Token{
|
||||||
@ -32,6 +33,15 @@ func (controller Controller) Activate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if activationToken.HasExpired() {
|
||||||
|
pd.Messages = append(pd.Messages, Message{
|
||||||
|
Type: "error",
|
||||||
|
Content: activationError,
|
||||||
|
})
|
||||||
|
c.HTML(http.StatusBadRequest, "activate.html", pd)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
user := models.User{}
|
user := models.User{}
|
||||||
user.ID = uint(activationToken.ModelID)
|
user.ID = uint(activationToken.ModelID)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ func (controller Controller) Admin(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Admin",
|
Title: "Admin",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "admin.html", pd)
|
c.HTML(http.StatusOK, "admin.html", pd)
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (controller Controller) ForgotPassword(c *gin.Context) {
|
func (controller Controller) ForgotPassword(c *gin.Context) {
|
||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Forgot Password",
|
Title: "Forgot Password",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "forgotpassword.html", pd)
|
c.HTML(http.StatusOK, "forgotpassword.html", pd)
|
||||||
}
|
}
|
||||||
@ -25,6 +27,7 @@ func (controller Controller) ForgotPasswordPost(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Forgot Password",
|
Title: "Forgot Password",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
user := models.User{Email: email}
|
user := models.User{Email: email}
|
||||||
@ -57,6 +60,8 @@ func (controller Controller) forgotPasswordEmailHandler(userID uint, email strin
|
|||||||
|
|
||||||
forgotPasswordToken.ModelID = int(userID)
|
forgotPasswordToken.ModelID = int(userID)
|
||||||
forgotPasswordToken.ModelType = "User"
|
forgotPasswordToken.ModelType = "User"
|
||||||
|
// The token will expire 10 minutes after it was created
|
||||||
|
forgotPasswordToken.ExpiresAt = time.Now().Add(time.Minute * 10)
|
||||||
|
|
||||||
res = controller.db.Save(&forgotPasswordToken)
|
res = controller.db.Save(&forgotPasswordToken)
|
||||||
if res.Error != nil || res.RowsAffected == 0 {
|
if res.Error != nil || res.RowsAffected == 0 {
|
||||||
|
@ -9,6 +9,7 @@ func (controller Controller) Index(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Home",
|
Title: "Home",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "index.html", pd)
|
c.HTML(http.StatusOK, "index.html", pd)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ import (
|
|||||||
|
|
||||||
func (controller Controller) Login(c *gin.Context) {
|
func (controller Controller) Login(c *gin.Context) {
|
||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Login",
|
Title: "Login",
|
||||||
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "login.html", pd)
|
c.HTML(http.StatusOK, "login.html", pd)
|
||||||
}
|
}
|
||||||
@ -24,6 +26,7 @@ func (controller Controller) LoginPost(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Login",
|
Title: "Login",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
user := models.User{Email: email}
|
user := models.User{Email: email}
|
||||||
@ -76,7 +79,7 @@ func (controller Controller) LoginPost(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Session is valid for 1 hour
|
// Session is valid for 1 hour
|
||||||
ses.DeletedAt.Time = time.Now().Add(time.Hour * 1)
|
ses.ExpiresAt = time.Now().Add(time.Hour)
|
||||||
ses.UserID = user.ID
|
ses.UserID = user.ID
|
||||||
|
|
||||||
res = controller.db.Save(&ses)
|
res = controller.db.Save(&ses)
|
||||||
|
@ -24,6 +24,7 @@ type PageData struct {
|
|||||||
Title string
|
Title string
|
||||||
Messages []Message
|
Messages []Message
|
||||||
IsAuthenticated bool
|
IsAuthenticated bool
|
||||||
|
CacheParameter string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
|
@ -9,6 +9,7 @@ func (controller Controller) NoRoute(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "404 Not Found",
|
Title: "404 Not Found",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "404.html", pd)
|
c.HTML(http.StatusOK, "404.html", pd)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
email2 "github.com/uberswe/golang-base-project/email"
|
email2 "github.com/uberswe/golang-base-project/email"
|
||||||
"github.com/uberswe/golang-base-project/models"
|
"github.com/uberswe/golang-base-project/models"
|
||||||
"github.com/uberswe/golang-base-project/util"
|
"github.com/uberswe/golang-base-project/util"
|
||||||
@ -12,12 +13,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (controller Controller) Register(c *gin.Context) {
|
func (controller Controller) Register(c *gin.Context) {
|
||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Register",
|
Title: "Register",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "register.html", pd)
|
c.HTML(http.StatusOK, "register.html", pd)
|
||||||
}
|
}
|
||||||
@ -29,6 +32,7 @@ func (controller Controller) RegisterPost(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Register",
|
Title: "Register",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
password := c.PostForm("password")
|
password := c.PostForm("password")
|
||||||
if len(password) < 8 {
|
if len(password) < 8 {
|
||||||
@ -53,6 +57,21 @@ func (controller Controller) RegisterPost(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
|
|
||||||
|
// Validate the email
|
||||||
|
validate := validator.New()
|
||||||
|
err = validate.Var(email, "required,email")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
pd.Messages = append(pd.Messages, Message{
|
||||||
|
Type: "error",
|
||||||
|
Content: registerError,
|
||||||
|
})
|
||||||
|
log.Println(err)
|
||||||
|
c.HTML(http.StatusInternalServerError, "register.html", pd)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
user := models.User{Email: email}
|
user := models.User{Email: email}
|
||||||
|
|
||||||
res := controller.db.Where(&user).First(&user)
|
res := controller.db.Where(&user).First(&user)
|
||||||
@ -115,6 +134,7 @@ func (controller Controller) activationEmailHandler(userID uint, email string) {
|
|||||||
|
|
||||||
activationToken.ModelID = int(userID)
|
activationToken.ModelID = int(userID)
|
||||||
activationToken.ModelType = "User"
|
activationToken.ModelType = "User"
|
||||||
|
activationToken.ExpiresAt = time.Now().Add(time.Minute * 10)
|
||||||
|
|
||||||
res = controller.db.Save(&activationToken)
|
res = controller.db.Save(&activationToken)
|
||||||
if res.Error != nil || res.RowsAffected == 0 {
|
if res.Error != nil || res.RowsAffected == 0 {
|
||||||
|
@ -11,6 +11,7 @@ func (controller Controller) ResendActivation(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Resend Activation Email",
|
Title: "Resend Activation Email",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "resendactivation.html", pd)
|
c.HTML(http.StatusOK, "resendactivation.html", pd)
|
||||||
}
|
}
|
||||||
@ -19,6 +20,7 @@ func (controller Controller) ResendActivationPost(c *gin.Context) {
|
|||||||
pd := PageData{
|
pd := PageData{
|
||||||
Title: "Resend Activation Email",
|
Title: "Resend Activation Email",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
}
|
}
|
||||||
email := c.PostForm("email")
|
email := c.PostForm("email")
|
||||||
user := models.User{Email: email}
|
user := models.User{Email: email}
|
||||||
|
@ -19,6 +19,7 @@ func (controller Controller) ResetPassword(c *gin.Context) {
|
|||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "Reset Password",
|
Title: "Reset Password",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
},
|
},
|
||||||
Token: token,
|
Token: token,
|
||||||
}
|
}
|
||||||
@ -34,6 +35,7 @@ func (controller Controller) ResetPasswordPost(c *gin.Context) {
|
|||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "Reset Password",
|
Title: "Reset Password",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
},
|
},
|
||||||
Token: token,
|
Token: token,
|
||||||
}
|
}
|
||||||
@ -63,6 +65,15 @@ func (controller Controller) ResetPasswordPost(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if forgotPasswordToken.HasExpired() {
|
||||||
|
pd.Messages = append(pd.Messages, Message{
|
||||||
|
Type: "error",
|
||||||
|
Content: resetError,
|
||||||
|
})
|
||||||
|
c.HTML(http.StatusBadRequest, "resetpassword.html", pd)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
user := models.User{}
|
user := models.User{}
|
||||||
user.ID = uint(forgotPasswordToken.ModelID)
|
user.ID = uint(forgotPasswordToken.ModelID)
|
||||||
res = controller.db.Where(&user).First(&user)
|
res = controller.db.Where(&user).First(&user)
|
||||||
|
@ -18,6 +18,7 @@ func (controller Controller) Search(c *gin.Context) {
|
|||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "Search",
|
Title: "Search",
|
||||||
IsAuthenticated: isAuthenticated(c),
|
IsAuthenticated: isAuthenticated(c),
|
||||||
|
CacheParameter: controller.config.CacheParameter,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
search := c.PostForm("search")
|
search := c.PostForm("search")
|
||||||
|
13
util/text.go
13
util/text.go
@ -3,6 +3,7 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -34,3 +35,15 @@ func GetStringBetweenStrings(str string, start string, end string) (result strin
|
|||||||
}
|
}
|
||||||
return str[s : s+e]
|
return str[s : s+e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RandomString generates a random string of n length. Based on https://stackoverflow.com/a/22892986/1260548
|
||||||
|
func RandomString(n int) string {
|
||||||
|
// remove vowels to make it less likely to generate something offensive
|
||||||
|
var letters = []rune("bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ")
|
||||||
|
|
||||||
|
b := make([]rune, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = letters[rand.Intn(len(letters))]
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
16
vendor/github.com/KyleBanks/depth/.gitignore
generated
vendored
16
vendor/github.com/KyleBanks/depth/.gitignore
generated
vendored
@ -1,16 +0,0 @@
|
|||||||
# Binaries for programs and plugins
|
|
||||||
*.exe
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Test binary, build with `go test -c`
|
|
||||||
*.test
|
|
||||||
|
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
|
||||||
*.out
|
|
||||||
|
|
||||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
|
||||||
.glide/
|
|
||||||
|
|
||||||
bin/
|
|
9
vendor/github.com/KyleBanks/depth/.travis.yml
generated
vendored
9
vendor/github.com/KyleBanks/depth/.travis.yml
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
language: go
|
|
||||||
sudo: false
|
|
||||||
go:
|
|
||||||
- 1.9.x
|
|
||||||
before_install:
|
|
||||||
- go get github.com/mattn/goveralls
|
|
||||||
script:
|
|
||||||
- $HOME/gopath/bin/goveralls -service=travis-ci
|
|
||||||
#script: go test $(go list ./... | grep -v vendor/)
|
|
21
vendor/github.com/KyleBanks/depth/LICENSE
generated
vendored
21
vendor/github.com/KyleBanks/depth/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Kyle Banks
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
32
vendor/github.com/KyleBanks/depth/Makefile
generated
vendored
32
vendor/github.com/KyleBanks/depth/Makefile
generated
vendored
@ -1,32 +0,0 @@
|
|||||||
VERSION = 1.2.1
|
|
||||||
|
|
||||||
RELEASE_PKG = ./cmd/depth
|
|
||||||
INSTALL_PKG = $(RELEASE_PKG)
|
|
||||||
|
|
||||||
|
|
||||||
# Remote includes require 'mmake'
|
|
||||||
# github.com/tj/mmake
|
|
||||||
include github.com/KyleBanks/make/go/install
|
|
||||||
include github.com/KyleBanks/make/go/sanity
|
|
||||||
include github.com/KyleBanks/make/go/release
|
|
||||||
include github.com/KyleBanks/make/go/bench
|
|
||||||
include github.com/KyleBanks/make/git/precommit
|
|
||||||
|
|
||||||
# Runs a number of depth commands as examples of what's possible.
|
|
||||||
example: | install
|
|
||||||
depth github.com/KyleBanks/depth/cmd/depth strings ./
|
|
||||||
|
|
||||||
depth -internal strings
|
|
||||||
|
|
||||||
depth -json github.com/KyleBanks/depth/cmd/depth
|
|
||||||
|
|
||||||
depth -test github.com/KyleBanks/depth/cmd/depth
|
|
||||||
|
|
||||||
depth -test -internal strings
|
|
||||||
|
|
||||||
depth -test -internal -max 3 strings
|
|
||||||
|
|
||||||
depth .
|
|
||||||
|
|
||||||
depth ./cmd/depth
|
|
||||||
.PHONY: example
|
|
232
vendor/github.com/KyleBanks/depth/README.md
generated
vendored
232
vendor/github.com/KyleBanks/depth/README.md
generated
vendored
@ -1,232 +0,0 @@
|
|||||||
# depth
|
|
||||||
|
|
||||||
[](https://godoc.org/github.com/KyleBanks/depth)
|
|
||||||
[](https://travis-ci.org/KyleBanks/depth)
|
|
||||||
[](https://goreportcard.com/report/github.com/KyleBanks/depth)
|
|
||||||
[](https://coveralls.io/github/KyleBanks/depth?branch=master)
|
|
||||||
|
|
||||||
`depth` is tool to retrieve and visualize Go source code dependency trees.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Download the appropriate binary for your platform from the [Releases](https://github.com/KyleBanks/depth/releases) page, or:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go get github.com/KyleBanks/depth/cmd/depth
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
`depth` can be used as a standalone command-line application, or as a package within your own project.
|
|
||||||
|
|
||||||
### Command-Line
|
|
||||||
|
|
||||||
Simply execute `depth` with one or more package names to visualize. You can use the fully qualified import path of the package, like so:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth github.com/KyleBanks/depth/cmd/depth
|
|
||||||
github.com/KyleBanks/depth/cmd/depth
|
|
||||||
├ encoding/json
|
|
||||||
├ flag
|
|
||||||
├ fmt
|
|
||||||
├ io
|
|
||||||
├ log
|
|
||||||
├ os
|
|
||||||
├ strings
|
|
||||||
└ github.com/KyleBanks/depth
|
|
||||||
├ fmt
|
|
||||||
├ go/build
|
|
||||||
├ path
|
|
||||||
├ sort
|
|
||||||
└ strings
|
|
||||||
12 dependencies (11 internal, 1 external, 0 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
Or you can use a relative path, for example:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth .
|
|
||||||
$ depth ./cmd/depth
|
|
||||||
$ depth ../
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use `depth` on the Go standard library:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth strings
|
|
||||||
strings
|
|
||||||
├ errors
|
|
||||||
├ io
|
|
||||||
├ unicode
|
|
||||||
└ unicode/utf8
|
|
||||||
5 dependencies (5 internal, 0 external, 0 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
Visualizing multiple packages at a time is supported by simply naming the packages you'd like to visualize:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth strings github.com/KyleBanks/depth
|
|
||||||
strings
|
|
||||||
├ errors
|
|
||||||
├ io
|
|
||||||
├ unicode
|
|
||||||
└ unicode/utf8
|
|
||||||
5 dependencies (5 internal, 0 external, 0 testing).
|
|
||||||
github.com/KyleBanks/depth
|
|
||||||
├ fmt
|
|
||||||
├ go/build
|
|
||||||
├ path
|
|
||||||
├ sort
|
|
||||||
└ strings
|
|
||||||
7 dependencies (7 internal, 0 external, 0 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `-internal`
|
|
||||||
|
|
||||||
By default, `depth` only resolves the top level of dependencies for standard library packages, however you can use the `-internal` flag to visualize all internal dependencies:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth -internal strings
|
|
||||||
strings
|
|
||||||
├ errors
|
|
||||||
├ io
|
|
||||||
├ errors
|
|
||||||
└ sync
|
|
||||||
├ internal/race
|
|
||||||
└ unsafe
|
|
||||||
├ runtime
|
|
||||||
├ runtime/internal/atomic
|
|
||||||
└ unsafe
|
|
||||||
├ runtime/internal/sys
|
|
||||||
└ unsafe
|
|
||||||
├ sync/atomic
|
|
||||||
└ unsafe
|
|
||||||
└ unsafe
|
|
||||||
├ unicode
|
|
||||||
└ unicode/utf8
|
|
||||||
12 dependencies (12 internal, 0 external, 0 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `-max`
|
|
||||||
|
|
||||||
The `-max` flag limits the dependency tree to the maximum depth provided. For example, if you supply `-max 1` on the `depth` package, your output would look like so:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ depth -max 1 github.com/KyleBanks/depth/cmd/depth
|
|
||||||
github.com/KyleBanks/depth/cmd/depth
|
|
||||||
├ encoding/json
|
|
||||||
├ flag
|
|
||||||
├ fmt
|
|
||||||
├ io
|
|
||||||
├ log
|
|
||||||
├ os
|
|
||||||
├ strings
|
|
||||||
└ github.com/KyleBanks/depth
|
|
||||||
7 dependencies (6 internal, 1 external, 0 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
The `-max` flag is particularly useful in conjunction with the `-internal` flag which can lead to very deep dependency trees.
|
|
||||||
|
|
||||||
#### `-test`
|
|
||||||
|
|
||||||
By default, `depth` ignores dependencies that are only required for testing. However, you can view test dependencies using the `-test` flag:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth -test strings
|
|
||||||
strings
|
|
||||||
├ bytes
|
|
||||||
├ errors
|
|
||||||
├ fmt
|
|
||||||
├ io
|
|
||||||
├ io/ioutil
|
|
||||||
├ math/rand
|
|
||||||
├ reflect
|
|
||||||
├ sync
|
|
||||||
├ testing
|
|
||||||
├ unicode
|
|
||||||
├ unicode/utf8
|
|
||||||
└ unsafe
|
|
||||||
13 dependencies (13 internal, 0 external, 8 testing).
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `-explain target-package`
|
|
||||||
|
|
||||||
The `-explain` flag instructs `depth` to print import chains in which the
|
|
||||||
`target-package` is found:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth -explain strings github.com/KyleBanks/depth/cmd/depth
|
|
||||||
github.com/KyleBanks/depth/cmd/depth -> strings
|
|
||||||
github.com/KyleBanks/depth/cmd/depth -> github.com/KyleBanks/depth -> strings
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `-json`
|
|
||||||
|
|
||||||
The `-json` flag instructs `depth` to output dependencies in JSON format:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ depth -json github.com/KyleBanks/depth/cmd/depth
|
|
||||||
{
|
|
||||||
"name": "github.com/KyleBanks/depth/cmd/depth",
|
|
||||||
"deps": [
|
|
||||||
{
|
|
||||||
"name": "encoding/json",
|
|
||||||
"internal": true,
|
|
||||||
"deps": null
|
|
||||||
},
|
|
||||||
...
|
|
||||||
{
|
|
||||||
"name": "github.com/KyleBanks/depth",
|
|
||||||
"internal": false,
|
|
||||||
"deps": [
|
|
||||||
{
|
|
||||||
"name": "go/build",
|
|
||||||
"internal": true,
|
|
||||||
"deps": null
|
|
||||||
},
|
|
||||||
...
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Integrating With Your Project
|
|
||||||
|
|
||||||
The `depth` package can easily be used to retrieve the dependency tree for a particular package in your own project. For example, here's how you would retrieve the dependency tree for the `strings` package:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import "github.com/KyleBanks/depth"
|
|
||||||
|
|
||||||
var t depth.Tree
|
|
||||||
err := t.Resolve("strings")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output: "'strings' has 4 dependencies."
|
|
||||||
log.Printf("'%v' has %v dependencies.", t.Root.Name, len(t.Root.Deps))
|
|
||||||
```
|
|
||||||
|
|
||||||
For additional customization, simply set the appropriate flags on the `Tree` before resolving:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import "github.com/KyleBanks/depth"
|
|
||||||
|
|
||||||
t := depth.Tree {
|
|
||||||
ResolveInternal: true,
|
|
||||||
ResolveTest: true,
|
|
||||||
MaxDepth: 10,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
err := t.Resolve("strings")
|
|
||||||
```
|
|
||||||
|
|
||||||
## Author
|
|
||||||
|
|
||||||
`depth` was developed by [Kyle Banks](https://twitter.com/kylewbanks).
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
`depth` is available under the [MIT](./LICENSE) license.
|
|
129
vendor/github.com/KyleBanks/depth/depth.go
generated
vendored
129
vendor/github.com/KyleBanks/depth/depth.go
generated
vendored
@ -1,129 +0,0 @@
|
|||||||
// Package depth provides the ability to traverse and retrieve Go source code dependencies in the form of
|
|
||||||
// internal and external packages.
|
|
||||||
//
|
|
||||||
// For example, the dependencies of the stdlib `strings` package can be resolved like so:
|
|
||||||
//
|
|
||||||
// import "github.com/KyleBanks/depth"
|
|
||||||
//
|
|
||||||
// var t depth.Tree
|
|
||||||
// err := t.Resolve("strings")
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Output: "strings has 4 dependencies."
|
|
||||||
// log.Printf("%v has %v dependencies.", t.Root.Name, len(t.Root.Deps))
|
|
||||||
//
|
|
||||||
// For additional customization, simply set the appropriate flags on the `Tree` before resolving:
|
|
||||||
//
|
|
||||||
// import "github.com/KyleBanks/depth"
|
|
||||||
//
|
|
||||||
// t := depth.Tree {
|
|
||||||
// ResolveInternal: true,
|
|
||||||
// ResolveTest: true,
|
|
||||||
// MaxDepth: 10,
|
|
||||||
// }
|
|
||||||
// err := t.Resolve("strings")
|
|
||||||
package depth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"go/build"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrRootPkgNotResolved is returned when the root Pkg of the Tree cannot be resolved,
|
|
||||||
// typically because it does not exist.
|
|
||||||
var ErrRootPkgNotResolved = errors.New("unable to resolve root package")
|
|
||||||
|
|
||||||
// Importer defines a type that can import a package and return its details.
|
|
||||||
type Importer interface {
|
|
||||||
Import(name, srcDir string, im build.ImportMode) (*build.Package, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tree represents the top level of a Pkg and the configuration used to
|
|
||||||
// initialize and represent its contents.
|
|
||||||
type Tree struct {
|
|
||||||
Root *Pkg
|
|
||||||
|
|
||||||
ResolveInternal bool
|
|
||||||
ResolveTest bool
|
|
||||||
MaxDepth int
|
|
||||||
|
|
||||||
Importer Importer
|
|
||||||
|
|
||||||
importCache map[string]struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve recursively finds all dependencies for the root Pkg name provided,
|
|
||||||
// and the packages it depends on.
|
|
||||||
func (t *Tree) Resolve(name string) error {
|
|
||||||
pwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Root = &Pkg{
|
|
||||||
Name: name,
|
|
||||||
Tree: t,
|
|
||||||
SrcDir: pwd,
|
|
||||||
Test: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the import cache each time to ensure a reused Tree doesn't
|
|
||||||
// reuse the same cache.
|
|
||||||
t.importCache = nil
|
|
||||||
|
|
||||||
// Allow custom importers, but use build.Default if none is provided.
|
|
||||||
if t.Importer == nil {
|
|
||||||
t.Importer = &build.Default
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Root.Resolve(t.Importer)
|
|
||||||
if !t.Root.Resolved {
|
|
||||||
return ErrRootPkgNotResolved
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// shouldResolveInternal determines if internal packages should be further resolved beyond the
|
|
||||||
// current parent.
|
|
||||||
//
|
|
||||||
// For example, if the parent Pkg is `github.com/foo/bar` and true is returned, all the
|
|
||||||
// internal dependencies it relies on will be resolved. If for example `strings` is one of those
|
|
||||||
// dependencies, and it is passed as the parent here, false may be returned and its internal
|
|
||||||
// dependencies will not be resolved.
|
|
||||||
func (t *Tree) shouldResolveInternal(parent *Pkg) bool {
|
|
||||||
if t.ResolveInternal {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent == t.Root
|
|
||||||
}
|
|
||||||
|
|
||||||
// isAtMaxDepth returns true when the depth of the Pkg provided is at or beyond the maximum
|
|
||||||
// depth allowed by the tree.
|
|
||||||
//
|
|
||||||
// If the Tree has a MaxDepth of zero, true is never returned.
|
|
||||||
func (t *Tree) isAtMaxDepth(p *Pkg) bool {
|
|
||||||
if t.MaxDepth == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.depth() >= t.MaxDepth
|
|
||||||
}
|
|
||||||
|
|
||||||
// hasSeenImport returns true if the import name provided has already been seen within the tree.
|
|
||||||
// This function only returns false for a name once.
|
|
||||||
func (t *Tree) hasSeenImport(name string) bool {
|
|
||||||
if t.importCache == nil {
|
|
||||||
t.importCache = make(map[string]struct{})
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := t.importCache[name]; ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
t.importCache[name] = struct{}{}
|
|
||||||
return false
|
|
||||||
}
|
|
184
vendor/github.com/KyleBanks/depth/pkg.go
generated
vendored
184
vendor/github.com/KyleBanks/depth/pkg.go
generated
vendored
@ -1,184 +0,0 @@
|
|||||||
package depth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"go/build"
|
|
||||||
"path"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Pkg represents a Go source package, and its dependencies.
|
|
||||||
type Pkg struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
SrcDir string `json:"-"`
|
|
||||||
|
|
||||||
Internal bool `json:"internal"`
|
|
||||||
Resolved bool `json:"resolved"`
|
|
||||||
Test bool `json:"-"`
|
|
||||||
|
|
||||||
Tree *Tree `json:"-"`
|
|
||||||
Parent *Pkg `json:"-"`
|
|
||||||
Deps []Pkg `json:"deps"`
|
|
||||||
|
|
||||||
Raw *build.Package `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve recursively finds all dependencies for the Pkg and the packages it depends on.
|
|
||||||
func (p *Pkg) Resolve(i Importer) {
|
|
||||||
// Resolved is always true, regardless of if we skip the import,
|
|
||||||
// it is only false if there is an error while importing.
|
|
||||||
p.Resolved = true
|
|
||||||
|
|
||||||
name := p.cleanName()
|
|
||||||
if name == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop resolving imports if we've reached max depth or found a duplicate.
|
|
||||||
var importMode build.ImportMode
|
|
||||||
if p.Tree.hasSeenImport(name) || p.Tree.isAtMaxDepth(p) {
|
|
||||||
importMode = build.FindOnly
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg, err := i.Import(name, p.SrcDir, importMode)
|
|
||||||
if err != nil {
|
|
||||||
// TODO: Check the error type?
|
|
||||||
p.Resolved = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.Raw = pkg
|
|
||||||
|
|
||||||
// Update the name with the fully qualified import path.
|
|
||||||
p.Name = pkg.ImportPath
|
|
||||||
|
|
||||||
// If this is an internal dependency, we may need to skip it.
|
|
||||||
if pkg.Goroot {
|
|
||||||
p.Internal = true
|
|
||||||
if !p.Tree.shouldResolveInternal(p) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//first we set the regular dependencies, then we add the test dependencies
|
|
||||||
//sharing the same set. This allows us to mark all test-only deps linearly
|
|
||||||
unique := make(map[string]struct{})
|
|
||||||
p.setDeps(i, pkg.Imports, pkg.Dir, unique, false)
|
|
||||||
if p.Tree.ResolveTest {
|
|
||||||
p.setDeps(i, append(pkg.TestImports, pkg.XTestImports...), pkg.Dir, unique, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// setDeps takes a slice of import paths and the source directory they are relative to,
|
|
||||||
// and creates the Deps of the Pkg. Each dependency is also further resolved prior to being added
|
|
||||||
// to the Pkg.
|
|
||||||
func (p *Pkg) setDeps(i Importer, imports []string, srcDir string, unique map[string]struct{}, isTest bool) {
|
|
||||||
for _, imp := range imports {
|
|
||||||
// Mostly for testing files where cyclic imports are allowed.
|
|
||||||
if imp == p.Name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip duplicates.
|
|
||||||
if _, ok := unique[imp]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
unique[imp] = struct{}{}
|
|
||||||
|
|
||||||
p.addDep(i, imp, srcDir, isTest)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(byInternalAndName(p.Deps))
|
|
||||||
}
|
|
||||||
|
|
||||||
// addDep creates a Pkg and it's dependencies from an imported package name.
|
|
||||||
func (p *Pkg) addDep(i Importer, name string, srcDir string, isTest bool) {
|
|
||||||
dep := Pkg{
|
|
||||||
Name: name,
|
|
||||||
SrcDir: srcDir,
|
|
||||||
Tree: p.Tree,
|
|
||||||
Parent: p,
|
|
||||||
Test: isTest,
|
|
||||||
}
|
|
||||||
dep.Resolve(i)
|
|
||||||
|
|
||||||
p.Deps = append(p.Deps, dep)
|
|
||||||
}
|
|
||||||
|
|
||||||
// isParent goes recursively up the chain of Pkgs to determine if the name provided is ever a
|
|
||||||
// parent of the current Pkg.
|
|
||||||
func (p *Pkg) isParent(name string) bool {
|
|
||||||
if p.Parent == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Parent.Name == name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.Parent.isParent(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// depth returns the depth of the Pkg within the Tree.
|
|
||||||
func (p *Pkg) depth() int {
|
|
||||||
if p.Parent == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.Parent.depth() + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanName returns a cleaned version of the Pkg name used for resolving dependencies.
|
|
||||||
//
|
|
||||||
// If an empty string is returned, dependencies should not be resolved.
|
|
||||||
func (p *Pkg) cleanName() string {
|
|
||||||
name := p.Name
|
|
||||||
|
|
||||||
// C 'package' cannot be resolved.
|
|
||||||
if name == "C" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal golang_org/* packages must be prefixed with vendor/
|
|
||||||
//
|
|
||||||
// Thanks to @davecheney for this:
|
|
||||||
// https://github.com/davecheney/graphpkg/blob/master/main.go#L46
|
|
||||||
if strings.HasPrefix(name, "golang_org") {
|
|
||||||
name = path.Join("vendor", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a string representation of the Pkg containing the Pkg name and status.
|
|
||||||
func (p *Pkg) String() string {
|
|
||||||
b := bytes.NewBufferString(p.Name)
|
|
||||||
|
|
||||||
if !p.Resolved {
|
|
||||||
b.Write([]byte(" (unresolved)"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// byInternalAndName ensures a slice of Pkgs are sorted such that the internal stdlib
|
|
||||||
// packages are always above external packages (ie. github.com/whatever).
|
|
||||||
type byInternalAndName []Pkg
|
|
||||||
|
|
||||||
func (b byInternalAndName) Len() int {
|
|
||||||
return len(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b byInternalAndName) Swap(i, j int) {
|
|
||||||
b[i], b[j] = b[j], b[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b byInternalAndName) Less(i, j int) bool {
|
|
||||||
if b[i].Internal && !b[j].Internal {
|
|
||||||
return true
|
|
||||||
} else if !b[i].Internal && b[j].Internal {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return b[i].Name < b[j].Name
|
|
||||||
}
|
|
5
vendor/github.com/PuerkitoBio/purell/.gitignore
generated
vendored
5
vendor/github.com/PuerkitoBio/purell/.gitignore
generated
vendored
@ -1,5 +0,0 @@
|
|||||||
*.sublime-*
|
|
||||||
.DS_Store
|
|
||||||
*.swp
|
|
||||||
*.swo
|
|
||||||
tags
|
|
12
vendor/github.com/PuerkitoBio/purell/.travis.yml
generated
vendored
12
vendor/github.com/PuerkitoBio/purell/.travis.yml
generated
vendored
@ -1,12 +0,0 @@
|
|||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.4.x
|
|
||||||
- 1.5.x
|
|
||||||
- 1.6.x
|
|
||||||
- 1.7.x
|
|
||||||
- 1.8.x
|
|
||||||
- 1.9.x
|
|
||||||
- "1.10.x"
|
|
||||||
- "1.11.x"
|
|
||||||
- tip
|
|
12
vendor/github.com/PuerkitoBio/purell/LICENSE
generated
vendored
12
vendor/github.com/PuerkitoBio/purell/LICENSE
generated
vendored
@ -1,12 +0,0 @@
|
|||||||
Copyright (c) 2012, Martin Angers
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
188
vendor/github.com/PuerkitoBio/purell/README.md
generated
vendored
188
vendor/github.com/PuerkitoBio/purell/README.md
generated
vendored
@ -1,188 +0,0 @@
|
|||||||
# Purell
|
|
||||||
|
|
||||||
Purell is a tiny Go library to normalize URLs. It returns a pure URL. Pure-ell. Sanitizer and all. Yeah, I know...
|
|
||||||
|
|
||||||
Based on the [wikipedia paper][wiki] and the [RFC 3986 document][rfc].
|
|
||||||
|
|
||||||
[](http://travis-ci.org/PuerkitoBio/purell)
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
`go get github.com/PuerkitoBio/purell`
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
* **v1.1.1** : Fix failing test due to Go1.12 changes (thanks to @ianlancetaylor).
|
|
||||||
* **2016-11-14 (v1.1.0)** : IDN: Conform to RFC 5895: Fold character width (thanks to @beeker1121).
|
|
||||||
* **2016-07-27 (v1.0.0)** : Normalize IDN to ASCII (thanks to @zenovich).
|
|
||||||
* **2015-02-08** : Add fix for relative paths issue ([PR #5][pr5]) and add fix for unnecessary encoding of reserved characters ([see issue #7][iss7]).
|
|
||||||
* **v0.2.0** : Add benchmarks, Attempt IDN support.
|
|
||||||
* **v0.1.0** : Initial release.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
From `example_test.go` (note that in your code, you would import "github.com/PuerkitoBio/purell", and would prefix references to its methods and constants with "purell."):
|
|
||||||
|
|
||||||
```go
|
|
||||||
package purell
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ExampleNormalizeURLString() {
|
|
||||||
if normalized, err := NormalizeURLString("hTTp://someWEBsite.com:80/Amazing%3f/url/",
|
|
||||||
FlagLowercaseScheme|FlagLowercaseHost|FlagUppercaseEscapes); err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else {
|
|
||||||
fmt.Print(normalized)
|
|
||||||
}
|
|
||||||
// Output: http://somewebsite.com:80/Amazing%3F/url/
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleMustNormalizeURLString() {
|
|
||||||
normalized := MustNormalizeURLString("hTTpS://someWEBsite.com:443/Amazing%fa/url/",
|
|
||||||
FlagsUnsafeGreedy)
|
|
||||||
fmt.Print(normalized)
|
|
||||||
|
|
||||||
// Output: http://somewebsite.com/Amazing%FA/url
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleNormalizeURL() {
|
|
||||||
if u, err := url.Parse("Http://SomeUrl.com:8080/a/b/.././c///g?c=3&a=1&b=9&c=0#target"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
} else {
|
|
||||||
normalized := NormalizeURL(u, FlagsUsuallySafeGreedy|FlagRemoveDuplicateSlashes|FlagRemoveFragment)
|
|
||||||
fmt.Print(normalized)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output: http://someurl.com:8080/a/c/g?c=3&a=1&b=9&c=0
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
As seen in the examples above, purell offers three methods, `NormalizeURLString(string, NormalizationFlags) (string, error)`, `MustNormalizeURLString(string, NormalizationFlags) (string)` and `NormalizeURL(*url.URL, NormalizationFlags) (string)`. They all normalize the provided URL based on the specified flags. Here are the available flags:
|
|
||||||
|
|
||||||
```go
|
|
||||||
const (
|
|
||||||
// Safe normalizations
|
|
||||||
FlagLowercaseScheme NormalizationFlags = 1 << iota // HTTP://host -> http://host, applied by default in Go1.1
|
|
||||||
FlagLowercaseHost // http://HOST -> http://host
|
|
||||||
FlagUppercaseEscapes // http://host/t%ef -> http://host/t%EF
|
|
||||||
FlagDecodeUnnecessaryEscapes // http://host/t%41 -> http://host/tA
|
|
||||||
FlagEncodeNecessaryEscapes // http://host/!"#$ -> http://host/%21%22#$
|
|
||||||
FlagRemoveDefaultPort // http://host:80 -> http://host
|
|
||||||
FlagRemoveEmptyQuerySeparator // http://host/path? -> http://host/path
|
|
||||||
|
|
||||||
// Usually safe normalizations
|
|
||||||
FlagRemoveTrailingSlash // http://host/path/ -> http://host/path
|
|
||||||
FlagAddTrailingSlash // http://host/path -> http://host/path/ (should choose only one of these add/remove trailing slash flags)
|
|
||||||
FlagRemoveDotSegments // http://host/path/./a/b/../c -> http://host/path/a/c
|
|
||||||
|
|
||||||
// Unsafe normalizations
|
|
||||||
FlagRemoveDirectoryIndex // http://host/path/index.html -> http://host/path/
|
|
||||||
FlagRemoveFragment // http://host/path#fragment -> http://host/path
|
|
||||||
FlagForceHTTP // https://host -> http://host
|
|
||||||
FlagRemoveDuplicateSlashes // http://host/path//a///b -> http://host/path/a/b
|
|
||||||
FlagRemoveWWW // http://www.host/ -> http://host/
|
|
||||||
FlagAddWWW // http://host/ -> http://www.host/ (should choose only one of these add/remove WWW flags)
|
|
||||||
FlagSortQuery // http://host/path?c=3&b=2&a=1&b=1 -> http://host/path?a=1&b=1&b=2&c=3
|
|
||||||
|
|
||||||
// Normalizations not in the wikipedia article, required to cover tests cases
|
|
||||||
// submitted by jehiah
|
|
||||||
FlagDecodeDWORDHost // http://1113982867 -> http://66.102.7.147
|
|
||||||
FlagDecodeOctalHost // http://0102.0146.07.0223 -> http://66.102.7.147
|
|
||||||
FlagDecodeHexHost // http://0x42660793 -> http://66.102.7.147
|
|
||||||
FlagRemoveUnnecessaryHostDots // http://.host../path -> http://host/path
|
|
||||||
FlagRemoveEmptyPortSeparator // http://host:/path -> http://host/path
|
|
||||||
|
|
||||||
// Convenience set of safe normalizations
|
|
||||||
FlagsSafe NormalizationFlags = FlagLowercaseHost | FlagLowercaseScheme | FlagUppercaseEscapes | FlagDecodeUnnecessaryEscapes | FlagEncodeNecessaryEscapes | FlagRemoveDefaultPort | FlagRemoveEmptyQuerySeparator
|
|
||||||
|
|
||||||
// For convenience sets, "greedy" uses the "remove trailing slash" and "remove www. prefix" flags,
|
|
||||||
// while "non-greedy" uses the "add (or keep) the trailing slash" and "add www. prefix".
|
|
||||||
|
|
||||||
// Convenience set of usually safe normalizations (includes FlagsSafe)
|
|
||||||
FlagsUsuallySafeGreedy NormalizationFlags = FlagsSafe | FlagRemoveTrailingSlash | FlagRemoveDotSegments
|
|
||||||
FlagsUsuallySafeNonGreedy NormalizationFlags = FlagsSafe | FlagAddTrailingSlash | FlagRemoveDotSegments
|
|
||||||
|
|
||||||
// Convenience set of unsafe normalizations (includes FlagsUsuallySafe)
|
|
||||||
FlagsUnsafeGreedy NormalizationFlags = FlagsUsuallySafeGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagRemoveWWW | FlagSortQuery
|
|
||||||
FlagsUnsafeNonGreedy NormalizationFlags = FlagsUsuallySafeNonGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagAddWWW | FlagSortQuery
|
|
||||||
|
|
||||||
// Convenience set of all available flags
|
|
||||||
FlagsAllGreedy = FlagsUnsafeGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator
|
|
||||||
FlagsAllNonGreedy = FlagsUnsafeNonGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
For convenience, the set of flags `FlagsSafe`, `FlagsUsuallySafe[Greedy|NonGreedy]`, `FlagsUnsafe[Greedy|NonGreedy]` and `FlagsAll[Greedy|NonGreedy]` are provided for the similarly grouped normalizations on [wikipedia's URL normalization page][wiki]. You can add (using the bitwise OR `|` operator) or remove (using the bitwise AND NOT `&^` operator) individual flags from the sets if required, to build your own custom set.
|
|
||||||
|
|
||||||
The [full godoc reference is available on gopkgdoc][godoc].
|
|
||||||
|
|
||||||
Some things to note:
|
|
||||||
|
|
||||||
* `FlagDecodeUnnecessaryEscapes`, `FlagEncodeNecessaryEscapes`, `FlagUppercaseEscapes` and `FlagRemoveEmptyQuerySeparator` are always implicitly set, because internally, the URL string is parsed as an URL object, which automatically decodes unnecessary escapes, uppercases and encodes necessary ones, and removes empty query separators (an unnecessary `?` at the end of the url). So this operation cannot **not** be done. For this reason, `FlagRemoveEmptyQuerySeparator` (as well as the other three) has been included in the `FlagsSafe` convenience set, instead of `FlagsUnsafe`, where Wikipedia puts it.
|
|
||||||
|
|
||||||
* The `FlagDecodeUnnecessaryEscapes` decodes the following escapes (*from -> to*):
|
|
||||||
- %24 -> $
|
|
||||||
- %26 -> &
|
|
||||||
- %2B-%3B -> +,-./0123456789:;
|
|
||||||
- %3D -> =
|
|
||||||
- %40-%5A -> @ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
||||||
- %5F -> _
|
|
||||||
- %61-%7A -> abcdefghijklmnopqrstuvwxyz
|
|
||||||
- %7E -> ~
|
|
||||||
|
|
||||||
|
|
||||||
* When the `NormalizeURL` function is used (passing an URL object), this source URL object is modified (that is, after the call, the URL object will be modified to reflect the normalization).
|
|
||||||
|
|
||||||
* The *replace IP with domain name* normalization (`http://208.77.188.166/ → http://www.example.com/`) is obviously not possible for a library without making some network requests. This is not implemented in purell.
|
|
||||||
|
|
||||||
* The *remove unused query string parameters* and *remove default query parameters* are also not implemented, since this is a very case-specific normalization, and it is quite trivial to do with an URL object.
|
|
||||||
|
|
||||||
### Safe vs Usually Safe vs Unsafe
|
|
||||||
|
|
||||||
Purell allows you to control the level of risk you take while normalizing an URL. You can aggressively normalize, play it totally safe, or anything in between.
|
|
||||||
|
|
||||||
Consider the following URL:
|
|
||||||
|
|
||||||
`HTTPS://www.RooT.com/toto/t%45%1f///a/./b/../c/?z=3&w=2&a=4&w=1#invalid`
|
|
||||||
|
|
||||||
Normalizing with the `FlagsSafe` gives:
|
|
||||||
|
|
||||||
`https://www.root.com/toto/tE%1F///a/./b/../c/?z=3&w=2&a=4&w=1#invalid`
|
|
||||||
|
|
||||||
With the `FlagsUsuallySafeGreedy`:
|
|
||||||
|
|
||||||
`https://www.root.com/toto/tE%1F///a/c?z=3&w=2&a=4&w=1#invalid`
|
|
||||||
|
|
||||||
And with `FlagsUnsafeGreedy`:
|
|
||||||
|
|
||||||
`http://root.com/toto/tE%1F/a/c?a=4&w=1&w=2&z=3`
|
|
||||||
|
|
||||||
## TODOs
|
|
||||||
|
|
||||||
* Add a class/default instance to allow specifying custom directory index names? At the moment, removing directory index removes `(^|/)((?:default|index)\.\w{1,4})$`.
|
|
||||||
|
|
||||||
## Thanks / Contributions
|
|
||||||
|
|
||||||
@rogpeppe
|
|
||||||
@jehiah
|
|
||||||
@opennota
|
|
||||||
@pchristopher1275
|
|
||||||
@zenovich
|
|
||||||
@beeker1121
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
The [BSD 3-Clause license][bsd].
|
|
||||||
|
|
||||||
[bsd]: http://opensource.org/licenses/BSD-3-Clause
|
|
||||||
[wiki]: http://en.wikipedia.org/wiki/URL_normalization
|
|
||||||
[rfc]: http://tools.ietf.org/html/rfc3986#section-6
|
|
||||||
[godoc]: http://go.pkgdoc.org/github.com/PuerkitoBio/purell
|
|
||||||
[pr5]: https://github.com/PuerkitoBio/purell/pull/5
|
|
||||||
[iss7]: https://github.com/PuerkitoBio/purell/issues/7
|
|
379
vendor/github.com/PuerkitoBio/purell/purell.go
generated
vendored
379
vendor/github.com/PuerkitoBio/purell/purell.go
generated
vendored
@ -1,379 +0,0 @@
|
|||||||
/*
|
|
||||||
Package purell offers URL normalization as described on the wikipedia page:
|
|
||||||
http://en.wikipedia.org/wiki/URL_normalization
|
|
||||||
*/
|
|
||||||
package purell
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/PuerkitoBio/urlesc"
|
|
||||||
"golang.org/x/net/idna"
|
|
||||||
"golang.org/x/text/unicode/norm"
|
|
||||||
"golang.org/x/text/width"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A set of normalization flags determines how a URL will
|
|
||||||
// be normalized.
|
|
||||||
type NormalizationFlags uint
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Safe normalizations
|
|
||||||
FlagLowercaseScheme NormalizationFlags = 1 << iota // HTTP://host -> http://host, applied by default in Go1.1
|
|
||||||
FlagLowercaseHost // http://HOST -> http://host
|
|
||||||
FlagUppercaseEscapes // http://host/t%ef -> http://host/t%EF
|
|
||||||
FlagDecodeUnnecessaryEscapes // http://host/t%41 -> http://host/tA
|
|
||||||
FlagEncodeNecessaryEscapes // http://host/!"#$ -> http://host/%21%22#$
|
|
||||||
FlagRemoveDefaultPort // http://host:80 -> http://host
|
|
||||||
FlagRemoveEmptyQuerySeparator // http://host/path? -> http://host/path
|
|
||||||
|
|
||||||
// Usually safe normalizations
|
|
||||||
FlagRemoveTrailingSlash // http://host/path/ -> http://host/path
|
|
||||||
FlagAddTrailingSlash // http://host/path -> http://host/path/ (should choose only one of these add/remove trailing slash flags)
|
|
||||||
FlagRemoveDotSegments // http://host/path/./a/b/../c -> http://host/path/a/c
|
|
||||||
|
|
||||||
// Unsafe normalizations
|
|
||||||
FlagRemoveDirectoryIndex // http://host/path/index.html -> http://host/path/
|
|
||||||
FlagRemoveFragment // http://host/path#fragment -> http://host/path
|
|
||||||
FlagForceHTTP // https://host -> http://host
|
|
||||||
FlagRemoveDuplicateSlashes // http://host/path//a///b -> http://host/path/a/b
|
|
||||||
FlagRemoveWWW // http://www.host/ -> http://host/
|
|
||||||
FlagAddWWW // http://host/ -> http://www.host/ (should choose only one of these add/remove WWW flags)
|
|
||||||
FlagSortQuery // http://host/path?c=3&b=2&a=1&b=1 -> http://host/path?a=1&b=1&b=2&c=3
|
|
||||||
|
|
||||||
// Normalizations not in the wikipedia article, required to cover tests cases
|
|
||||||
// submitted by jehiah
|
|
||||||
FlagDecodeDWORDHost // http://1113982867 -> http://66.102.7.147
|
|
||||||
FlagDecodeOctalHost // http://0102.0146.07.0223 -> http://66.102.7.147
|
|
||||||
FlagDecodeHexHost // http://0x42660793 -> http://66.102.7.147
|
|
||||||
FlagRemoveUnnecessaryHostDots // http://.host../path -> http://host/path
|
|
||||||
FlagRemoveEmptyPortSeparator // http://host:/path -> http://host/path
|
|
||||||
|
|
||||||
// Convenience set of safe normalizations
|
|
||||||
FlagsSafe NormalizationFlags = FlagLowercaseHost | FlagLowercaseScheme | FlagUppercaseEscapes | FlagDecodeUnnecessaryEscapes | FlagEncodeNecessaryEscapes | FlagRemoveDefaultPort | FlagRemoveEmptyQuerySeparator
|
|
||||||
|
|
||||||
// For convenience sets, "greedy" uses the "remove trailing slash" and "remove www. prefix" flags,
|
|
||||||
// while "non-greedy" uses the "add (or keep) the trailing slash" and "add www. prefix".
|
|
||||||
|
|
||||||
// Convenience set of usually safe normalizations (includes FlagsSafe)
|
|
||||||
FlagsUsuallySafeGreedy NormalizationFlags = FlagsSafe | FlagRemoveTrailingSlash | FlagRemoveDotSegments
|
|
||||||
FlagsUsuallySafeNonGreedy NormalizationFlags = FlagsSafe | FlagAddTrailingSlash | FlagRemoveDotSegments
|
|
||||||
|
|
||||||
// Convenience set of unsafe normalizations (includes FlagsUsuallySafe)
|
|
||||||
FlagsUnsafeGreedy NormalizationFlags = FlagsUsuallySafeGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagRemoveWWW | FlagSortQuery
|
|
||||||
FlagsUnsafeNonGreedy NormalizationFlags = FlagsUsuallySafeNonGreedy | FlagRemoveDirectoryIndex | FlagRemoveFragment | FlagForceHTTP | FlagRemoveDuplicateSlashes | FlagAddWWW | FlagSortQuery
|
|
||||||
|
|
||||||
// Convenience set of all available flags
|
|
||||||
FlagsAllGreedy = FlagsUnsafeGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator
|
|
||||||
FlagsAllNonGreedy = FlagsUnsafeNonGreedy | FlagDecodeDWORDHost | FlagDecodeOctalHost | FlagDecodeHexHost | FlagRemoveUnnecessaryHostDots | FlagRemoveEmptyPortSeparator
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultHttpPort = ":80"
|
|
||||||
defaultHttpsPort = ":443"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Regular expressions used by the normalizations
|
|
||||||
var rxPort = regexp.MustCompile(`(:\d+)/?$`)
|
|
||||||
var rxDirIndex = regexp.MustCompile(`(^|/)((?:default|index)\.\w{1,4})$`)
|
|
||||||
var rxDupSlashes = regexp.MustCompile(`/{2,}`)
|
|
||||||
var rxDWORDHost = regexp.MustCompile(`^(\d+)((?:\.+)?(?:\:\d*)?)$`)
|
|
||||||
var rxOctalHost = regexp.MustCompile(`^(0\d*)\.(0\d*)\.(0\d*)\.(0\d*)((?:\.+)?(?:\:\d*)?)$`)
|
|
||||||
var rxHexHost = regexp.MustCompile(`^0x([0-9A-Fa-f]+)((?:\.+)?(?:\:\d*)?)$`)
|
|
||||||
var rxHostDots = regexp.MustCompile(`^(.+?)(:\d+)?$`)
|
|
||||||
var rxEmptyPort = regexp.MustCompile(`:+$`)
|
|
||||||
|
|
||||||
// Map of flags to implementation function.
|
|
||||||
// FlagDecodeUnnecessaryEscapes has no action, since it is done automatically
|
|
||||||
// by parsing the string as an URL. Same for FlagUppercaseEscapes and FlagRemoveEmptyQuerySeparator.
|
|
||||||
|
|
||||||
// Since maps have undefined traversing order, make a slice of ordered keys
|
|
||||||
var flagsOrder = []NormalizationFlags{
|
|
||||||
FlagLowercaseScheme,
|
|
||||||
FlagLowercaseHost,
|
|
||||||
FlagRemoveDefaultPort,
|
|
||||||
FlagRemoveDirectoryIndex,
|
|
||||||
FlagRemoveDotSegments,
|
|
||||||
FlagRemoveFragment,
|
|
||||||
FlagForceHTTP, // Must be after remove default port (because https=443/http=80)
|
|
||||||
FlagRemoveDuplicateSlashes,
|
|
||||||
FlagRemoveWWW,
|
|
||||||
FlagAddWWW,
|
|
||||||
FlagSortQuery,
|
|
||||||
FlagDecodeDWORDHost,
|
|
||||||
FlagDecodeOctalHost,
|
|
||||||
FlagDecodeHexHost,
|
|
||||||
FlagRemoveUnnecessaryHostDots,
|
|
||||||
FlagRemoveEmptyPortSeparator,
|
|
||||||
FlagRemoveTrailingSlash, // These two (add/remove trailing slash) must be last
|
|
||||||
FlagAddTrailingSlash,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ... and then the map, where order is unimportant
|
|
||||||
var flags = map[NormalizationFlags]func(*url.URL){
|
|
||||||
FlagLowercaseScheme: lowercaseScheme,
|
|
||||||
FlagLowercaseHost: lowercaseHost,
|
|
||||||
FlagRemoveDefaultPort: removeDefaultPort,
|
|
||||||
FlagRemoveDirectoryIndex: removeDirectoryIndex,
|
|
||||||
FlagRemoveDotSegments: removeDotSegments,
|
|
||||||
FlagRemoveFragment: removeFragment,
|
|
||||||
FlagForceHTTP: forceHTTP,
|
|
||||||
FlagRemoveDuplicateSlashes: removeDuplicateSlashes,
|
|
||||||
FlagRemoveWWW: removeWWW,
|
|
||||||
FlagAddWWW: addWWW,
|
|
||||||
FlagSortQuery: sortQuery,
|
|
||||||
FlagDecodeDWORDHost: decodeDWORDHost,
|
|
||||||
FlagDecodeOctalHost: decodeOctalHost,
|
|
||||||
FlagDecodeHexHost: decodeHexHost,
|
|
||||||
FlagRemoveUnnecessaryHostDots: removeUnncessaryHostDots,
|
|
||||||
FlagRemoveEmptyPortSeparator: removeEmptyPortSeparator,
|
|
||||||
FlagRemoveTrailingSlash: removeTrailingSlash,
|
|
||||||
FlagAddTrailingSlash: addTrailingSlash,
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustNormalizeURLString returns the normalized string, and panics if an error occurs.
|
|
||||||
// It takes an URL string as input, as well as the normalization flags.
|
|
||||||
func MustNormalizeURLString(u string, f NormalizationFlags) string {
|
|
||||||
result, e := NormalizeURLString(u, f)
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// NormalizeURLString returns the normalized string, or an error if it can't be parsed into an URL object.
|
|
||||||
// It takes an URL string as input, as well as the normalization flags.
|
|
||||||
func NormalizeURLString(u string, f NormalizationFlags) (string, error) {
|
|
||||||
parsed, err := url.Parse(u)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if f&FlagLowercaseHost == FlagLowercaseHost {
|
|
||||||
parsed.Host = strings.ToLower(parsed.Host)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The idna package doesn't fully conform to RFC 5895
|
|
||||||
// (https://tools.ietf.org/html/rfc5895), so we do it here.
|
|
||||||
// Taken from Go 1.8 cycle source, courtesy of bradfitz.
|
|
||||||
// TODO: Remove when (if?) idna package conforms to RFC 5895.
|
|
||||||
parsed.Host = width.Fold.String(parsed.Host)
|
|
||||||
parsed.Host = norm.NFC.String(parsed.Host)
|
|
||||||
if parsed.Host, err = idna.ToASCII(parsed.Host); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return NormalizeURL(parsed, f), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NormalizeURL returns the normalized string.
|
|
||||||
// It takes a parsed URL object as input, as well as the normalization flags.
|
|
||||||
func NormalizeURL(u *url.URL, f NormalizationFlags) string {
|
|
||||||
for _, k := range flagsOrder {
|
|
||||||
if f&k == k {
|
|
||||||
flags[k](u)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return urlesc.Escape(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
func lowercaseScheme(u *url.URL) {
|
|
||||||
if len(u.Scheme) > 0 {
|
|
||||||
u.Scheme = strings.ToLower(u.Scheme)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func lowercaseHost(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
u.Host = strings.ToLower(u.Host)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeDefaultPort(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
scheme := strings.ToLower(u.Scheme)
|
|
||||||
u.Host = rxPort.ReplaceAllStringFunc(u.Host, func(val string) string {
|
|
||||||
if (scheme == "http" && val == defaultHttpPort) || (scheme == "https" && val == defaultHttpsPort) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return val
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeTrailingSlash(u *url.URL) {
|
|
||||||
if l := len(u.Path); l > 0 {
|
|
||||||
if strings.HasSuffix(u.Path, "/") {
|
|
||||||
u.Path = u.Path[:l-1]
|
|
||||||
}
|
|
||||||
} else if l = len(u.Host); l > 0 {
|
|
||||||
if strings.HasSuffix(u.Host, "/") {
|
|
||||||
u.Host = u.Host[:l-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addTrailingSlash(u *url.URL) {
|
|
||||||
if l := len(u.Path); l > 0 {
|
|
||||||
if !strings.HasSuffix(u.Path, "/") {
|
|
||||||
u.Path += "/"
|
|
||||||
}
|
|
||||||
} else if l = len(u.Host); l > 0 {
|
|
||||||
if !strings.HasSuffix(u.Host, "/") {
|
|
||||||
u.Host += "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeDotSegments(u *url.URL) {
|
|
||||||
if len(u.Path) > 0 {
|
|
||||||
var dotFree []string
|
|
||||||
var lastIsDot bool
|
|
||||||
|
|
||||||
sections := strings.Split(u.Path, "/")
|
|
||||||
for _, s := range sections {
|
|
||||||
if s == ".." {
|
|
||||||
if len(dotFree) > 0 {
|
|
||||||
dotFree = dotFree[:len(dotFree)-1]
|
|
||||||
}
|
|
||||||
} else if s != "." {
|
|
||||||
dotFree = append(dotFree, s)
|
|
||||||
}
|
|
||||||
lastIsDot = (s == "." || s == "..")
|
|
||||||
}
|
|
||||||
// Special case if host does not end with / and new path does not begin with /
|
|
||||||
u.Path = strings.Join(dotFree, "/")
|
|
||||||
if u.Host != "" && !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
|
|
||||||
u.Path = "/" + u.Path
|
|
||||||
}
|
|
||||||
// Special case if the last segment was a dot, make sure the path ends with a slash
|
|
||||||
if lastIsDot && !strings.HasSuffix(u.Path, "/") {
|
|
||||||
u.Path += "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeDirectoryIndex(u *url.URL) {
|
|
||||||
if len(u.Path) > 0 {
|
|
||||||
u.Path = rxDirIndex.ReplaceAllString(u.Path, "$1")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeFragment(u *url.URL) {
|
|
||||||
u.Fragment = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func forceHTTP(u *url.URL) {
|
|
||||||
if strings.ToLower(u.Scheme) == "https" {
|
|
||||||
u.Scheme = "http"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeDuplicateSlashes(u *url.URL) {
|
|
||||||
if len(u.Path) > 0 {
|
|
||||||
u.Path = rxDupSlashes.ReplaceAllString(u.Path, "/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeWWW(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 && strings.HasPrefix(strings.ToLower(u.Host), "www.") {
|
|
||||||
u.Host = u.Host[4:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addWWW(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 && !strings.HasPrefix(strings.ToLower(u.Host), "www.") {
|
|
||||||
u.Host = "www." + u.Host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortQuery(u *url.URL) {
|
|
||||||
q := u.Query()
|
|
||||||
|
|
||||||
if len(q) > 0 {
|
|
||||||
arKeys := make([]string, len(q))
|
|
||||||
i := 0
|
|
||||||
for k := range q {
|
|
||||||
arKeys[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
sort.Strings(arKeys)
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
for _, k := range arKeys {
|
|
||||||
sort.Strings(q[k])
|
|
||||||
for _, v := range q[k] {
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
buf.WriteRune('&')
|
|
||||||
}
|
|
||||||
buf.WriteString(fmt.Sprintf("%s=%s", k, urlesc.QueryEscape(v)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild the raw query string
|
|
||||||
u.RawQuery = buf.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeDWORDHost(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
if matches := rxDWORDHost.FindStringSubmatch(u.Host); len(matches) > 2 {
|
|
||||||
var parts [4]int64
|
|
||||||
|
|
||||||
dword, _ := strconv.ParseInt(matches[1], 10, 0)
|
|
||||||
for i, shift := range []uint{24, 16, 8, 0} {
|
|
||||||
parts[i] = dword >> shift & 0xFF
|
|
||||||
}
|
|
||||||
u.Host = fmt.Sprintf("%d.%d.%d.%d%s", parts[0], parts[1], parts[2], parts[3], matches[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeOctalHost(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
if matches := rxOctalHost.FindStringSubmatch(u.Host); len(matches) > 5 {
|
|
||||||
var parts [4]int64
|
|
||||||
|
|
||||||
for i := 1; i <= 4; i++ {
|
|
||||||
parts[i-1], _ = strconv.ParseInt(matches[i], 8, 0)
|
|
||||||
}
|
|
||||||
u.Host = fmt.Sprintf("%d.%d.%d.%d%s", parts[0], parts[1], parts[2], parts[3], matches[5])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeHexHost(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
if matches := rxHexHost.FindStringSubmatch(u.Host); len(matches) > 2 {
|
|
||||||
// Conversion is safe because of regex validation
|
|
||||||
parsed, _ := strconv.ParseInt(matches[1], 16, 0)
|
|
||||||
// Set host as DWORD (base 10) encoded host
|
|
||||||
u.Host = fmt.Sprintf("%d%s", parsed, matches[2])
|
|
||||||
// The rest is the same as decoding a DWORD host
|
|
||||||
decodeDWORDHost(u)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeUnncessaryHostDots(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
if matches := rxHostDots.FindStringSubmatch(u.Host); len(matches) > 1 {
|
|
||||||
// Trim the leading and trailing dots
|
|
||||||
u.Host = strings.Trim(matches[1], ".")
|
|
||||||
if len(matches) > 2 {
|
|
||||||
u.Host += matches[2]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func removeEmptyPortSeparator(u *url.URL) {
|
|
||||||
if len(u.Host) > 0 {
|
|
||||||
u.Host = rxEmptyPort.ReplaceAllString(u.Host, "")
|
|
||||||
}
|
|
||||||
}
|
|
15
vendor/github.com/PuerkitoBio/urlesc/.travis.yml
generated
vendored
15
vendor/github.com/PuerkitoBio/urlesc/.travis.yml
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.4.x
|
|
||||||
- 1.5.x
|
|
||||||
- 1.6.x
|
|
||||||
- 1.7.x
|
|
||||||
- 1.8.x
|
|
||||||
- tip
|
|
||||||
|
|
||||||
install:
|
|
||||||
- go build .
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go test -v
|
|
27
vendor/github.com/PuerkitoBio/urlesc/LICENSE
generated
vendored
27
vendor/github.com/PuerkitoBio/urlesc/LICENSE
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
Copyright (c) 2012 The Go Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
16
vendor/github.com/PuerkitoBio/urlesc/README.md
generated
vendored
16
vendor/github.com/PuerkitoBio/urlesc/README.md
generated
vendored
@ -1,16 +0,0 @@
|
|||||||
urlesc [](https://travis-ci.org/PuerkitoBio/urlesc) [](http://godoc.org/github.com/PuerkitoBio/urlesc)
|
|
||||||
======
|
|
||||||
|
|
||||||
Package urlesc implements query escaping as per RFC 3986.
|
|
||||||
|
|
||||||
It contains some parts of the net/url package, modified so as to allow
|
|
||||||
some reserved characters incorrectly escaped by net/url (see [issue 5684](https://github.com/golang/go/issues/5684)).
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
go get github.com/PuerkitoBio/urlesc
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Go license (BSD-3-Clause)
|
|
||||||
|
|
180
vendor/github.com/PuerkitoBio/urlesc/urlesc.go
generated
vendored
180
vendor/github.com/PuerkitoBio/urlesc/urlesc.go
generated
vendored
@ -1,180 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package urlesc implements query escaping as per RFC 3986.
|
|
||||||
// It contains some parts of the net/url package, modified so as to allow
|
|
||||||
// some reserved characters incorrectly escaped by net/url.
|
|
||||||
// See https://github.com/golang/go/issues/5684
|
|
||||||
package urlesc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type encoding int
|
|
||||||
|
|
||||||
const (
|
|
||||||
encodePath encoding = 1 + iota
|
|
||||||
encodeUserPassword
|
|
||||||
encodeQueryComponent
|
|
||||||
encodeFragment
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return true if the specified character should be escaped when
|
|
||||||
// appearing in a URL string, according to RFC 3986.
|
|
||||||
func shouldEscape(c byte, mode encoding) bool {
|
|
||||||
// §2.3 Unreserved characters (alphanum)
|
|
||||||
if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
switch c {
|
|
||||||
case '-', '.', '_', '~': // §2.3 Unreserved characters (mark)
|
|
||||||
return false
|
|
||||||
|
|
||||||
// §2.2 Reserved characters (reserved)
|
|
||||||
case ':', '/', '?', '#', '[', ']', '@', // gen-delims
|
|
||||||
'!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=': // sub-delims
|
|
||||||
// Different sections of the URL allow a few of
|
|
||||||
// the reserved characters to appear unescaped.
|
|
||||||
switch mode {
|
|
||||||
case encodePath: // §3.3
|
|
||||||
// The RFC allows sub-delims and : @.
|
|
||||||
// '/', '[' and ']' can be used to assign meaning to individual path
|
|
||||||
// segments. This package only manipulates the path as a whole,
|
|
||||||
// so we allow those as well. That leaves only ? and # to escape.
|
|
||||||
return c == '?' || c == '#'
|
|
||||||
|
|
||||||
case encodeUserPassword: // §3.2.1
|
|
||||||
// The RFC allows : and sub-delims in
|
|
||||||
// userinfo. The parsing of userinfo treats ':' as special so we must escape
|
|
||||||
// all the gen-delims.
|
|
||||||
return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' || c == ']' || c == '@'
|
|
||||||
|
|
||||||
case encodeQueryComponent: // §3.4
|
|
||||||
// The RFC allows / and ?.
|
|
||||||
return c != '/' && c != '?'
|
|
||||||
|
|
||||||
case encodeFragment: // §4.1
|
|
||||||
// The RFC text is silent but the grammar allows
|
|
||||||
// everything, so escape nothing but #
|
|
||||||
return c == '#'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Everything else must be escaped.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryEscape escapes the string so it can be safely placed
|
|
||||||
// inside a URL query.
|
|
||||||
func QueryEscape(s string) string {
|
|
||||||
return escape(s, encodeQueryComponent)
|
|
||||||
}
|
|
||||||
|
|
||||||
func escape(s string, mode encoding) string {
|
|
||||||
spaceCount, hexCount := 0, 0
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
c := s[i]
|
|
||||||
if shouldEscape(c, mode) {
|
|
||||||
if c == ' ' && mode == encodeQueryComponent {
|
|
||||||
spaceCount++
|
|
||||||
} else {
|
|
||||||
hexCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if spaceCount == 0 && hexCount == 0 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
t := make([]byte, len(s)+2*hexCount)
|
|
||||||
j := 0
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
switch c := s[i]; {
|
|
||||||
case c == ' ' && mode == encodeQueryComponent:
|
|
||||||
t[j] = '+'
|
|
||||||
j++
|
|
||||||
case shouldEscape(c, mode):
|
|
||||||
t[j] = '%'
|
|
||||||
t[j+1] = "0123456789ABCDEF"[c>>4]
|
|
||||||
t[j+2] = "0123456789ABCDEF"[c&15]
|
|
||||||
j += 3
|
|
||||||
default:
|
|
||||||
t[j] = s[i]
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
var uiReplacer = strings.NewReplacer(
|
|
||||||
"%21", "!",
|
|
||||||
"%27", "'",
|
|
||||||
"%28", "(",
|
|
||||||
"%29", ")",
|
|
||||||
"%2A", "*",
|
|
||||||
)
|
|
||||||
|
|
||||||
// unescapeUserinfo unescapes some characters that need not to be escaped as per RFC3986.
|
|
||||||
func unescapeUserinfo(s string) string {
|
|
||||||
return uiReplacer.Replace(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escape reassembles the URL into a valid URL string.
|
|
||||||
// The general form of the result is one of:
|
|
||||||
//
|
|
||||||
// scheme:opaque
|
|
||||||
// scheme://userinfo@host/path?query#fragment
|
|
||||||
//
|
|
||||||
// If u.Opaque is non-empty, String uses the first form;
|
|
||||||
// otherwise it uses the second form.
|
|
||||||
//
|
|
||||||
// In the second form, the following rules apply:
|
|
||||||
// - if u.Scheme is empty, scheme: is omitted.
|
|
||||||
// - if u.User is nil, userinfo@ is omitted.
|
|
||||||
// - if u.Host is empty, host/ is omitted.
|
|
||||||
// - if u.Scheme and u.Host are empty and u.User is nil,
|
|
||||||
// the entire scheme://userinfo@host/ is omitted.
|
|
||||||
// - if u.Host is non-empty and u.Path begins with a /,
|
|
||||||
// the form host/path does not add its own /.
|
|
||||||
// - if u.RawQuery is empty, ?query is omitted.
|
|
||||||
// - if u.Fragment is empty, #fragment is omitted.
|
|
||||||
func Escape(u *url.URL) string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if u.Scheme != "" {
|
|
||||||
buf.WriteString(u.Scheme)
|
|
||||||
buf.WriteByte(':')
|
|
||||||
}
|
|
||||||
if u.Opaque != "" {
|
|
||||||
buf.WriteString(u.Opaque)
|
|
||||||
} else {
|
|
||||||
if u.Scheme != "" || u.Host != "" || u.User != nil {
|
|
||||||
buf.WriteString("//")
|
|
||||||
if ui := u.User; ui != nil {
|
|
||||||
buf.WriteString(unescapeUserinfo(ui.String()))
|
|
||||||
buf.WriteByte('@')
|
|
||||||
}
|
|
||||||
if h := u.Host; h != "" {
|
|
||||||
buf.WriteString(h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
|
|
||||||
buf.WriteByte('/')
|
|
||||||
}
|
|
||||||
buf.WriteString(escape(u.Path, encodePath))
|
|
||||||
}
|
|
||||||
if u.RawQuery != "" {
|
|
||||||
buf.WriteByte('?')
|
|
||||||
buf.WriteString(u.RawQuery)
|
|
||||||
}
|
|
||||||
if u.Fragment != "" {
|
|
||||||
buf.WriteByte('#')
|
|
||||||
buf.WriteString(escape(u.Fragment, encodeFragment))
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
26
vendor/github.com/go-openapi/jsonpointer/.editorconfig
generated
vendored
26
vendor/github.com/go-openapi/jsonpointer/.editorconfig
generated
vendored
@ -1,26 +0,0 @@
|
|||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
# Unix-style newlines with a newline ending every file
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
|
|
||||||
# Set default charset
|
|
||||||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
|
|
||||||
charset = utf-8
|
|
||||||
|
|
||||||
# Tab indentation (no size specified)
|
|
||||||
[*.go]
|
|
||||||
indent_style = tab
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
# Matches the exact files either package.json or .travis.yml
|
|
||||||
[{package.json,.travis.yml}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
1
vendor/github.com/go-openapi/jsonpointer/.gitignore
generated
vendored
1
vendor/github.com/go-openapi/jsonpointer/.gitignore
generated
vendored
@ -1 +0,0 @@
|
|||||||
secrets.yml
|
|
15
vendor/github.com/go-openapi/jsonpointer/.travis.yml
generated
vendored
15
vendor/github.com/go-openapi/jsonpointer/.travis.yml
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
go:
|
|
||||||
- 1.14.x
|
|
||||||
- 1.15.x
|
|
||||||
install:
|
|
||||||
- GO111MODULE=off go get -u gotest.tools/gotestsum
|
|
||||||
env:
|
|
||||||
- GO111MODULE=on
|
|
||||||
language: go
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: a5VgoiwB1G/AZqzmephPZIhEB9avMlsWSlVnM1dSAtYAwdrQHGTQxAmpOxYIoSPDhWNN5bfZmjd29++UlTwLcHSR+e0kJhH6IfDlsHj/HplNCJ9tyI0zYc7XchtdKgeMxMzBKCzgwFXGSbQGydXTliDNBo0HOzmY3cou/daMFTP60K+offcjS+3LRAYb1EroSRXZqrk1nuF/xDL3792DZUdPMiFR/L/Df6y74D6/QP4sTkTDFQitz4Wy/7jbsfj8dG6qK2zivgV6/l+w4OVjFkxVpPXogDWY10vVXNVynqxfJ7to2d1I9lNCHE2ilBCkWMIPdyJF7hjF8pKW+82yP4EzRh0vu8Xn0HT5MZpQxdRY/YMxNrWaG7SxsoEaO4q5uhgdzAqLYY3TRa7MjIK+7Ur+aqOeTXn6OKwVi0CjvZ6mIU3WUKSwiwkFZMbjRAkSb5CYwMEfGFO/z964xz83qGt6WAtBXNotqCQpTIiKtDHQeLOMfksHImCg6JLhQcWBVxamVgu0G3Pdh8Y6DyPnxraXY95+QDavbjqv7TeYT9T/FNnrkXaTTK0s4iWE5H4ACU0Qvz0wUYgfQrZv0/Hp7V17+rabUwnzYySHCy9SWX/7OV9Cfh31iMp9ZIffr76xmmThtOEqs8TrTtU6BWI3rWwvA9cXQipZTVtL0oswrGw=
|
|
||||||
script:
|
|
||||||
- gotestsum -f short-verbose -- -race -coverprofile=coverage.txt -covermode=atomic ./...
|
|
74
vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md
generated
vendored
74
vendor/github.com/go-openapi/jsonpointer/CODE_OF_CONDUCT.md
generated
vendored
@ -1,74 +0,0 @@
|
|||||||
# Contributor Covenant Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
|
||||||
contributors and maintainers pledge to making participation in our project and
|
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity and
|
|
||||||
orientation.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
|
||||||
include:
|
|
||||||
|
|
||||||
* Using welcoming and inclusive language
|
|
||||||
* Being respectful of differing viewpoints and experiences
|
|
||||||
* Gracefully accepting constructive criticism
|
|
||||||
* Focusing on what is best for the community
|
|
||||||
* Showing empathy towards other community members
|
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
||||||
advances
|
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or electronic
|
|
||||||
address, without explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
## Our Responsibilities
|
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable
|
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
|
||||||
response to any instances of unacceptable behavior.
|
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or
|
|
||||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
||||||
permanently any contributor for other behaviors that they deem inappropriate,
|
|
||||||
threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
|
||||||
when an individual is representing the project or its community. Examples of
|
|
||||||
representing a project or community include using an official project e-mail
|
|
||||||
address, posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event. Representation of a project may be
|
|
||||||
further defined and clarified by project maintainers.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
|
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
||||||
Further details of specific enforcement policies may be posted separately.
|
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
||||||
faith may face temporary or permanent repercussions as determined by other
|
|
||||||
members of the project's leadership.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
||||||
available at [http://contributor-covenant.org/version/1/4][version]
|
|
||||||
|
|
||||||
[homepage]: http://contributor-covenant.org
|
|
||||||
[version]: http://contributor-covenant.org/version/1/4/
|
|
202
vendor/github.com/go-openapi/jsonpointer/LICENSE
generated
vendored
202
vendor/github.com/go-openapi/jsonpointer/LICENSE
generated
vendored
@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
15
vendor/github.com/go-openapi/jsonpointer/README.md
generated
vendored
15
vendor/github.com/go-openapi/jsonpointer/README.md
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
# gojsonpointer [](https://travis-ci.org/go-openapi/jsonpointer) [](https://codecov.io/gh/go-openapi/jsonpointer) [](https://slackin.goswagger.io)
|
|
||||||
|
|
||||||
[](https://raw.githubusercontent.com/go-openapi/jsonpointer/master/LICENSE) [](http://godoc.org/github.com/go-openapi/jsonpointer)
|
|
||||||
An implementation of JSON Pointer - Go language
|
|
||||||
|
|
||||||
## Status
|
|
||||||
Completed YES
|
|
||||||
|
|
||||||
Tested YES
|
|
||||||
|
|
||||||
## References
|
|
||||||
http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
|
|
||||||
|
|
||||||
### Note
|
|
||||||
The 4.Evaluation part of the previous reference, starting with 'If the currently referenced value is a JSON array, the reference token MUST contain either...' is not implemented.
|
|
9
vendor/github.com/go-openapi/jsonpointer/go.mod
generated
vendored
9
vendor/github.com/go-openapi/jsonpointer/go.mod
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
module github.com/go-openapi/jsonpointer
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/go-openapi/swag v0.19.5
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
|
|
||||||
github.com/stretchr/testify v1.3.0
|
|
||||||
)
|
|
||||||
|
|
||||||
go 1.13
|
|
24
vendor/github.com/go-openapi/jsonpointer/go.sum
generated
vendored
24
vendor/github.com/go-openapi/jsonpointer/go.sum
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63 h1:nTT4s92Dgz2HlrB2NaMgvlfqHH39OgMhA7z3PK7PGD4=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
390
vendor/github.com/go-openapi/jsonpointer/pointer.go
generated
vendored
390
vendor/github.com/go-openapi/jsonpointer/pointer.go
generated
vendored
@ -1,390 +0,0 @@
|
|||||||
// Copyright 2013 sigu-399 ( https://github.com/sigu-399 )
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// author sigu-399
|
|
||||||
// author-github https://github.com/sigu-399
|
|
||||||
// author-mail sigu.399@gmail.com
|
|
||||||
//
|
|
||||||
// repository-name jsonpointer
|
|
||||||
// repository-desc An implementation of JSON Pointer - Go language
|
|
||||||
//
|
|
||||||
// description Main and unique file.
|
|
||||||
//
|
|
||||||
// created 25-02-2013
|
|
||||||
|
|
||||||
package jsonpointer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
emptyPointer = ``
|
|
||||||
pointerSeparator = `/`
|
|
||||||
|
|
||||||
invalidStart = `JSON pointer must be empty or start with a "` + pointerSeparator
|
|
||||||
)
|
|
||||||
|
|
||||||
var jsonPointableType = reflect.TypeOf(new(JSONPointable)).Elem()
|
|
||||||
var jsonSetableType = reflect.TypeOf(new(JSONSetable)).Elem()
|
|
||||||
|
|
||||||
// JSONPointable is an interface for structs to implement when they need to customize the
|
|
||||||
// json pointer process
|
|
||||||
type JSONPointable interface {
|
|
||||||
JSONLookup(string) (interface{}, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONSetable is an interface for structs to implement when they need to customize the
|
|
||||||
// json pointer process
|
|
||||||
type JSONSetable interface {
|
|
||||||
JSONSet(string, interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new json pointer for the given string
|
|
||||||
func New(jsonPointerString string) (Pointer, error) {
|
|
||||||
|
|
||||||
var p Pointer
|
|
||||||
err := p.parse(jsonPointerString)
|
|
||||||
return p, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pointer the json pointer reprsentation
|
|
||||||
type Pointer struct {
|
|
||||||
referenceTokens []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Constructor", parses the given string JSON pointer
|
|
||||||
func (p *Pointer) parse(jsonPointerString string) error {
|
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if jsonPointerString != emptyPointer {
|
|
||||||
if !strings.HasPrefix(jsonPointerString, pointerSeparator) {
|
|
||||||
err = errors.New(invalidStart)
|
|
||||||
} else {
|
|
||||||
referenceTokens := strings.Split(jsonPointerString, pointerSeparator)
|
|
||||||
for _, referenceToken := range referenceTokens[1:] {
|
|
||||||
p.referenceTokens = append(p.referenceTokens, referenceToken)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get uses the pointer to retrieve a value from a JSON document
|
|
||||||
func (p *Pointer) Get(document interface{}) (interface{}, reflect.Kind, error) {
|
|
||||||
return p.get(document, swag.DefaultJSONNameProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set uses the pointer to set a value from a JSON document
|
|
||||||
func (p *Pointer) Set(document interface{}, value interface{}) (interface{}, error) {
|
|
||||||
return document, p.set(document, value, swag.DefaultJSONNameProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetForToken gets a value for a json pointer token 1 level deep
|
|
||||||
func GetForToken(document interface{}, decodedToken string) (interface{}, reflect.Kind, error) {
|
|
||||||
return getSingleImpl(document, decodedToken, swag.DefaultJSONNameProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetForToken gets a value for a json pointer token 1 level deep
|
|
||||||
func SetForToken(document interface{}, decodedToken string, value interface{}) (interface{}, error) {
|
|
||||||
return document, setSingleImpl(document, value, decodedToken, swag.DefaultJSONNameProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSingleImpl(node interface{}, decodedToken string, nameProvider *swag.NameProvider) (interface{}, reflect.Kind, error) {
|
|
||||||
rValue := reflect.Indirect(reflect.ValueOf(node))
|
|
||||||
kind := rValue.Kind()
|
|
||||||
|
|
||||||
if rValue.Type().Implements(jsonPointableType) {
|
|
||||||
r, err := node.(JSONPointable).JSONLookup(decodedToken)
|
|
||||||
if err != nil {
|
|
||||||
return nil, kind, err
|
|
||||||
}
|
|
||||||
return r, kind, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch kind {
|
|
||||||
case reflect.Struct:
|
|
||||||
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
|
|
||||||
if !ok {
|
|
||||||
return nil, kind, fmt.Errorf("object has no field %q", decodedToken)
|
|
||||||
}
|
|
||||||
fld := rValue.FieldByName(nm)
|
|
||||||
return fld.Interface(), kind, nil
|
|
||||||
|
|
||||||
case reflect.Map:
|
|
||||||
kv := reflect.ValueOf(decodedToken)
|
|
||||||
mv := rValue.MapIndex(kv)
|
|
||||||
|
|
||||||
if mv.IsValid() {
|
|
||||||
return mv.Interface(), kind, nil
|
|
||||||
}
|
|
||||||
return nil, kind, fmt.Errorf("object has no key %q", decodedToken)
|
|
||||||
|
|
||||||
case reflect.Slice:
|
|
||||||
tokenIndex, err := strconv.Atoi(decodedToken)
|
|
||||||
if err != nil {
|
|
||||||
return nil, kind, err
|
|
||||||
}
|
|
||||||
sLength := rValue.Len()
|
|
||||||
if tokenIndex < 0 || tokenIndex >= sLength {
|
|
||||||
return nil, kind, fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength-1, tokenIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
elem := rValue.Index(tokenIndex)
|
|
||||||
return elem.Interface(), kind, nil
|
|
||||||
|
|
||||||
default:
|
|
||||||
return nil, kind, fmt.Errorf("invalid token reference %q", decodedToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func setSingleImpl(node, data interface{}, decodedToken string, nameProvider *swag.NameProvider) error {
|
|
||||||
rValue := reflect.Indirect(reflect.ValueOf(node))
|
|
||||||
|
|
||||||
if ns, ok := node.(JSONSetable); ok { // pointer impl
|
|
||||||
return ns.JSONSet(decodedToken, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rValue.Type().Implements(jsonSetableType) {
|
|
||||||
return node.(JSONSetable).JSONSet(decodedToken, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch rValue.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("object has no field %q", decodedToken)
|
|
||||||
}
|
|
||||||
fld := rValue.FieldByName(nm)
|
|
||||||
if fld.IsValid() {
|
|
||||||
fld.Set(reflect.ValueOf(data))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
|
|
||||||
case reflect.Map:
|
|
||||||
kv := reflect.ValueOf(decodedToken)
|
|
||||||
rValue.SetMapIndex(kv, reflect.ValueOf(data))
|
|
||||||
return nil
|
|
||||||
|
|
||||||
case reflect.Slice:
|
|
||||||
tokenIndex, err := strconv.Atoi(decodedToken)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sLength := rValue.Len()
|
|
||||||
if tokenIndex < 0 || tokenIndex >= sLength {
|
|
||||||
return fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength, tokenIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
elem := rValue.Index(tokenIndex)
|
|
||||||
if !elem.CanSet() {
|
|
||||||
return fmt.Errorf("can't set slice index %s to %v", decodedToken, data)
|
|
||||||
}
|
|
||||||
elem.Set(reflect.ValueOf(data))
|
|
||||||
return nil
|
|
||||||
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid token reference %q", decodedToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pointer) get(node interface{}, nameProvider *swag.NameProvider) (interface{}, reflect.Kind, error) {
|
|
||||||
|
|
||||||
if nameProvider == nil {
|
|
||||||
nameProvider = swag.DefaultJSONNameProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
kind := reflect.Invalid
|
|
||||||
|
|
||||||
// Full document when empty
|
|
||||||
if len(p.referenceTokens) == 0 {
|
|
||||||
return node, kind, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, token := range p.referenceTokens {
|
|
||||||
|
|
||||||
decodedToken := Unescape(token)
|
|
||||||
|
|
||||||
r, knd, err := getSingleImpl(node, decodedToken, nameProvider)
|
|
||||||
if err != nil {
|
|
||||||
return nil, knd, err
|
|
||||||
}
|
|
||||||
node, kind = r, knd
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rValue := reflect.ValueOf(node)
|
|
||||||
kind = rValue.Kind()
|
|
||||||
|
|
||||||
return node, kind, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pointer) set(node, data interface{}, nameProvider *swag.NameProvider) error {
|
|
||||||
knd := reflect.ValueOf(node).Kind()
|
|
||||||
|
|
||||||
if knd != reflect.Ptr && knd != reflect.Struct && knd != reflect.Map && knd != reflect.Slice && knd != reflect.Array {
|
|
||||||
return fmt.Errorf("only structs, pointers, maps and slices are supported for setting values")
|
|
||||||
}
|
|
||||||
|
|
||||||
if nameProvider == nil {
|
|
||||||
nameProvider = swag.DefaultJSONNameProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
// Full document when empty
|
|
||||||
if len(p.referenceTokens) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lastI := len(p.referenceTokens) - 1
|
|
||||||
for i, token := range p.referenceTokens {
|
|
||||||
isLastToken := i == lastI
|
|
||||||
decodedToken := Unescape(token)
|
|
||||||
|
|
||||||
if isLastToken {
|
|
||||||
|
|
||||||
return setSingleImpl(node, data, decodedToken, nameProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
rValue := reflect.Indirect(reflect.ValueOf(node))
|
|
||||||
kind := rValue.Kind()
|
|
||||||
|
|
||||||
if rValue.Type().Implements(jsonPointableType) {
|
|
||||||
r, err := node.(JSONPointable).JSONLookup(decodedToken)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fld := reflect.ValueOf(r)
|
|
||||||
if fld.CanAddr() && fld.Kind() != reflect.Interface && fld.Kind() != reflect.Map && fld.Kind() != reflect.Slice && fld.Kind() != reflect.Ptr {
|
|
||||||
node = fld.Addr().Interface()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node = r
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch kind {
|
|
||||||
case reflect.Struct:
|
|
||||||
nm, ok := nameProvider.GetGoNameForType(rValue.Type(), decodedToken)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("object has no field %q", decodedToken)
|
|
||||||
}
|
|
||||||
fld := rValue.FieldByName(nm)
|
|
||||||
if fld.CanAddr() && fld.Kind() != reflect.Interface && fld.Kind() != reflect.Map && fld.Kind() != reflect.Slice && fld.Kind() != reflect.Ptr {
|
|
||||||
node = fld.Addr().Interface()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node = fld.Interface()
|
|
||||||
|
|
||||||
case reflect.Map:
|
|
||||||
kv := reflect.ValueOf(decodedToken)
|
|
||||||
mv := rValue.MapIndex(kv)
|
|
||||||
|
|
||||||
if !mv.IsValid() {
|
|
||||||
return fmt.Errorf("object has no key %q", decodedToken)
|
|
||||||
}
|
|
||||||
if mv.CanAddr() && mv.Kind() != reflect.Interface && mv.Kind() != reflect.Map && mv.Kind() != reflect.Slice && mv.Kind() != reflect.Ptr {
|
|
||||||
node = mv.Addr().Interface()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node = mv.Interface()
|
|
||||||
|
|
||||||
case reflect.Slice:
|
|
||||||
tokenIndex, err := strconv.Atoi(decodedToken)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sLength := rValue.Len()
|
|
||||||
if tokenIndex < 0 || tokenIndex >= sLength {
|
|
||||||
return fmt.Errorf("index out of bounds array[0,%d] index '%d'", sLength, tokenIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
elem := rValue.Index(tokenIndex)
|
|
||||||
if elem.CanAddr() && elem.Kind() != reflect.Interface && elem.Kind() != reflect.Map && elem.Kind() != reflect.Slice && elem.Kind() != reflect.Ptr {
|
|
||||||
node = elem.Addr().Interface()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
node = elem.Interface()
|
|
||||||
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid token reference %q", decodedToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodedTokens returns the decoded tokens
|
|
||||||
func (p *Pointer) DecodedTokens() []string {
|
|
||||||
result := make([]string, 0, len(p.referenceTokens))
|
|
||||||
for _, t := range p.referenceTokens {
|
|
||||||
result = append(result, Unescape(t))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEmpty returns true if this is an empty json pointer
|
|
||||||
// this indicates that it points to the root document
|
|
||||||
func (p *Pointer) IsEmpty() bool {
|
|
||||||
return len(p.referenceTokens) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pointer to string representation function
|
|
||||||
func (p *Pointer) String() string {
|
|
||||||
|
|
||||||
if len(p.referenceTokens) == 0 {
|
|
||||||
return emptyPointer
|
|
||||||
}
|
|
||||||
|
|
||||||
pointerString := pointerSeparator + strings.Join(p.referenceTokens, pointerSeparator)
|
|
||||||
|
|
||||||
return pointerString
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specific JSON pointer encoding here
|
|
||||||
// ~0 => ~
|
|
||||||
// ~1 => /
|
|
||||||
// ... and vice versa
|
|
||||||
|
|
||||||
const (
|
|
||||||
encRefTok0 = `~0`
|
|
||||||
encRefTok1 = `~1`
|
|
||||||
decRefTok0 = `~`
|
|
||||||
decRefTok1 = `/`
|
|
||||||
)
|
|
||||||
|
|
||||||
// Unescape unescapes a json pointer reference token string to the original representation
|
|
||||||
func Unescape(token string) string {
|
|
||||||
step1 := strings.Replace(token, encRefTok1, decRefTok1, -1)
|
|
||||||
step2 := strings.Replace(step1, encRefTok0, decRefTok0, -1)
|
|
||||||
return step2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escape escapes a pointer reference token string
|
|
||||||
func Escape(token string) string {
|
|
||||||
step1 := strings.Replace(token, decRefTok0, encRefTok0, -1)
|
|
||||||
step2 := strings.Replace(step1, decRefTok1, encRefTok1, -1)
|
|
||||||
return step2
|
|
||||||
}
|
|
1
vendor/github.com/go-openapi/jsonreference/.gitignore
generated
vendored
1
vendor/github.com/go-openapi/jsonreference/.gitignore
generated
vendored
@ -1 +0,0 @@
|
|||||||
secrets.yml
|
|
41
vendor/github.com/go-openapi/jsonreference/.golangci.yml
generated
vendored
41
vendor/github.com/go-openapi/jsonreference/.golangci.yml
generated
vendored
@ -1,41 +0,0 @@
|
|||||||
linters-settings:
|
|
||||||
govet:
|
|
||||||
check-shadowing: true
|
|
||||||
golint:
|
|
||||||
min-confidence: 0
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 30
|
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
dupl:
|
|
||||||
threshold: 100
|
|
||||||
goconst:
|
|
||||||
min-len: 2
|
|
||||||
min-occurrences: 4
|
|
||||||
linters:
|
|
||||||
enable-all: true
|
|
||||||
disable:
|
|
||||||
- maligned
|
|
||||||
- lll
|
|
||||||
- gochecknoglobals
|
|
||||||
- godox
|
|
||||||
- gocognit
|
|
||||||
- whitespace
|
|
||||||
- wsl
|
|
||||||
- funlen
|
|
||||||
- gochecknoglobals
|
|
||||||
- gochecknoinits
|
|
||||||
- scopelint
|
|
||||||
- wrapcheck
|
|
||||||
- exhaustivestruct
|
|
||||||
- exhaustive
|
|
||||||
- nlreturn
|
|
||||||
- testpackage
|
|
||||||
- gci
|
|
||||||
- gofumpt
|
|
||||||
- goerr113
|
|
||||||
- gomnd
|
|
||||||
- tparallel
|
|
||||||
- nestif
|
|
||||||
- godot
|
|
||||||
- errorlint
|
|
24
vendor/github.com/go-openapi/jsonreference/.travis.yml
generated
vendored
24
vendor/github.com/go-openapi/jsonreference/.travis.yml
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
go:
|
|
||||||
- 1.14.x
|
|
||||||
- 1.x
|
|
||||||
install:
|
|
||||||
- go get gotest.tools/gotestsum
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
# include linting job, but only for latest go version and amd64 arch
|
|
||||||
- go: 1.x
|
|
||||||
arch: amd64
|
|
||||||
install:
|
|
||||||
go get github.com/golangci/golangci-lint/cmd/golangci-lint
|
|
||||||
script:
|
|
||||||
- golangci-lint run --new-from-rev master
|
|
||||||
env:
|
|
||||||
- GO111MODULE=on
|
|
||||||
language: go
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: OpQG/36F7DSF00HLm9WZMhyqFCYYyYTsVDObW226cWiR8PWYiNfLZiSEvIzT1Gx4dDjhigKTIqcLhG34CkL5iNXDjm9Yyo2RYhQPlK8NErNqUEXuBqn4RqYHW48VGhEhOyDd4Ei0E2FN5ZbgpvHgtpkdZ6XDi64r3Ac89isP9aPHXQTuv2Jog6b4/OKKiUTftLcTIst0p4Cp3gqOJWf1wnoj+IadWiECNVQT6zb47IYjtyw6+uV8iUjTzdKcRB6Zc6b4Dq7JAg1Zd7Jfxkql3hlKp4PNlRf9Cy7y5iA3G7MLyg3FcPX5z2kmcyPt2jOTRMBWUJ5zIQpOxizAcN8WsT3WWBL5KbuYK6k0PzujrIDLqdxGpNmjkkMfDBT9cKmZpm2FdW+oZgPFJP+oKmAo4u4KJz/vjiPTXgQlN5bmrLuRMCp+AwC5wkIohTqWZVPE2TK6ZSnMYcg/W39s+RP/9mJoyryAvPSpBOLTI+biCgaUCTOAZxNTWpMFc3tPYntc41WWkdKcooZ9JA5DwfcaVFyTGQ3YXz+HvX6G1z/gW0Q/A4dBi9mj2iE1xm7tRTT+4VQ2AXFvSEI1HJpfPgYnwAtwOD1v3Qm2EUHk9sCdtEDR4wVGEPIVn44GnwFMnGKx9JWppMPYwFu3SVDdHt+E+LOlhZUply11Aa+IVrT2KUQ=
|
|
||||||
script:
|
|
||||||
- gotestsum -f short-verbose -- -race -coverprofile=coverage.txt -covermode=atomic ./...
|
|
74
vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md
generated
vendored
74
vendor/github.com/go-openapi/jsonreference/CODE_OF_CONDUCT.md
generated
vendored
@ -1,74 +0,0 @@
|
|||||||
# Contributor Covenant Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
|
||||||
contributors and maintainers pledge to making participation in our project and
|
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity and
|
|
||||||
orientation.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
|
||||||
include:
|
|
||||||
|
|
||||||
* Using welcoming and inclusive language
|
|
||||||
* Being respectful of differing viewpoints and experiences
|
|
||||||
* Gracefully accepting constructive criticism
|
|
||||||
* Focusing on what is best for the community
|
|
||||||
* Showing empathy towards other community members
|
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
||||||
advances
|
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or electronic
|
|
||||||
address, without explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
## Our Responsibilities
|
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable
|
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
|
||||||
response to any instances of unacceptable behavior.
|
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or
|
|
||||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
||||||
permanently any contributor for other behaviors that they deem inappropriate,
|
|
||||||
threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
|
||||||
when an individual is representing the project or its community. Examples of
|
|
||||||
representing a project or community include using an official project e-mail
|
|
||||||
address, posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event. Representation of a project may be
|
|
||||||
further defined and clarified by project maintainers.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
|
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
||||||
Further details of specific enforcement policies may be posted separately.
|
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
||||||
faith may face temporary or permanent repercussions as determined by other
|
|
||||||
members of the project's leadership.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
||||||
available at [http://contributor-covenant.org/version/1/4][version]
|
|
||||||
|
|
||||||
[homepage]: http://contributor-covenant.org
|
|
||||||
[version]: http://contributor-covenant.org/version/1/4/
|
|
202
vendor/github.com/go-openapi/jsonreference/LICENSE
generated
vendored
202
vendor/github.com/go-openapi/jsonreference/LICENSE
generated
vendored
@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
15
vendor/github.com/go-openapi/jsonreference/README.md
generated
vendored
15
vendor/github.com/go-openapi/jsonreference/README.md
generated
vendored
@ -1,15 +0,0 @@
|
|||||||
# gojsonreference [](https://travis-ci.org/go-openapi/jsonreference) [](https://codecov.io/gh/go-openapi/jsonreference) [](https://slackin.goswagger.io)
|
|
||||||
|
|
||||||
[](https://raw.githubusercontent.com/go-openapi/jsonreference/master/LICENSE) [](http://godoc.org/github.com/go-openapi/jsonreference)
|
|
||||||
An implementation of JSON Reference - Go language
|
|
||||||
|
|
||||||
## Status
|
|
||||||
Feature complete. Stable API
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
https://github.com/go-openapi/jsonpointer
|
|
||||||
|
|
||||||
## References
|
|
||||||
http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
|
|
||||||
|
|
||||||
http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03
|
|
12
vendor/github.com/go-openapi/jsonreference/go.mod
generated
vendored
12
vendor/github.com/go-openapi/jsonreference/go.mod
generated
vendored
@ -1,12 +0,0 @@
|
|||||||
module github.com/go-openapi/jsonreference
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/PuerkitoBio/purell v1.1.1
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.3
|
|
||||||
github.com/stretchr/testify v1.3.0
|
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
|
|
||||||
golang.org/x/text v0.3.3 // indirect
|
|
||||||
)
|
|
||||||
|
|
||||||
go 1.13
|
|
38
vendor/github.com/go-openapi/jsonreference/go.sum
generated
vendored
38
vendor/github.com/go-openapi/jsonreference/go.sum
generated
vendored
@ -1,38 +0,0 @@
|
|||||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
|
||||||
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63 h1:nTT4s92Dgz2HlrB2NaMgvlfqHH39OgMhA7z3PK7PGD4=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
|
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
156
vendor/github.com/go-openapi/jsonreference/reference.go
generated
vendored
156
vendor/github.com/go-openapi/jsonreference/reference.go
generated
vendored
@ -1,156 +0,0 @@
|
|||||||
// Copyright 2013 sigu-399 ( https://github.com/sigu-399 )
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// author sigu-399
|
|
||||||
// author-github https://github.com/sigu-399
|
|
||||||
// author-mail sigu.399@gmail.com
|
|
||||||
//
|
|
||||||
// repository-name jsonreference
|
|
||||||
// repository-desc An implementation of JSON Reference - Go language
|
|
||||||
//
|
|
||||||
// description Main and unique file.
|
|
||||||
//
|
|
||||||
// created 26-02-2013
|
|
||||||
|
|
||||||
package jsonreference
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/PuerkitoBio/purell"
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
fragmentRune = `#`
|
|
||||||
)
|
|
||||||
|
|
||||||
// New creates a new reference for the given string
|
|
||||||
func New(jsonReferenceString string) (Ref, error) {
|
|
||||||
|
|
||||||
var r Ref
|
|
||||||
err := r.parse(jsonReferenceString)
|
|
||||||
return r, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustCreateRef parses the ref string and panics when it's invalid.
|
|
||||||
// Use the New method for a version that returns an error
|
|
||||||
func MustCreateRef(ref string) Ref {
|
|
||||||
r, err := New(ref)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ref represents a json reference object
|
|
||||||
type Ref struct {
|
|
||||||
referenceURL *url.URL
|
|
||||||
referencePointer jsonpointer.Pointer
|
|
||||||
|
|
||||||
HasFullURL bool
|
|
||||||
HasURLPathOnly bool
|
|
||||||
HasFragmentOnly bool
|
|
||||||
HasFileScheme bool
|
|
||||||
HasFullFilePath bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetURL gets the URL for this reference
|
|
||||||
func (r *Ref) GetURL() *url.URL {
|
|
||||||
return r.referenceURL
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPointer gets the json pointer for this reference
|
|
||||||
func (r *Ref) GetPointer() *jsonpointer.Pointer {
|
|
||||||
return &r.referencePointer
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the best version of the url for this reference
|
|
||||||
func (r *Ref) String() string {
|
|
||||||
|
|
||||||
if r.referenceURL != nil {
|
|
||||||
return r.referenceURL.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.HasFragmentOnly {
|
|
||||||
return fragmentRune + r.referencePointer.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.referencePointer.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRoot returns true if this reference is a root document
|
|
||||||
func (r *Ref) IsRoot() bool {
|
|
||||||
return r.referenceURL != nil &&
|
|
||||||
!r.IsCanonical() &&
|
|
||||||
!r.HasURLPathOnly &&
|
|
||||||
r.referenceURL.Fragment == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsCanonical returns true when this pointer starts with http(s):// or file://
|
|
||||||
func (r *Ref) IsCanonical() bool {
|
|
||||||
return (r.HasFileScheme && r.HasFullFilePath) || (!r.HasFileScheme && r.HasFullURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Constructor", parses the given string JSON reference
|
|
||||||
func (r *Ref) parse(jsonReferenceString string) error {
|
|
||||||
|
|
||||||
parsed, err := url.Parse(jsonReferenceString)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.referenceURL, _ = url.Parse(purell.NormalizeURL(parsed, purell.FlagsSafe|purell.FlagRemoveDuplicateSlashes))
|
|
||||||
refURL := r.referenceURL
|
|
||||||
|
|
||||||
if refURL.Scheme != "" && refURL.Host != "" {
|
|
||||||
r.HasFullURL = true
|
|
||||||
} else {
|
|
||||||
if refURL.Path != "" {
|
|
||||||
r.HasURLPathOnly = true
|
|
||||||
} else if refURL.RawQuery == "" && refURL.Fragment != "" {
|
|
||||||
r.HasFragmentOnly = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.HasFileScheme = refURL.Scheme == "file"
|
|
||||||
r.HasFullFilePath = strings.HasPrefix(refURL.Path, "/")
|
|
||||||
|
|
||||||
// invalid json-pointer error means url has no json-pointer fragment. simply ignore error
|
|
||||||
r.referencePointer, _ = jsonpointer.New(refURL.Fragment)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inherits creates a new reference from a parent and a child
|
|
||||||
// If the child cannot inherit from the parent, an error is returned
|
|
||||||
func (r *Ref) Inherits(child Ref) (*Ref, error) {
|
|
||||||
childURL := child.GetURL()
|
|
||||||
parentURL := r.GetURL()
|
|
||||||
if childURL == nil {
|
|
||||||
return nil, errors.New("child url is nil")
|
|
||||||
}
|
|
||||||
if parentURL == nil {
|
|
||||||
return &child, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ref, err := New(parentURL.ResolveReference(childURL).String())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &ref, nil
|
|
||||||
}
|
|
26
vendor/github.com/go-openapi/spec/.editorconfig
generated
vendored
26
vendor/github.com/go-openapi/spec/.editorconfig
generated
vendored
@ -1,26 +0,0 @@
|
|||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
# Unix-style newlines with a newline ending every file
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
|
|
||||||
# Set default charset
|
|
||||||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
|
|
||||||
charset = utf-8
|
|
||||||
|
|
||||||
# Tab indentation (no size specified)
|
|
||||||
[*.go]
|
|
||||||
indent_style = tab
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
# Matches the exact files either package.json or .travis.yml
|
|
||||||
[{package.json,.travis.yml}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
2
vendor/github.com/go-openapi/spec/.gitignore
generated
vendored
2
vendor/github.com/go-openapi/spec/.gitignore
generated
vendored
@ -1,2 +0,0 @@
|
|||||||
secrets.yml
|
|
||||||
coverage.out
|
|
42
vendor/github.com/go-openapi/spec/.golangci.yml
generated
vendored
42
vendor/github.com/go-openapi/spec/.golangci.yml
generated
vendored
@ -1,42 +0,0 @@
|
|||||||
linters-settings:
|
|
||||||
govet:
|
|
||||||
check-shadowing: true
|
|
||||||
golint:
|
|
||||||
min-confidence: 0
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 45
|
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
dupl:
|
|
||||||
threshold: 200
|
|
||||||
goconst:
|
|
||||||
min-len: 2
|
|
||||||
min-occurrences: 2
|
|
||||||
|
|
||||||
linters:
|
|
||||||
enable-all: true
|
|
||||||
disable:
|
|
||||||
- maligned
|
|
||||||
- unparam
|
|
||||||
- lll
|
|
||||||
- gochecknoinits
|
|
||||||
- gochecknoglobals
|
|
||||||
- funlen
|
|
||||||
- godox
|
|
||||||
- gocognit
|
|
||||||
- whitespace
|
|
||||||
- wsl
|
|
||||||
- wrapcheck
|
|
||||||
- testpackage
|
|
||||||
- nlreturn
|
|
||||||
- gomnd
|
|
||||||
- exhaustivestruct
|
|
||||||
- goerr113
|
|
||||||
- errorlint
|
|
||||||
- nestif
|
|
||||||
- godot
|
|
||||||
- gofumpt
|
|
||||||
- paralleltest
|
|
||||||
- tparallel
|
|
||||||
- thelper
|
|
||||||
- ifshort
|
|
31
vendor/github.com/go-openapi/spec/.travis.yml
generated
vendored
31
vendor/github.com/go-openapi/spec/.travis.yml
generated
vendored
@ -1,31 +0,0 @@
|
|||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
go:
|
|
||||||
- 1.14.x
|
|
||||||
- 1.x
|
|
||||||
arch:
|
|
||||||
- amd64
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
# only run fast tests on ppc64le
|
|
||||||
- go: 1.x
|
|
||||||
arch: ppc64le
|
|
||||||
script:
|
|
||||||
- gotestsum -f short-verbose -- ./...
|
|
||||||
|
|
||||||
# include linting job, but only for latest go version and amd64 arch
|
|
||||||
- go: 1.x
|
|
||||||
arch: amd64
|
|
||||||
install:
|
|
||||||
go get github.com/golangci/golangci-lint/cmd/golangci-lint
|
|
||||||
script:
|
|
||||||
- golangci-lint run --new-from-rev master
|
|
||||||
|
|
||||||
install:
|
|
||||||
- GO111MODULE=off go get -u gotest.tools/gotestsum
|
|
||||||
language: go
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: QUWvCkBBK09GF7YtEvHHVt70JOkdlNBG0nIKu/5qc4/nW5HP8I2w0SEf/XR2je0eED1Qe3L/AfMCWwrEj+IUZc3l4v+ju8X8R3Lomhme0Eb0jd1MTMCuPcBT47YCj0M7RON7vXtbFfm1hFJ/jLe5+9FXz0hpXsR24PJc5ZIi/ogNwkaPqG4BmndzecpSh0vc2FJPZUD9LT0I09REY/vXR0oQAalLkW0asGD5taHZTUZq/kBpsNxaAFrLM23i4mUcf33M5fjLpvx5LRICrX/57XpBrDh2TooBU6Qj3CgoY0uPRYUmSNxbVx1czNzl2JtEpb5yjoxfVPQeg0BvQM00G8LJINISR+ohrjhkZmAqchDupAX+yFrxTtORa78CtnIL6z/aTNlgwwVD8kvL/1pFA/JWYmKDmz93mV/+6wubGzNSQCstzjkFA4/iZEKewKUoRIAi/fxyscP6L/rCpmY/4llZZvrnyTqVbt6URWpopUpH4rwYqreXAtJxJsfBJIeSmUIiDIOMGkCTvyTEW3fWGmGoqWtSHLoaWDyAIGb7azb+KvfpWtEcoPFWfSWU+LGee0A/YsUhBl7ADB9A0CJEuR8q4BPpKpfLwPKSiKSAXL7zDkyjExyhtgqbSl2jS+rKIHOZNL8JkCcTP2MKMVd563C5rC5FMKqu3S9m2b6380E=
|
|
||||||
script:
|
|
||||||
- gotestsum -f short-verbose -- -race -coverprofile=coverage.txt -covermode=atomic ./...
|
|
74
vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md
generated
vendored
74
vendor/github.com/go-openapi/spec/CODE_OF_CONDUCT.md
generated
vendored
@ -1,74 +0,0 @@
|
|||||||
# Contributor Covenant Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
|
||||||
contributors and maintainers pledge to making participation in our project and
|
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity and
|
|
||||||
orientation.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
|
||||||
include:
|
|
||||||
|
|
||||||
* Using welcoming and inclusive language
|
|
||||||
* Being respectful of differing viewpoints and experiences
|
|
||||||
* Gracefully accepting constructive criticism
|
|
||||||
* Focusing on what is best for the community
|
|
||||||
* Showing empathy towards other community members
|
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
||||||
advances
|
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or electronic
|
|
||||||
address, without explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
## Our Responsibilities
|
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable
|
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
|
||||||
response to any instances of unacceptable behavior.
|
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or
|
|
||||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
||||||
permanently any contributor for other behaviors that they deem inappropriate,
|
|
||||||
threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
|
||||||
when an individual is representing the project or its community. Examples of
|
|
||||||
representing a project or community include using an official project e-mail
|
|
||||||
address, posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event. Representation of a project may be
|
|
||||||
further defined and clarified by project maintainers.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
|
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
||||||
Further details of specific enforcement policies may be posted separately.
|
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
||||||
faith may face temporary or permanent repercussions as determined by other
|
|
||||||
members of the project's leadership.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
||||||
available at [http://contributor-covenant.org/version/1/4][version]
|
|
||||||
|
|
||||||
[homepage]: http://contributor-covenant.org
|
|
||||||
[version]: http://contributor-covenant.org/version/1/4/
|
|
202
vendor/github.com/go-openapi/spec/LICENSE
generated
vendored
202
vendor/github.com/go-openapi/spec/LICENSE
generated
vendored
@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
34
vendor/github.com/go-openapi/spec/README.md
generated
vendored
34
vendor/github.com/go-openapi/spec/README.md
generated
vendored
@ -1,34 +0,0 @@
|
|||||||
# OAI object model
|
|
||||||
|
|
||||||
[](https://travis-ci.org/go-openapi/spec)
|
|
||||||
<!-- [](https://ci.appveyor.com/project/casualjim/go-openapi/spec/branch/master) -->
|
|
||||||
[](https://codecov.io/gh/go-openapi/spec)
|
|
||||||
[](https://slackin.goswagger.io)
|
|
||||||
[](https://raw.githubusercontent.com/go-openapi/spec/master/LICENSE)
|
|
||||||
[](https://pkg.go.dev/github.com/go-openapi/spec)
|
|
||||||
[](https://goreportcard.com/report/github.com/go-openapi/spec)
|
|
||||||
|
|
||||||
The object model for OpenAPI specification documents.
|
|
||||||
|
|
||||||
### FAQ
|
|
||||||
|
|
||||||
* What does this do?
|
|
||||||
|
|
||||||
> 1. This package knows how to marshal and unmarshal Swagger API specifications into a golang object model
|
|
||||||
> 2. It knows how to resolve $ref and expand them to make a single root document
|
|
||||||
|
|
||||||
* How does it play with the rest of the go-openapi packages ?
|
|
||||||
|
|
||||||
> 1. This package is at the core of the go-openapi suite of packages and [code generator](https://github.com/go-swagger/go-swagger)
|
|
||||||
> 2. There is a [spec loading package](https://github.com/go-openapi/loads) to fetch specs as JSON or YAML from local or remote locations
|
|
||||||
> 3. There is a [spec validation package](https://github.com/go-openapi/validate) built on top of it
|
|
||||||
> 4. There is a [spec analysis package](https://github.com/go-openapi/analysis) built on top of it, to analyze, flatten, fix and merge spec documents
|
|
||||||
|
|
||||||
* Does this library support OpenAPI 3?
|
|
||||||
|
|
||||||
> No.
|
|
||||||
> This package currently only supports OpenAPI 2.0 (aka Swagger 2.0).
|
|
||||||
> There is no plan to make it evolve toward supporting OpenAPI 3.x.
|
|
||||||
> This [discussion thread](https://github.com/go-openapi/spec/issues/21) relates the full story.
|
|
||||||
>
|
|
||||||
> An early attempt to support Swagger 3 may be found at: https://github.com/go-openapi/spec3
|
|
32
vendor/github.com/go-openapi/spec/appveyor.yml
generated
vendored
32
vendor/github.com/go-openapi/spec/appveyor.yml
generated
vendored
@ -1,32 +0,0 @@
|
|||||||
version: "0.1.{build}"
|
|
||||||
|
|
||||||
clone_folder: C:\go-openapi\spec
|
|
||||||
shallow_clone: true # for startup speed
|
|
||||||
pull_requests:
|
|
||||||
do_not_increment_build_number: true
|
|
||||||
|
|
||||||
#skip_tags: true
|
|
||||||
#skip_branch_with_pr: true
|
|
||||||
|
|
||||||
# appveyor.yml
|
|
||||||
build: off
|
|
||||||
|
|
||||||
environment:
|
|
||||||
GOPATH: c:\gopath
|
|
||||||
|
|
||||||
stack: go 1.15
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- go test -v -timeout 20m ./...
|
|
||||||
|
|
||||||
deploy: off
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
- provider: Slack
|
|
||||||
incoming_webhook: https://hooks.slack.com/services/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
|
|
||||||
auth_token:
|
|
||||||
secure: Sf7kZf7ZGbnwWUMpffHwMu5A0cHkLK2MYY32LNTPj4+/3qC3Ghl7+9v4TSLOqOlCwdRNjOGblAq7s+GDJed6/xgRQl1JtCi1klzZNrYX4q01pgTPvvGcwbBkIYgeMaPeIRcK9OZnud7sRXdttozgTOpytps2U6Js32ip7uj5mHSg2ub0FwoSJwlS6dbezZ8+eDhoha0F/guY99BEwx8Bd+zROrT2TFGsSGOFGN6wFc7moCqTHO/YkWib13a2QNXqOxCCVBy/lt76Wp+JkeFppjHlzs/2lP3EAk13RIUAaesdEUHvIHrzCyNJEd3/+KO2DzsWOYfpktd+KBCvgaYOsoo7ubdT3IROeAegZdCgo/6xgCEsmFc9ZcqCfN5yNx2A+BZ2Vwmpws+bQ1E1+B5HDzzaiLcYfG4X2O210QVGVDLWsv1jqD+uPYeHY2WRfh5ZsIUFvaqgUEnwHwrK44/8REAhQavt1QAj5uJpsRd7CkRVPWRNK+yIky+wgbVUFEchRNmS55E7QWf+W4+4QZkQi7vUTMc9nbTUu2Es9NfvfudOpM2wZbn98fjpb/qq/nRv6Bk+ca+7XD5/IgNLMbWp2ouDdzbiHLCOfDUiHiDJhLfFZx9Bwo7ZwfzeOlbrQX66bx7xRKYmOe4DLrXhNcpbsMa8qbfxlZRCmYbubB/Y8h4=
|
|
||||||
channel: bots
|
|
||||||
on_build_success: false
|
|
||||||
on_build_failure: true
|
|
||||||
on_build_status_changed: true
|
|
297
vendor/github.com/go-openapi/spec/bindata.go
generated
vendored
297
vendor/github.com/go-openapi/spec/bindata.go
generated
vendored
File diff suppressed because one or more lines are too long
98
vendor/github.com/go-openapi/spec/cache.go
generated
vendored
98
vendor/github.com/go-openapi/spec/cache.go
generated
vendored
@ -1,98 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResolutionCache a cache for resolving urls
|
|
||||||
type ResolutionCache interface {
|
|
||||||
Get(string) (interface{}, bool)
|
|
||||||
Set(string, interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type simpleCache struct {
|
|
||||||
lock sync.RWMutex
|
|
||||||
store map[string]interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *simpleCache) ShallowClone() ResolutionCache {
|
|
||||||
store := make(map[string]interface{}, len(s.store))
|
|
||||||
s.lock.RLock()
|
|
||||||
for k, v := range s.store {
|
|
||||||
store[k] = v
|
|
||||||
}
|
|
||||||
s.lock.RUnlock()
|
|
||||||
|
|
||||||
return &simpleCache{
|
|
||||||
store: store,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get retrieves a cached URI
|
|
||||||
func (s *simpleCache) Get(uri string) (interface{}, bool) {
|
|
||||||
s.lock.RLock()
|
|
||||||
v, ok := s.store[uri]
|
|
||||||
|
|
||||||
s.lock.RUnlock()
|
|
||||||
return v, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set caches a URI
|
|
||||||
func (s *simpleCache) Set(uri string, data interface{}) {
|
|
||||||
s.lock.Lock()
|
|
||||||
s.store[uri] = data
|
|
||||||
s.lock.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// resCache is a package level cache for $ref resolution and expansion.
|
|
||||||
// It is initialized lazily by methods that have the need for it: no
|
|
||||||
// memory is allocated unless some expander methods are called.
|
|
||||||
//
|
|
||||||
// It is initialized with JSON schema and swagger schema,
|
|
||||||
// which do not mutate during normal operations.
|
|
||||||
//
|
|
||||||
// All subsequent utilizations of this cache are produced from a shallow
|
|
||||||
// clone of this initial version.
|
|
||||||
resCache *simpleCache
|
|
||||||
onceCache sync.Once
|
|
||||||
|
|
||||||
_ ResolutionCache = &simpleCache{}
|
|
||||||
)
|
|
||||||
|
|
||||||
// initResolutionCache initializes the URI resolution cache. To be wrapped in a sync.Once.Do call.
|
|
||||||
func initResolutionCache() {
|
|
||||||
resCache = defaultResolutionCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultResolutionCache() *simpleCache {
|
|
||||||
return &simpleCache{store: map[string]interface{}{
|
|
||||||
"http://swagger.io/v2/schema.json": MustLoadSwagger20Schema(),
|
|
||||||
"http://json-schema.org/draft-04/schema": MustLoadJSONSchemaDraft04(),
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cacheOrDefault(cache ResolutionCache) ResolutionCache {
|
|
||||||
onceCache.Do(initResolutionCache)
|
|
||||||
|
|
||||||
if cache != nil {
|
|
||||||
return cache
|
|
||||||
}
|
|
||||||
|
|
||||||
// get a shallow clone of the base cache with swagger and json schema
|
|
||||||
return resCache.ShallowClone()
|
|
||||||
}
|
|
57
vendor/github.com/go-openapi/spec/contact_info.go
generated
vendored
57
vendor/github.com/go-openapi/spec/contact_info.go
generated
vendored
@ -1,57 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ContactInfo contact information for the exposed API.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#contactObject
|
|
||||||
type ContactInfo struct {
|
|
||||||
ContactInfoProps
|
|
||||||
VendorExtensible
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContactInfoProps hold the properties of a ContactInfo object
|
|
||||||
type ContactInfoProps struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
Email string `json:"email,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates ContactInfo from json
|
|
||||||
func (c *ContactInfo) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &c.ContactInfoProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &c.VendorExtensible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON produces ContactInfo as json
|
|
||||||
func (c ContactInfo) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(c.ContactInfoProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(c.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
49
vendor/github.com/go-openapi/spec/debug.go
generated
vendored
49
vendor/github.com/go-openapi/spec/debug.go
generated
vendored
@ -1,49 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Debug is true when the SWAGGER_DEBUG env var is not empty.
|
|
||||||
//
|
|
||||||
// It enables a more verbose logging of this package.
|
|
||||||
var Debug = os.Getenv("SWAGGER_DEBUG") != ""
|
|
||||||
|
|
||||||
var (
|
|
||||||
// specLogger is a debug logger for this package
|
|
||||||
specLogger *log.Logger
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
debugOptions()
|
|
||||||
}
|
|
||||||
|
|
||||||
func debugOptions() {
|
|
||||||
specLogger = log.New(os.Stdout, "spec:", log.LstdFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
func debugLog(msg string, args ...interface{}) {
|
|
||||||
// A private, trivial trace logger, based on go-openapi/spec/expander.go:debugLog()
|
|
||||||
if Debug {
|
|
||||||
_, file1, pos1, _ := runtime.Caller(1)
|
|
||||||
specLogger.Printf("%s:%d: %s", path.Base(file1), pos1, fmt.Sprintf(msg, args...))
|
|
||||||
}
|
|
||||||
}
|
|
19
vendor/github.com/go-openapi/spec/errors.go
generated
vendored
19
vendor/github.com/go-openapi/spec/errors.go
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
package spec
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
// Error codes
|
|
||||||
var (
|
|
||||||
// ErrUnknownTypeForReference indicates that a resolved reference was found in an unsupported container type
|
|
||||||
ErrUnknownTypeForReference = errors.New("unknown type for the resolved reference")
|
|
||||||
|
|
||||||
// ErrResolveRefNeedsAPointer indicates that a $ref target must be a valid JSON pointer
|
|
||||||
ErrResolveRefNeedsAPointer = errors.New("resolve ref: target needs to be a pointer")
|
|
||||||
|
|
||||||
// ErrDerefUnsupportedType indicates that a resolved reference was found in an unsupported container type.
|
|
||||||
// At the moment, $ref are supported only inside: schemas, parameters, responses, path items
|
|
||||||
ErrDerefUnsupportedType = errors.New("deref: unsupported type")
|
|
||||||
|
|
||||||
// ErrExpandUnsupportedType indicates that $ref expansion is attempted on some invalid type
|
|
||||||
ErrExpandUnsupportedType = errors.New("expand: unsupported type. Input should be of type *Parameter or *Response")
|
|
||||||
)
|
|
594
vendor/github.com/go-openapi/spec/expander.go
generated
vendored
594
vendor/github.com/go-openapi/spec/expander.go
generated
vendored
@ -1,594 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExpandOptions provides options for the spec expander.
|
|
||||||
//
|
|
||||||
// RelativeBase is the path to the root document. This can be a remote URL or a path to a local file.
|
|
||||||
//
|
|
||||||
// If left empty, the root document is assumed to be located in the current working directory:
|
|
||||||
// all relative $ref's will be resolved from there.
|
|
||||||
//
|
|
||||||
// PathLoader injects a document loading method. By default, this resolves to the function provided by the SpecLoader package variable.
|
|
||||||
//
|
|
||||||
type ExpandOptions struct {
|
|
||||||
RelativeBase string // the path to the root document to expand. This is a file, not a directory
|
|
||||||
SkipSchemas bool // do not expand schemas, just paths, parameters and responses
|
|
||||||
ContinueOnError bool // continue expanding even after and error is found
|
|
||||||
PathLoader func(string) (json.RawMessage, error) `json:"-"` // the document loading method that takes a path as input and yields a json document
|
|
||||||
AbsoluteCircularRef bool // circular $ref remaining after expansion remain absolute URLs
|
|
||||||
}
|
|
||||||
|
|
||||||
func optionsOrDefault(opts *ExpandOptions) *ExpandOptions {
|
|
||||||
if opts != nil {
|
|
||||||
clone := *opts // shallow clone to avoid internal changes to be propagated to the caller
|
|
||||||
if clone.RelativeBase != "" {
|
|
||||||
clone.RelativeBase = normalizeBase(clone.RelativeBase)
|
|
||||||
}
|
|
||||||
// if the relative base is empty, let the schema loader choose a pseudo root document
|
|
||||||
return &clone
|
|
||||||
}
|
|
||||||
return &ExpandOptions{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandSpec expands the references in a swagger spec
|
|
||||||
func ExpandSpec(spec *Swagger, options *ExpandOptions) error {
|
|
||||||
options = optionsOrDefault(options)
|
|
||||||
resolver := defaultSchemaLoader(spec, options, nil, nil)
|
|
||||||
|
|
||||||
specBasePath := options.RelativeBase
|
|
||||||
|
|
||||||
if !options.SkipSchemas {
|
|
||||||
for key, definition := range spec.Definitions {
|
|
||||||
parentRefs := make([]string, 0, 10)
|
|
||||||
parentRefs = append(parentRefs, fmt.Sprintf("#/definitions/%s", key))
|
|
||||||
|
|
||||||
def, err := expandSchema(definition, parentRefs, resolver, specBasePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if def != nil {
|
|
||||||
spec.Definitions[key] = *def
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for key := range spec.Parameters {
|
|
||||||
parameter := spec.Parameters[key]
|
|
||||||
if err := expandParameterOrResponse(¶meter, resolver, specBasePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
spec.Parameters[key] = parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
for key := range spec.Responses {
|
|
||||||
response := spec.Responses[key]
|
|
||||||
if err := expandParameterOrResponse(&response, resolver, specBasePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
spec.Responses[key] = response
|
|
||||||
}
|
|
||||||
|
|
||||||
if spec.Paths != nil {
|
|
||||||
for key := range spec.Paths.Paths {
|
|
||||||
pth := spec.Paths.Paths[key]
|
|
||||||
if err := expandPathItem(&pth, resolver, specBasePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
spec.Paths.Paths[key] = pth
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const rootBase = ".root"
|
|
||||||
|
|
||||||
// baseForRoot loads in the cache the root document and produces a fake ".root" base path entry
|
|
||||||
// for further $ref resolution
|
|
||||||
//
|
|
||||||
// Setting the cache is optional and this parameter may safely be left to nil.
|
|
||||||
func baseForRoot(root interface{}, cache ResolutionCache) string {
|
|
||||||
if root == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// cache the root document to resolve $ref's
|
|
||||||
normalizedBase := normalizeBase(rootBase)
|
|
||||||
cache.Set(normalizedBase, root)
|
|
||||||
|
|
||||||
return normalizedBase
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandSchema expands the refs in the schema object with reference to the root object.
|
|
||||||
//
|
|
||||||
// go-openapi/validate uses this function.
|
|
||||||
//
|
|
||||||
// Notice that it is impossible to reference a json schema in a different document other than root
|
|
||||||
// (use ExpandSchemaWithBasePath to resolve external references).
|
|
||||||
//
|
|
||||||
// Setting the cache is optional and this parameter may safely be left to nil.
|
|
||||||
func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error {
|
|
||||||
cache = cacheOrDefault(cache)
|
|
||||||
if root == nil {
|
|
||||||
root = schema
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := &ExpandOptions{
|
|
||||||
// when a root is specified, cache the root as an in-memory document for $ref retrieval
|
|
||||||
RelativeBase: baseForRoot(root, cache),
|
|
||||||
SkipSchemas: false,
|
|
||||||
ContinueOnError: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExpandSchemaWithBasePath(schema, cache, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandSchemaWithBasePath expands the refs in the schema object, base path configured through expand options.
|
|
||||||
//
|
|
||||||
// Setting the cache is optional and this parameter may safely be left to nil.
|
|
||||||
func ExpandSchemaWithBasePath(schema *Schema, cache ResolutionCache, opts *ExpandOptions) error {
|
|
||||||
if schema == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cache = cacheOrDefault(cache)
|
|
||||||
|
|
||||||
opts = optionsOrDefault(opts)
|
|
||||||
|
|
||||||
resolver := defaultSchemaLoader(nil, opts, cache, nil)
|
|
||||||
|
|
||||||
parentRefs := make([]string, 0, 10)
|
|
||||||
s, err := expandSchema(*schema, parentRefs, resolver, opts.RelativeBase)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if s != nil {
|
|
||||||
// guard for when continuing on error
|
|
||||||
*schema = *s
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandItems(target Schema, parentRefs []string, resolver *schemaLoader, basePath string) (*Schema, error) {
|
|
||||||
if target.Items == nil {
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// array
|
|
||||||
if target.Items.Schema != nil {
|
|
||||||
t, err := expandSchema(*target.Items.Schema, parentRefs, resolver, basePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
*target.Items.Schema = *t
|
|
||||||
}
|
|
||||||
|
|
||||||
// tuple
|
|
||||||
for i := range target.Items.Schemas {
|
|
||||||
t, err := expandSchema(target.Items.Schemas[i], parentRefs, resolver, basePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
target.Items.Schemas[i] = *t
|
|
||||||
}
|
|
||||||
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader, basePath string) (*Schema, error) {
|
|
||||||
if target.Ref.String() == "" && target.Ref.IsRoot() {
|
|
||||||
newRef := normalizeRef(&target.Ref, basePath)
|
|
||||||
target.Ref = *newRef
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// change the base path of resolution when an ID is encountered
|
|
||||||
// otherwise the basePath should inherit the parent's
|
|
||||||
if target.ID != "" {
|
|
||||||
basePath, _ = resolver.setSchemaID(target, target.ID, basePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if target.Ref.String() != "" {
|
|
||||||
return expandSchemaRef(target, parentRefs, resolver, basePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
for k := range target.Definitions {
|
|
||||||
tt, err := expandSchema(target.Definitions[k], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if tt != nil {
|
|
||||||
target.Definitions[k] = *tt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t, err := expandItems(target, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target = *t
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range target.AllOf {
|
|
||||||
t, err := expandSchema(target.AllOf[i], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target.AllOf[i] = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range target.AnyOf {
|
|
||||||
t, err := expandSchema(target.AnyOf[i], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target.AnyOf[i] = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range target.OneOf {
|
|
||||||
t, err := expandSchema(target.OneOf[i], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target.OneOf[i] = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if target.Not != nil {
|
|
||||||
t, err := expandSchema(*target.Not, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
*target.Not = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for k := range target.Properties {
|
|
||||||
t, err := expandSchema(target.Properties[k], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target.Properties[k] = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if target.AdditionalProperties != nil && target.AdditionalProperties.Schema != nil {
|
|
||||||
t, err := expandSchema(*target.AdditionalProperties.Schema, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
*target.AdditionalProperties.Schema = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for k := range target.PatternProperties {
|
|
||||||
t, err := expandSchema(target.PatternProperties[k], parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
target.PatternProperties[k] = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for k := range target.Dependencies {
|
|
||||||
if target.Dependencies[k].Schema != nil {
|
|
||||||
t, err := expandSchema(*target.Dependencies[k].Schema, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
*target.Dependencies[k].Schema = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if target.AdditionalItems != nil && target.AdditionalItems.Schema != nil {
|
|
||||||
t, err := expandSchema(*target.AdditionalItems.Schema, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return &target, err
|
|
||||||
}
|
|
||||||
if t != nil {
|
|
||||||
*target.AdditionalItems.Schema = *t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandSchemaRef(target Schema, parentRefs []string, resolver *schemaLoader, basePath string) (*Schema, error) {
|
|
||||||
// if a Ref is found, all sibling fields are skipped
|
|
||||||
// Ref also changes the resolution scope of children expandSchema
|
|
||||||
|
|
||||||
// here the resolution scope is changed because a $ref was encountered
|
|
||||||
normalizedRef := normalizeRef(&target.Ref, basePath)
|
|
||||||
normalizedBasePath := normalizedRef.RemoteURI()
|
|
||||||
|
|
||||||
if resolver.isCircular(normalizedRef, basePath, parentRefs...) {
|
|
||||||
// this means there is a cycle in the recursion tree: return the Ref
|
|
||||||
// - circular refs cannot be expanded. We leave them as ref.
|
|
||||||
// - denormalization means that a new local file ref is set relative to the original basePath
|
|
||||||
debugLog("short circuit circular ref: basePath: %s, normalizedPath: %s, normalized ref: %s",
|
|
||||||
basePath, normalizedBasePath, normalizedRef.String())
|
|
||||||
if !resolver.options.AbsoluteCircularRef {
|
|
||||||
target.Ref = denormalizeRef(normalizedRef, resolver.context.basePath, resolver.context.rootID)
|
|
||||||
} else {
|
|
||||||
target.Ref = *normalizedRef
|
|
||||||
}
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var t *Schema
|
|
||||||
err := resolver.Resolve(&target.Ref, &t, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if t == nil {
|
|
||||||
// guard for when continuing on error
|
|
||||||
return &target, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
parentRefs = append(parentRefs, normalizedRef.String())
|
|
||||||
transitiveResolver := resolver.transitiveResolver(basePath, target.Ref)
|
|
||||||
|
|
||||||
basePath = resolver.updateBasePath(transitiveResolver, normalizedBasePath)
|
|
||||||
|
|
||||||
return expandSchema(*t, parentRefs, transitiveResolver, basePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandPathItem(pathItem *PathItem, resolver *schemaLoader, basePath string) error {
|
|
||||||
if pathItem == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
parentRefs := make([]string, 0, 10)
|
|
||||||
if err := resolver.deref(pathItem, parentRefs, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if pathItem.Ref.String() != "" {
|
|
||||||
transitiveResolver := resolver.transitiveResolver(basePath, pathItem.Ref)
|
|
||||||
basePath = transitiveResolver.updateBasePath(resolver, basePath)
|
|
||||||
resolver = transitiveResolver
|
|
||||||
}
|
|
||||||
|
|
||||||
pathItem.Ref = Ref{}
|
|
||||||
for i := range pathItem.Parameters {
|
|
||||||
if err := expandParameterOrResponse(&(pathItem.Parameters[i]), resolver, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ops := []*Operation{
|
|
||||||
pathItem.Get,
|
|
||||||
pathItem.Head,
|
|
||||||
pathItem.Options,
|
|
||||||
pathItem.Put,
|
|
||||||
pathItem.Post,
|
|
||||||
pathItem.Patch,
|
|
||||||
pathItem.Delete,
|
|
||||||
}
|
|
||||||
for _, op := range ops {
|
|
||||||
if err := expandOperation(op, resolver, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandOperation(op *Operation, resolver *schemaLoader, basePath string) error {
|
|
||||||
if op == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range op.Parameters {
|
|
||||||
param := op.Parameters[i]
|
|
||||||
if err := expandParameterOrResponse(¶m, resolver, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
op.Parameters[i] = param
|
|
||||||
}
|
|
||||||
|
|
||||||
if op.Responses == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
responses := op.Responses
|
|
||||||
if err := expandParameterOrResponse(responses.Default, resolver, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for code := range responses.StatusCodeResponses {
|
|
||||||
response := responses.StatusCodeResponses[code]
|
|
||||||
if err := expandParameterOrResponse(&response, resolver, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
responses.StatusCodeResponses[code] = response
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandResponseWithRoot expands a response based on a root document, not a fetchable document
|
|
||||||
//
|
|
||||||
// Notice that it is impossible to reference a json schema in a different document other than root
|
|
||||||
// (use ExpandResponse to resolve external references).
|
|
||||||
//
|
|
||||||
// Setting the cache is optional and this parameter may safely be left to nil.
|
|
||||||
func ExpandResponseWithRoot(response *Response, root interface{}, cache ResolutionCache) error {
|
|
||||||
cache = cacheOrDefault(cache)
|
|
||||||
opts := &ExpandOptions{
|
|
||||||
RelativeBase: baseForRoot(root, cache),
|
|
||||||
}
|
|
||||||
resolver := defaultSchemaLoader(root, opts, cache, nil)
|
|
||||||
|
|
||||||
return expandParameterOrResponse(response, resolver, opts.RelativeBase)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandResponse expands a response based on a basepath
|
|
||||||
//
|
|
||||||
// All refs inside response will be resolved relative to basePath
|
|
||||||
func ExpandResponse(response *Response, basePath string) error {
|
|
||||||
opts := optionsOrDefault(&ExpandOptions{
|
|
||||||
RelativeBase: basePath,
|
|
||||||
})
|
|
||||||
resolver := defaultSchemaLoader(nil, opts, nil, nil)
|
|
||||||
|
|
||||||
return expandParameterOrResponse(response, resolver, opts.RelativeBase)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandParameterWithRoot expands a parameter based on a root document, not a fetchable document.
|
|
||||||
//
|
|
||||||
// Notice that it is impossible to reference a json schema in a different document other than root
|
|
||||||
// (use ExpandParameter to resolve external references).
|
|
||||||
func ExpandParameterWithRoot(parameter *Parameter, root interface{}, cache ResolutionCache) error {
|
|
||||||
cache = cacheOrDefault(cache)
|
|
||||||
|
|
||||||
opts := &ExpandOptions{
|
|
||||||
RelativeBase: baseForRoot(root, cache),
|
|
||||||
}
|
|
||||||
resolver := defaultSchemaLoader(root, opts, cache, nil)
|
|
||||||
|
|
||||||
return expandParameterOrResponse(parameter, resolver, opts.RelativeBase)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandParameter expands a parameter based on a basepath.
|
|
||||||
// This is the exported version of expandParameter
|
|
||||||
// all refs inside parameter will be resolved relative to basePath
|
|
||||||
func ExpandParameter(parameter *Parameter, basePath string) error {
|
|
||||||
opts := optionsOrDefault(&ExpandOptions{
|
|
||||||
RelativeBase: basePath,
|
|
||||||
})
|
|
||||||
resolver := defaultSchemaLoader(nil, opts, nil, nil)
|
|
||||||
|
|
||||||
return expandParameterOrResponse(parameter, resolver, opts.RelativeBase)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getRefAndSchema(input interface{}) (*Ref, *Schema, error) {
|
|
||||||
var (
|
|
||||||
ref *Ref
|
|
||||||
sch *Schema
|
|
||||||
)
|
|
||||||
|
|
||||||
switch refable := input.(type) {
|
|
||||||
case *Parameter:
|
|
||||||
if refable == nil {
|
|
||||||
return nil, nil, nil
|
|
||||||
}
|
|
||||||
ref = &refable.Ref
|
|
||||||
sch = refable.Schema
|
|
||||||
case *Response:
|
|
||||||
if refable == nil {
|
|
||||||
return nil, nil, nil
|
|
||||||
}
|
|
||||||
ref = &refable.Ref
|
|
||||||
sch = refable.Schema
|
|
||||||
default:
|
|
||||||
return nil, nil, fmt.Errorf("unsupported type: %T: %w", input, ErrExpandUnsupportedType)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ref, sch, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandParameterOrResponse(input interface{}, resolver *schemaLoader, basePath string) error {
|
|
||||||
ref, _, err := getRefAndSchema(input)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if ref == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
parentRefs := make([]string, 0, 10)
|
|
||||||
if err = resolver.deref(input, parentRefs, basePath); resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ref, sch, _ := getRefAndSchema(input)
|
|
||||||
if ref.String() != "" {
|
|
||||||
transitiveResolver := resolver.transitiveResolver(basePath, *ref)
|
|
||||||
basePath = resolver.updateBasePath(transitiveResolver, basePath)
|
|
||||||
resolver = transitiveResolver
|
|
||||||
}
|
|
||||||
|
|
||||||
if sch == nil {
|
|
||||||
// nothing to be expanded
|
|
||||||
if ref != nil {
|
|
||||||
*ref = Ref{}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if sch.Ref.String() != "" {
|
|
||||||
rebasedRef, ern := NewRef(normalizeURI(sch.Ref.String(), basePath))
|
|
||||||
if ern != nil {
|
|
||||||
return ern
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case resolver.isCircular(&rebasedRef, basePath, parentRefs...):
|
|
||||||
// this is a circular $ref: stop expansion
|
|
||||||
if !resolver.options.AbsoluteCircularRef {
|
|
||||||
sch.Ref = denormalizeRef(&rebasedRef, resolver.context.basePath, resolver.context.rootID)
|
|
||||||
} else {
|
|
||||||
sch.Ref = rebasedRef
|
|
||||||
}
|
|
||||||
case !resolver.options.SkipSchemas:
|
|
||||||
// schema expanded to a $ref in another root
|
|
||||||
sch.Ref = rebasedRef
|
|
||||||
debugLog("rebased to: %s", sch.Ref.String())
|
|
||||||
default:
|
|
||||||
// skip schema expansion but rebase $ref to schema
|
|
||||||
sch.Ref = denormalizeRef(&rebasedRef, resolver.context.basePath, resolver.context.rootID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ref != nil {
|
|
||||||
*ref = Ref{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// expand schema
|
|
||||||
if !resolver.options.SkipSchemas {
|
|
||||||
s, err := expandSchema(*sch, parentRefs, resolver, basePath)
|
|
||||||
if resolver.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if s == nil {
|
|
||||||
// guard for when continuing on error
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
*sch = *s
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
24
vendor/github.com/go-openapi/spec/external_docs.go
generated
vendored
24
vendor/github.com/go-openapi/spec/external_docs.go
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
// ExternalDocumentation allows referencing an external resource for
|
|
||||||
// extended documentation.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#externalDocumentationObject
|
|
||||||
type ExternalDocumentation struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
}
|
|
13
vendor/github.com/go-openapi/spec/go.mod
generated
vendored
13
vendor/github.com/go-openapi/spec/go.mod
generated
vendored
@ -1,13 +0,0 @@
|
|||||||
module github.com/go-openapi/spec
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.5
|
|
||||||
github.com/go-openapi/jsonreference v0.19.5
|
|
||||||
github.com/go-openapi/swag v0.19.14
|
|
||||||
github.com/stretchr/testify v1.6.1
|
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
|
|
||||||
golang.org/x/text v0.3.5 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
|
||||||
)
|
|
||||||
|
|
||||||
go 1.13
|
|
65
vendor/github.com/go-openapi/spec/go.sum
generated
vendored
65
vendor/github.com/go-openapi/spec/go.sum
generated
vendored
@ -1,65 +0,0 @@
|
|||||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
|
||||||
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
|
|
||||||
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
|
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
|
||||||
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
|
||||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
|
||||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
|
||||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
|
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
203
vendor/github.com/go-openapi/spec/header.go
generated
vendored
203
vendor/github.com/go-openapi/spec/header.go
generated
vendored
@ -1,203 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
jsonArray = "array"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HeaderProps describes a response header
|
|
||||||
type HeaderProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Header describes a header for a response of the API
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#headerObject
|
|
||||||
type Header struct {
|
|
||||||
CommonValidations
|
|
||||||
SimpleSchema
|
|
||||||
VendorExtensible
|
|
||||||
HeaderProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResponseHeader creates a new header instance for use in a response
|
|
||||||
func ResponseHeader() *Header {
|
|
||||||
return new(Header)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDescription sets the description on this response, allows for chaining
|
|
||||||
func (h *Header) WithDescription(description string) *Header {
|
|
||||||
h.Description = description
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typed a fluent builder method for the type of parameter
|
|
||||||
func (h *Header) Typed(tpe, format string) *Header {
|
|
||||||
h.Type = tpe
|
|
||||||
h.Format = format
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectionOf a fluent builder method for an array item
|
|
||||||
func (h *Header) CollectionOf(items *Items, format string) *Header {
|
|
||||||
h.Type = jsonArray
|
|
||||||
h.Items = items
|
|
||||||
h.CollectionFormat = format
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDefault sets the default value on this item
|
|
||||||
func (h *Header) WithDefault(defaultValue interface{}) *Header {
|
|
||||||
h.Default = defaultValue
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxLength sets a max length value
|
|
||||||
func (h *Header) WithMaxLength(max int64) *Header {
|
|
||||||
h.MaxLength = &max
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinLength sets a min length value
|
|
||||||
func (h *Header) WithMinLength(min int64) *Header {
|
|
||||||
h.MinLength = &min
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPattern sets a pattern value
|
|
||||||
func (h *Header) WithPattern(pattern string) *Header {
|
|
||||||
h.Pattern = pattern
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMultipleOf sets a multiple of value
|
|
||||||
func (h *Header) WithMultipleOf(number float64) *Header {
|
|
||||||
h.MultipleOf = &number
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaximum sets a maximum number value
|
|
||||||
func (h *Header) WithMaximum(max float64, exclusive bool) *Header {
|
|
||||||
h.Maximum = &max
|
|
||||||
h.ExclusiveMaximum = exclusive
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinimum sets a minimum number value
|
|
||||||
func (h *Header) WithMinimum(min float64, exclusive bool) *Header {
|
|
||||||
h.Minimum = &min
|
|
||||||
h.ExclusiveMinimum = exclusive
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithEnum sets a the enum values (replace)
|
|
||||||
func (h *Header) WithEnum(values ...interface{}) *Header {
|
|
||||||
h.Enum = append([]interface{}{}, values...)
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxItems sets the max items
|
|
||||||
func (h *Header) WithMaxItems(size int64) *Header {
|
|
||||||
h.MaxItems = &size
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinItems sets the min items
|
|
||||||
func (h *Header) WithMinItems(size int64) *Header {
|
|
||||||
h.MinItems = &size
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// UniqueValues dictates that this array can only have unique items
|
|
||||||
func (h *Header) UniqueValues() *Header {
|
|
||||||
h.UniqueItems = true
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowDuplicates this array can have duplicates
|
|
||||||
func (h *Header) AllowDuplicates() *Header {
|
|
||||||
h.UniqueItems = false
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValidations is a fluent method to set header validations
|
|
||||||
func (h *Header) WithValidations(val CommonValidations) *Header {
|
|
||||||
h.SetValidations(SchemaValidations{CommonValidations: val})
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (h Header) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(h.CommonValidations)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(h.SimpleSchema)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b3, err := json.Marshal(h.HeaderProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2, b3), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals this header from JSON
|
|
||||||
func (h *Header) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &h.CommonValidations); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &h.SimpleSchema); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &h.VendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &h.HeaderProps)
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (h Header) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := h.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(h.CommonValidations, token)
|
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r != nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(h.SimpleSchema, token)
|
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r != nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(h.HeaderProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
165
vendor/github.com/go-openapi/spec/info.go
generated
vendored
165
vendor/github.com/go-openapi/spec/info.go
generated
vendored
@ -1,165 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Extensions vendor specific extensions
|
|
||||||
type Extensions map[string]interface{}
|
|
||||||
|
|
||||||
// Add adds a value to these extensions
|
|
||||||
func (e Extensions) Add(key string, value interface{}) {
|
|
||||||
realKey := strings.ToLower(key)
|
|
||||||
e[realKey] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetString gets a string value from the extensions
|
|
||||||
func (e Extensions) GetString(key string) (string, bool) {
|
|
||||||
if v, ok := e[strings.ToLower(key)]; ok {
|
|
||||||
str, ok := v.(string)
|
|
||||||
return str, ok
|
|
||||||
}
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetBool gets a string value from the extensions
|
|
||||||
func (e Extensions) GetBool(key string) (bool, bool) {
|
|
||||||
if v, ok := e[strings.ToLower(key)]; ok {
|
|
||||||
str, ok := v.(bool)
|
|
||||||
return str, ok
|
|
||||||
}
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStringSlice gets a string value from the extensions
|
|
||||||
func (e Extensions) GetStringSlice(key string) ([]string, bool) {
|
|
||||||
if v, ok := e[strings.ToLower(key)]; ok {
|
|
||||||
arr, isSlice := v.([]interface{})
|
|
||||||
if !isSlice {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
var strs []string
|
|
||||||
for _, iface := range arr {
|
|
||||||
str, isString := iface.(string)
|
|
||||||
if !isString {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
strs = append(strs, str)
|
|
||||||
}
|
|
||||||
return strs, ok
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// VendorExtensible composition block.
|
|
||||||
type VendorExtensible struct {
|
|
||||||
Extensions Extensions
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddExtension adds an extension to this extensible object
|
|
||||||
func (v *VendorExtensible) AddExtension(key string, value interface{}) {
|
|
||||||
if value == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if v.Extensions == nil {
|
|
||||||
v.Extensions = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
v.Extensions.Add(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals the extensions to json
|
|
||||||
func (v VendorExtensible) MarshalJSON() ([]byte, error) {
|
|
||||||
toser := make(map[string]interface{})
|
|
||||||
for k, v := range v.Extensions {
|
|
||||||
lk := strings.ToLower(k)
|
|
||||||
if strings.HasPrefix(lk, "x-") {
|
|
||||||
toser[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return json.Marshal(toser)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON for this extensible object
|
|
||||||
func (v *VendorExtensible) UnmarshalJSON(data []byte) error {
|
|
||||||
var d map[string]interface{}
|
|
||||||
if err := json.Unmarshal(data, &d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k, vv := range d {
|
|
||||||
lk := strings.ToLower(k)
|
|
||||||
if strings.HasPrefix(lk, "x-") {
|
|
||||||
if v.Extensions == nil {
|
|
||||||
v.Extensions = map[string]interface{}{}
|
|
||||||
}
|
|
||||||
v.Extensions[k] = vv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InfoProps the properties for an info definition
|
|
||||||
type InfoProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Title string `json:"title,omitempty"`
|
|
||||||
TermsOfService string `json:"termsOfService,omitempty"`
|
|
||||||
Contact *ContactInfo `json:"contact,omitempty"`
|
|
||||||
License *License `json:"license,omitempty"`
|
|
||||||
Version string `json:"version,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info object provides metadata about the API.
|
|
||||||
// The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#infoObject
|
|
||||||
type Info struct {
|
|
||||||
VendorExtensible
|
|
||||||
InfoProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (i Info) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := i.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(i.InfoProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (i Info) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(i.InfoProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(i.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON marshal this from JSON
|
|
||||||
func (i *Info) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &i.InfoProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &i.VendorExtensible)
|
|
||||||
}
|
|
234
vendor/github.com/go-openapi/spec/items.go
generated
vendored
234
vendor/github.com/go-openapi/spec/items.go
generated
vendored
@ -1,234 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
jsonRef = "$ref"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SimpleSchema describe swagger simple schemas for parameters and headers
|
|
||||||
type SimpleSchema struct {
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Nullable bool `json:"nullable,omitempty"`
|
|
||||||
Format string `json:"format,omitempty"`
|
|
||||||
Items *Items `json:"items,omitempty"`
|
|
||||||
CollectionFormat string `json:"collectionFormat,omitempty"`
|
|
||||||
Default interface{} `json:"default,omitempty"`
|
|
||||||
Example interface{} `json:"example,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TypeName return the type (or format) of a simple schema
|
|
||||||
func (s *SimpleSchema) TypeName() string {
|
|
||||||
if s.Format != "" {
|
|
||||||
return s.Format
|
|
||||||
}
|
|
||||||
return s.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
// ItemsTypeName yields the type of items in a simple schema array
|
|
||||||
func (s *SimpleSchema) ItemsTypeName() string {
|
|
||||||
if s.Items == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return s.Items.TypeName()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Items a limited subset of JSON-Schema's items object.
|
|
||||||
// It is used by parameter definitions that are not located in "body".
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#items-object
|
|
||||||
type Items struct {
|
|
||||||
Refable
|
|
||||||
CommonValidations
|
|
||||||
SimpleSchema
|
|
||||||
VendorExtensible
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewItems creates a new instance of items
|
|
||||||
func NewItems() *Items {
|
|
||||||
return &Items{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typed a fluent builder method for the type of item
|
|
||||||
func (i *Items) Typed(tpe, format string) *Items {
|
|
||||||
i.Type = tpe
|
|
||||||
i.Format = format
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsNullable flags this schema as nullable.
|
|
||||||
func (i *Items) AsNullable() *Items {
|
|
||||||
i.Nullable = true
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectionOf a fluent builder method for an array item
|
|
||||||
func (i *Items) CollectionOf(items *Items, format string) *Items {
|
|
||||||
i.Type = jsonArray
|
|
||||||
i.Items = items
|
|
||||||
i.CollectionFormat = format
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDefault sets the default value on this item
|
|
||||||
func (i *Items) WithDefault(defaultValue interface{}) *Items {
|
|
||||||
i.Default = defaultValue
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxLength sets a max length value
|
|
||||||
func (i *Items) WithMaxLength(max int64) *Items {
|
|
||||||
i.MaxLength = &max
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinLength sets a min length value
|
|
||||||
func (i *Items) WithMinLength(min int64) *Items {
|
|
||||||
i.MinLength = &min
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPattern sets a pattern value
|
|
||||||
func (i *Items) WithPattern(pattern string) *Items {
|
|
||||||
i.Pattern = pattern
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMultipleOf sets a multiple of value
|
|
||||||
func (i *Items) WithMultipleOf(number float64) *Items {
|
|
||||||
i.MultipleOf = &number
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaximum sets a maximum number value
|
|
||||||
func (i *Items) WithMaximum(max float64, exclusive bool) *Items {
|
|
||||||
i.Maximum = &max
|
|
||||||
i.ExclusiveMaximum = exclusive
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinimum sets a minimum number value
|
|
||||||
func (i *Items) WithMinimum(min float64, exclusive bool) *Items {
|
|
||||||
i.Minimum = &min
|
|
||||||
i.ExclusiveMinimum = exclusive
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithEnum sets a the enum values (replace)
|
|
||||||
func (i *Items) WithEnum(values ...interface{}) *Items {
|
|
||||||
i.Enum = append([]interface{}{}, values...)
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxItems sets the max items
|
|
||||||
func (i *Items) WithMaxItems(size int64) *Items {
|
|
||||||
i.MaxItems = &size
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinItems sets the min items
|
|
||||||
func (i *Items) WithMinItems(size int64) *Items {
|
|
||||||
i.MinItems = &size
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// UniqueValues dictates that this array can only have unique items
|
|
||||||
func (i *Items) UniqueValues() *Items {
|
|
||||||
i.UniqueItems = true
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowDuplicates this array can have duplicates
|
|
||||||
func (i *Items) AllowDuplicates() *Items {
|
|
||||||
i.UniqueItems = false
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValidations is a fluent method to set Items validations
|
|
||||||
func (i *Items) WithValidations(val CommonValidations) *Items {
|
|
||||||
i.SetValidations(SchemaValidations{CommonValidations: val})
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (i *Items) UnmarshalJSON(data []byte) error {
|
|
||||||
var validations CommonValidations
|
|
||||||
if err := json.Unmarshal(data, &validations); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var ref Refable
|
|
||||||
if err := json.Unmarshal(data, &ref); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var simpleSchema SimpleSchema
|
|
||||||
if err := json.Unmarshal(data, &simpleSchema); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var vendorExtensible VendorExtensible
|
|
||||||
if err := json.Unmarshal(data, &vendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
i.Refable = ref
|
|
||||||
i.CommonValidations = validations
|
|
||||||
i.SimpleSchema = simpleSchema
|
|
||||||
i.VendorExtensible = vendorExtensible
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (i Items) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(i.CommonValidations)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(i.SimpleSchema)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b3, err := json.Marshal(i.Refable)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b4, err := json.Marshal(i.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b4, b3, b1, b2), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (i Items) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if token == jsonRef {
|
|
||||||
return &i.Ref, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(i.CommonValidations, token)
|
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r != nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(i.SimpleSchema, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
56
vendor/github.com/go-openapi/spec/license.go
generated
vendored
56
vendor/github.com/go-openapi/spec/license.go
generated
vendored
@ -1,56 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// License information for the exposed API.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#licenseObject
|
|
||||||
type License struct {
|
|
||||||
LicenseProps
|
|
||||||
VendorExtensible
|
|
||||||
}
|
|
||||||
|
|
||||||
// LicenseProps holds the properties of a License object
|
|
||||||
type LicenseProps struct {
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
URL string `json:"url,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates License from json
|
|
||||||
func (l *License) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &l.LicenseProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &l.VendorExtensible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON produces License as json
|
|
||||||
func (l License) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(l.LicenseProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(l.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
203
vendor/github.com/go-openapi/spec/normalizer.go
generated
vendored
203
vendor/github.com/go-openapi/spec/normalizer.go
generated
vendored
@ -1,203 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/url"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const fileScheme = "file"
|
|
||||||
|
|
||||||
// normalizeURI ensures that all $ref paths used internally by the expander are canonicalized.
|
|
||||||
//
|
|
||||||
// NOTE(windows): there is a tolerance over the strict URI format on windows.
|
|
||||||
//
|
|
||||||
// The normalizer accepts relative file URLs like 'Path\File.JSON' as well as absolute file URLs like
|
|
||||||
// 'C:\Path\file.Yaml'.
|
|
||||||
//
|
|
||||||
// Both are canonicalized with a "file://" scheme, slashes and a lower-cased path:
|
|
||||||
// 'file:///c:/path/file.yaml'
|
|
||||||
//
|
|
||||||
// URLs can be specified with a file scheme, like in 'file:///folder/file.json' or
|
|
||||||
// 'file:///c:\folder\File.json'.
|
|
||||||
//
|
|
||||||
// URLs like file://C:\folder are considered invalid (i.e. there is no host 'c:\folder') and a "repair"
|
|
||||||
// is attempted.
|
|
||||||
//
|
|
||||||
// The base path argument is assumed to be canonicalized (e.g. using normalizeBase()).
|
|
||||||
func normalizeURI(refPath, base string) string {
|
|
||||||
refURL, err := url.Parse(refPath)
|
|
||||||
if err != nil {
|
|
||||||
specLogger.Printf("warning: invalid URI in $ref %q: %v", refPath, err)
|
|
||||||
refURL, refPath = repairURI(refPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
fixWindowsURI(refURL, refPath) // noop on non-windows OS
|
|
||||||
|
|
||||||
refURL.Path = path.Clean(refURL.Path)
|
|
||||||
if refURL.Path == "." {
|
|
||||||
refURL.Path = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
r := MustCreateRef(refURL.String())
|
|
||||||
if r.IsCanonical() {
|
|
||||||
return refURL.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
baseURL, _ := url.Parse(base)
|
|
||||||
if path.IsAbs(refURL.Path) {
|
|
||||||
baseURL.Path = refURL.Path
|
|
||||||
} else if refURL.Path != "" {
|
|
||||||
baseURL.Path = path.Join(path.Dir(baseURL.Path), refURL.Path)
|
|
||||||
}
|
|
||||||
// copying fragment from ref to base
|
|
||||||
baseURL.Fragment = refURL.Fragment
|
|
||||||
|
|
||||||
return baseURL.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// denormalizeRef returns the simplest notation for a normalized $ref, given the path of the original root document.
|
|
||||||
//
|
|
||||||
// When calling this, we assume that:
|
|
||||||
// * $ref is a canonical URI
|
|
||||||
// * originalRelativeBase is a canonical URI
|
|
||||||
//
|
|
||||||
// denormalizeRef is currently used when we rewrite a $ref after a circular $ref has been detected.
|
|
||||||
// In this case, expansion stops and normally renders the internal canonical $ref.
|
|
||||||
//
|
|
||||||
// This internal $ref is eventually rebased to the original RelativeBase used for the expansion.
|
|
||||||
//
|
|
||||||
// There is a special case for schemas that are anchored with an "id":
|
|
||||||
// in that case, the rebasing is performed // against the id only if this is an anchor for the initial root document.
|
|
||||||
// All other intermediate "id"'s found along the way are ignored for the purpose of rebasing.
|
|
||||||
//
|
|
||||||
func denormalizeRef(ref *Ref, originalRelativeBase, id string) Ref {
|
|
||||||
debugLog("denormalizeRef called:\n$ref: %q\noriginal: %s\nroot ID:%s", ref.String(), originalRelativeBase, id)
|
|
||||||
|
|
||||||
if ref.String() == "" || ref.IsRoot() || ref.HasFragmentOnly {
|
|
||||||
// short circuit: $ref to current doc
|
|
||||||
return *ref
|
|
||||||
}
|
|
||||||
|
|
||||||
if id != "" {
|
|
||||||
idBaseURL, err := url.Parse(id)
|
|
||||||
if err == nil { // if the schema id is not usable as a URI, ignore it
|
|
||||||
if ref, ok := rebase(ref, idBaseURL, true); ok { // rebase, but keep references to root unchaged (do not want $ref: "")
|
|
||||||
// $ref relative to the ID of the schema in the root document
|
|
||||||
return ref
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
originalRelativeBaseURL, _ := url.Parse(originalRelativeBase)
|
|
||||||
|
|
||||||
r, _ := rebase(ref, originalRelativeBaseURL, false)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func rebase(ref *Ref, v *url.URL, notEqual bool) (Ref, bool) {
|
|
||||||
var newBase url.URL
|
|
||||||
|
|
||||||
u := ref.GetURL()
|
|
||||||
|
|
||||||
if u.Scheme != v.Scheme || u.Host != v.Host {
|
|
||||||
return *ref, false
|
|
||||||
}
|
|
||||||
|
|
||||||
docPath := v.Path
|
|
||||||
v.Path = path.Dir(v.Path)
|
|
||||||
|
|
||||||
if v.Path == "." {
|
|
||||||
v.Path = ""
|
|
||||||
} else if !strings.HasSuffix(v.Path, "/") {
|
|
||||||
v.Path += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
newBase.Fragment = u.Fragment
|
|
||||||
|
|
||||||
if strings.HasPrefix(u.Path, docPath) {
|
|
||||||
newBase.Path = strings.TrimPrefix(u.Path, docPath)
|
|
||||||
} else {
|
|
||||||
newBase.Path = strings.TrimPrefix(u.Path, v.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if notEqual && newBase.Path == "" && newBase.Fragment == "" {
|
|
||||||
// do not want rebasing to end up in an empty $ref
|
|
||||||
return *ref, false
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.IsAbs(newBase.Path) {
|
|
||||||
// whenever we end up with an absolute path, specify the scheme and host
|
|
||||||
newBase.Scheme = v.Scheme
|
|
||||||
newBase.Host = v.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
return MustCreateRef(newBase.String()), true
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizeRef canonicalize a Ref, using a canonical relativeBase as its absolute anchor
|
|
||||||
func normalizeRef(ref *Ref, relativeBase string) *Ref {
|
|
||||||
r := MustCreateRef(normalizeURI(ref.String(), relativeBase))
|
|
||||||
return &r
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizeBase performs a normalization of the input base path.
|
|
||||||
//
|
|
||||||
// This always yields a canonical URI (absolute), usable for the document cache.
|
|
||||||
//
|
|
||||||
// It ensures that all further internal work on basePath may safely assume
|
|
||||||
// a non-empty, cross-platform, canonical URI (i.e. absolute).
|
|
||||||
//
|
|
||||||
// This normalization tolerates windows paths (e.g. C:\x\y\File.dat) and transform this
|
|
||||||
// in a file:// URL with lower cased drive letter and path.
|
|
||||||
//
|
|
||||||
// See also: https://en.wikipedia.org/wiki/File_URI_scheme
|
|
||||||
func normalizeBase(in string) string {
|
|
||||||
u, err := url.Parse(in)
|
|
||||||
if err != nil {
|
|
||||||
specLogger.Printf("warning: invalid URI in RelativeBase %q: %v", in, err)
|
|
||||||
u, in = repairURI(in)
|
|
||||||
}
|
|
||||||
|
|
||||||
u.Fragment = "" // any fragment in the base is irrelevant
|
|
||||||
|
|
||||||
fixWindowsURI(u, in) // noop on non-windows OS
|
|
||||||
|
|
||||||
u.Path = path.Clean(u.Path)
|
|
||||||
if u.Path == "." { // empty after Clean()
|
|
||||||
u.Path = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if u.Scheme != "" {
|
|
||||||
if path.IsAbs(u.Path) || u.Scheme != fileScheme {
|
|
||||||
// this is absolute or explicitly not a local file: we're good
|
|
||||||
return u.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no scheme or file scheme with relative path: assume file and make it absolute
|
|
||||||
// enforce scheme file://... with absolute path.
|
|
||||||
//
|
|
||||||
// If the input path is relative, we anchor the path to the current working directory.
|
|
||||||
// NOTE: we may end up with a host component. Leave it unchanged: e.g. file://host/folder/file.json
|
|
||||||
|
|
||||||
u.Scheme = fileScheme
|
|
||||||
u.Path = absPath(u.Path) // platform-dependent
|
|
||||||
u.RawQuery = "" // any query component is irrelevant for a base
|
|
||||||
return u.String()
|
|
||||||
}
|
|
43
vendor/github.com/go-openapi/spec/normalizer_nonwindows.go
generated
vendored
43
vendor/github.com/go-openapi/spec/normalizer_nonwindows.go
generated
vendored
@ -1,43 +0,0 @@
|
|||||||
// +build !windows
|
|
||||||
|
|
||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/url"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// absPath makes a file path absolute and compatible with a URI path component.
|
|
||||||
//
|
|
||||||
// The parameter must be a path, not an URI.
|
|
||||||
func absPath(in string) string {
|
|
||||||
anchored, err := filepath.Abs(in)
|
|
||||||
if err != nil {
|
|
||||||
specLogger.Printf("warning: could not resolve current working directory: %v", err)
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
return anchored
|
|
||||||
}
|
|
||||||
|
|
||||||
func repairURI(in string) (*url.URL, string) {
|
|
||||||
u, _ := url.Parse("")
|
|
||||||
debugLog("repaired URI: original: %q, repaired: %q", in, "")
|
|
||||||
return u, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixWindowsURI(u *url.URL, in string) {
|
|
||||||
}
|
|
154
vendor/github.com/go-openapi/spec/normalizer_windows.go
generated
vendored
154
vendor/github.com/go-openapi/spec/normalizer_windows.go
generated
vendored
@ -1,154 +0,0 @@
|
|||||||
// -build windows
|
|
||||||
|
|
||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// absPath makes a file path absolute and compatible with a URI path component
|
|
||||||
//
|
|
||||||
// The parameter must be a path, not an URI.
|
|
||||||
func absPath(in string) string {
|
|
||||||
// NOTE(windows): filepath.Abs exhibits a special behavior on windows for empty paths.
|
|
||||||
// See https://github.com/golang/go/issues/24441
|
|
||||||
if in == "" {
|
|
||||||
in = "."
|
|
||||||
}
|
|
||||||
|
|
||||||
anchored, err := filepath.Abs(in)
|
|
||||||
if err != nil {
|
|
||||||
specLogger.Printf("warning: could not resolve current working directory: %v", err)
|
|
||||||
return in
|
|
||||||
}
|
|
||||||
|
|
||||||
pth := strings.ReplaceAll(strings.ToLower(anchored), `\`, `/`)
|
|
||||||
if !strings.HasPrefix(pth, "/") {
|
|
||||||
pth = "/" + pth
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.Clean(pth)
|
|
||||||
}
|
|
||||||
|
|
||||||
// repairURI tolerates invalid file URIs with common typos
|
|
||||||
// such as 'file://E:\folder\file', that break the regular URL parser.
|
|
||||||
//
|
|
||||||
// Adopting the same defaults as for unixes (e.g. return an empty path) would
|
|
||||||
// result into a counter-intuitive result for that case (e.g. E:\folder\file is
|
|
||||||
// eventually resolved as the current directory). The repair will detect the missing "/".
|
|
||||||
//
|
|
||||||
// Note that this only works for the file scheme.
|
|
||||||
func repairURI(in string) (*url.URL, string) {
|
|
||||||
const prefix = fileScheme + "://"
|
|
||||||
if !strings.HasPrefix(in, prefix) {
|
|
||||||
// giving up: resolve to empty path
|
|
||||||
u, _ := url.Parse("")
|
|
||||||
|
|
||||||
return u, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// attempt the repair, stripping the scheme should be sufficient
|
|
||||||
u, _ := url.Parse(strings.TrimPrefix(in, prefix))
|
|
||||||
debugLog("repaired URI: original: %q, repaired: %q", in, u.String())
|
|
||||||
|
|
||||||
return u, u.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// fixWindowsURI tolerates an absolute file path on windows such as C:\Base\File.yaml or \\host\share\Base\File.yaml
|
|
||||||
// and makes it a canonical URI: file:///c:/base/file.yaml
|
|
||||||
//
|
|
||||||
// Catch 22 notes for Windows:
|
|
||||||
//
|
|
||||||
// * There may be a drive letter on windows (it is lower-cased)
|
|
||||||
// * There may be a share UNC, e.g. \\server\folder\data.xml
|
|
||||||
// * Paths are case insensitive
|
|
||||||
// * Paths may already contain slashes
|
|
||||||
// * Paths must be slashed
|
|
||||||
//
|
|
||||||
// NOTE: there is no escaping. "/" may be valid separators just like "\".
|
|
||||||
// We don't use ToSlash() (which escapes everything) because windows now also
|
|
||||||
// tolerates the use of "/". Hence, both C:\File.yaml and C:/File.yaml will work.
|
|
||||||
func fixWindowsURI(u *url.URL, in string) {
|
|
||||||
drive := filepath.VolumeName(in)
|
|
||||||
|
|
||||||
if len(drive) > 0 {
|
|
||||||
if len(u.Scheme) == 1 && strings.EqualFold(u.Scheme, drive[:1]) { // a path with a drive letter
|
|
||||||
u.Scheme = fileScheme
|
|
||||||
u.Host = ""
|
|
||||||
u.Path = strings.Join([]string{drive, u.Opaque, u.Path}, `/`) // reconstruct the full path component (no fragment, no query)
|
|
||||||
} else if u.Host == "" && strings.HasPrefix(u.Path, drive) { // a path with a \\host volume
|
|
||||||
// NOTE: the special host@port syntax for UNC is not supported (yet)
|
|
||||||
u.Scheme = fileScheme
|
|
||||||
|
|
||||||
// this is a modified version of filepath.Dir() to apply on the VolumeName itself
|
|
||||||
i := len(drive) - 1
|
|
||||||
for i >= 0 && !os.IsPathSeparator(drive[i]) {
|
|
||||||
i--
|
|
||||||
}
|
|
||||||
host := drive[:i] // \\host\share => host
|
|
||||||
|
|
||||||
u.Path = strings.TrimPrefix(u.Path, host)
|
|
||||||
u.Host = strings.TrimPrefix(host, `\\`)
|
|
||||||
}
|
|
||||||
|
|
||||||
u.Opaque = ""
|
|
||||||
u.Path = strings.ReplaceAll(strings.ToLower(u.Path), `\`, `/`)
|
|
||||||
|
|
||||||
// ensure we form an absolute path
|
|
||||||
if !strings.HasPrefix(u.Path, "/") {
|
|
||||||
u.Path = "/" + u.Path
|
|
||||||
}
|
|
||||||
|
|
||||||
u.Path = path.Clean(u.Path)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if u.Scheme == fileScheme {
|
|
||||||
// Handle dodgy cases for file://{...} URIs on windows.
|
|
||||||
// A canonical URI should always be followed by an absolute path.
|
|
||||||
//
|
|
||||||
// Examples:
|
|
||||||
// * file:///folder/file => valid, unchanged
|
|
||||||
// * file:///c:\folder\file => slashed
|
|
||||||
// * file:///./folder/file => valid, cleaned to remove the dot
|
|
||||||
// * file:///.\folder\file => remapped to cwd
|
|
||||||
// * file:///. => dodgy, remapped to / (consistent with the behavior on unix)
|
|
||||||
// * file:///.. => dodgy, remapped to / (consistent with the behavior on unix)
|
|
||||||
if (!path.IsAbs(u.Path) && !filepath.IsAbs(u.Path)) || (strings.HasPrefix(u.Path, `/.`) && strings.Contains(u.Path, `\`)) {
|
|
||||||
// ensure we form an absolute path
|
|
||||||
u.Path, _ = filepath.Abs(strings.TrimLeft(u.Path, `/`))
|
|
||||||
if !strings.HasPrefix(u.Path, "/") {
|
|
||||||
u.Path = "/" + u.Path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
u.Path = strings.ToLower(u.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: lower case normalization does not propagate to inner resources,
|
|
||||||
// generated when rebasing: when joining a relative URI with a file to an absolute base,
|
|
||||||
// only the base is currently lower-cased.
|
|
||||||
//
|
|
||||||
// For now, we assume this is good enough for most use cases
|
|
||||||
// and try not to generate too many differences
|
|
||||||
// between the output produced on different platforms.
|
|
||||||
u.Path = path.Clean(strings.ReplaceAll(u.Path, `\`, `/`))
|
|
||||||
}
|
|
397
vendor/github.com/go-openapi/spec/operation.go
generated
vendored
397
vendor/github.com/go-openapi/spec/operation.go
generated
vendored
@ -1,397 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/gob"
|
|
||||||
"encoding/json"
|
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
gob.Register(map[string]interface{}{})
|
|
||||||
gob.Register([]interface{}{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// OperationProps describes an operation
|
|
||||||
//
|
|
||||||
// NOTES:
|
|
||||||
// - schemes, when present must be from [http, https, ws, wss]: see validate
|
|
||||||
// - Security is handled as a special case: see MarshalJSON function
|
|
||||||
type OperationProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Consumes []string `json:"consumes,omitempty"`
|
|
||||||
Produces []string `json:"produces,omitempty"`
|
|
||||||
Schemes []string `json:"schemes,omitempty"`
|
|
||||||
Tags []string `json:"tags,omitempty"`
|
|
||||||
Summary string `json:"summary,omitempty"`
|
|
||||||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
|
||||||
ID string `json:"operationId,omitempty"`
|
|
||||||
Deprecated bool `json:"deprecated,omitempty"`
|
|
||||||
Security []map[string][]string `json:"security,omitempty"`
|
|
||||||
Parameters []Parameter `json:"parameters,omitempty"`
|
|
||||||
Responses *Responses `json:"responses,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON takes care of serializing operation properties to JSON
|
|
||||||
//
|
|
||||||
// We use a custom marhaller here to handle a special cases related to
|
|
||||||
// the Security field. We need to preserve zero length slice
|
|
||||||
// while omitting the field when the value is nil/unset.
|
|
||||||
func (op OperationProps) MarshalJSON() ([]byte, error) {
|
|
||||||
type Alias OperationProps
|
|
||||||
if op.Security == nil {
|
|
||||||
return json.Marshal(&struct {
|
|
||||||
Security []map[string][]string `json:"security,omitempty"`
|
|
||||||
*Alias
|
|
||||||
}{
|
|
||||||
Security: op.Security,
|
|
||||||
Alias: (*Alias)(&op),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return json.Marshal(&struct {
|
|
||||||
Security []map[string][]string `json:"security"`
|
|
||||||
*Alias
|
|
||||||
}{
|
|
||||||
Security: op.Security,
|
|
||||||
Alias: (*Alias)(&op),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Operation describes a single API operation on a path.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#operationObject
|
|
||||||
type Operation struct {
|
|
||||||
VendorExtensible
|
|
||||||
OperationProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// SuccessResponse gets a success response model
|
|
||||||
func (o *Operation) SuccessResponse() (*Response, int, bool) {
|
|
||||||
if o.Responses == nil {
|
|
||||||
return nil, 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
responseCodes := make([]int, 0, len(o.Responses.StatusCodeResponses))
|
|
||||||
for k := range o.Responses.StatusCodeResponses {
|
|
||||||
if k >= 200 && k < 300 {
|
|
||||||
responseCodes = append(responseCodes, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(responseCodes) > 0 {
|
|
||||||
sort.Ints(responseCodes)
|
|
||||||
v := o.Responses.StatusCodeResponses[responseCodes[0]]
|
|
||||||
return &v, responseCodes[0], true
|
|
||||||
}
|
|
||||||
|
|
||||||
return o.Responses.Default, 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (o Operation) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := o.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(o.OperationProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (o *Operation) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &o.OperationProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &o.VendorExtensible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (o Operation) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(o.OperationProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(o.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
concated := swag.ConcatJSON(b1, b2)
|
|
||||||
return concated, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewOperation creates a new operation instance.
|
|
||||||
// It expects an ID as parameter but not passing an ID is also valid.
|
|
||||||
func NewOperation(id string) *Operation {
|
|
||||||
op := new(Operation)
|
|
||||||
op.ID = id
|
|
||||||
return op
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithID sets the ID property on this operation, allows for chaining.
|
|
||||||
func (o *Operation) WithID(id string) *Operation {
|
|
||||||
o.ID = id
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDescription sets the description on this operation, allows for chaining
|
|
||||||
func (o *Operation) WithDescription(description string) *Operation {
|
|
||||||
o.Description = description
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithSummary sets the summary on this operation, allows for chaining
|
|
||||||
func (o *Operation) WithSummary(summary string) *Operation {
|
|
||||||
o.Summary = summary
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithExternalDocs sets/removes the external docs for/from this operation.
|
|
||||||
// When you pass empty strings as params the external documents will be removed.
|
|
||||||
// When you pass non-empty string as one value then those values will be used on the external docs object.
|
|
||||||
// So when you pass a non-empty description, you should also pass the url and vice versa.
|
|
||||||
func (o *Operation) WithExternalDocs(description, url string) *Operation {
|
|
||||||
if description == "" && url == "" {
|
|
||||||
o.ExternalDocs = nil
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.ExternalDocs == nil {
|
|
||||||
o.ExternalDocs = &ExternalDocumentation{}
|
|
||||||
}
|
|
||||||
o.ExternalDocs.Description = description
|
|
||||||
o.ExternalDocs.URL = url
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecate marks the operation as deprecated
|
|
||||||
func (o *Operation) Deprecate() *Operation {
|
|
||||||
o.Deprecated = true
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// Undeprecate marks the operation as not deprected
|
|
||||||
func (o *Operation) Undeprecate() *Operation {
|
|
||||||
o.Deprecated = false
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithConsumes adds media types for incoming body values
|
|
||||||
func (o *Operation) WithConsumes(mediaTypes ...string) *Operation {
|
|
||||||
o.Consumes = append(o.Consumes, mediaTypes...)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithProduces adds media types for outgoing body values
|
|
||||||
func (o *Operation) WithProduces(mediaTypes ...string) *Operation {
|
|
||||||
o.Produces = append(o.Produces, mediaTypes...)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTags adds tags for this operation
|
|
||||||
func (o *Operation) WithTags(tags ...string) *Operation {
|
|
||||||
o.Tags = append(o.Tags, tags...)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddParam adds a parameter to this operation, when a parameter for that location
|
|
||||||
// and with that name already exists it will be replaced
|
|
||||||
func (o *Operation) AddParam(param *Parameter) *Operation {
|
|
||||||
if param == nil {
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, p := range o.Parameters {
|
|
||||||
if p.Name == param.Name && p.In == param.In {
|
|
||||||
params := append(o.Parameters[:i], *param)
|
|
||||||
params = append(params, o.Parameters[i+1:]...)
|
|
||||||
o.Parameters = params
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
o.Parameters = append(o.Parameters, *param)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveParam removes a parameter from the operation
|
|
||||||
func (o *Operation) RemoveParam(name, in string) *Operation {
|
|
||||||
for i, p := range o.Parameters {
|
|
||||||
if p.Name == name && p.In == in {
|
|
||||||
o.Parameters = append(o.Parameters[:i], o.Parameters[i+1:]...)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecuredWith adds a security scope to this operation.
|
|
||||||
func (o *Operation) SecuredWith(name string, scopes ...string) *Operation {
|
|
||||||
o.Security = append(o.Security, map[string][]string{name: scopes})
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDefaultResponse adds a default response to the operation.
|
|
||||||
// Passing a nil value will remove the response
|
|
||||||
func (o *Operation) WithDefaultResponse(response *Response) *Operation {
|
|
||||||
return o.RespondsWith(0, response)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RespondsWith adds a status code response to the operation.
|
|
||||||
// When the code is 0 the value of the response will be used as default response value.
|
|
||||||
// When the value of the response is nil it will be removed from the operation
|
|
||||||
func (o *Operation) RespondsWith(code int, response *Response) *Operation {
|
|
||||||
if o.Responses == nil {
|
|
||||||
o.Responses = new(Responses)
|
|
||||||
}
|
|
||||||
if code == 0 {
|
|
||||||
o.Responses.Default = response
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
if response == nil {
|
|
||||||
delete(o.Responses.StatusCodeResponses, code)
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
if o.Responses.StatusCodeResponses == nil {
|
|
||||||
o.Responses.StatusCodeResponses = make(map[int]Response)
|
|
||||||
}
|
|
||||||
o.Responses.StatusCodeResponses[code] = *response
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
type opsAlias OperationProps
|
|
||||||
|
|
||||||
type gobAlias struct {
|
|
||||||
Security []map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}
|
|
||||||
Alias *opsAlias
|
|
||||||
SecurityIsEmpty bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobEncode provides a safe gob encoder for Operation, including empty security requirements
|
|
||||||
func (o Operation) GobEncode() ([]byte, error) {
|
|
||||||
raw := struct {
|
|
||||||
Ext VendorExtensible
|
|
||||||
Props OperationProps
|
|
||||||
}{
|
|
||||||
Ext: o.VendorExtensible,
|
|
||||||
Props: o.OperationProps,
|
|
||||||
}
|
|
||||||
var b bytes.Buffer
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobDecode provides a safe gob decoder for Operation, including empty security requirements
|
|
||||||
func (o *Operation) GobDecode(b []byte) error {
|
|
||||||
var raw struct {
|
|
||||||
Ext VendorExtensible
|
|
||||||
Props OperationProps
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
err := gob.NewDecoder(buf).Decode(&raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
o.VendorExtensible = raw.Ext
|
|
||||||
o.OperationProps = raw.Props
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobEncode provides a safe gob encoder for Operation, including empty security requirements
|
|
||||||
func (op OperationProps) GobEncode() ([]byte, error) {
|
|
||||||
raw := gobAlias{
|
|
||||||
Alias: (*opsAlias)(&op),
|
|
||||||
}
|
|
||||||
|
|
||||||
var b bytes.Buffer
|
|
||||||
if op.Security == nil {
|
|
||||||
// nil security requirement
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(op.Security) == 0 {
|
|
||||||
// empty, but non-nil security requirement
|
|
||||||
raw.SecurityIsEmpty = true
|
|
||||||
raw.Alias.Security = nil
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
raw.Security = make([]map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}, 0, len(op.Security))
|
|
||||||
for _, req := range op.Security {
|
|
||||||
v := make(map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}, len(req))
|
|
||||||
for k, val := range req {
|
|
||||||
v[k] = struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}{
|
|
||||||
List: val,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raw.Security = append(raw.Security, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobDecode provides a safe gob decoder for Operation, including empty security requirements
|
|
||||||
func (op *OperationProps) GobDecode(b []byte) error {
|
|
||||||
var raw gobAlias
|
|
||||||
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
err := gob.NewDecoder(buf).Decode(&raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if raw.Alias == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case raw.SecurityIsEmpty:
|
|
||||||
// empty, but non-nil security requirement
|
|
||||||
raw.Alias.Security = []map[string][]string{}
|
|
||||||
case len(raw.Alias.Security) == 0:
|
|
||||||
// nil security requirement
|
|
||||||
raw.Alias.Security = nil
|
|
||||||
default:
|
|
||||||
raw.Alias.Security = make([]map[string][]string, 0, len(raw.Security))
|
|
||||||
for _, req := range raw.Security {
|
|
||||||
v := make(map[string][]string, len(req))
|
|
||||||
for k, val := range req {
|
|
||||||
v[k] = make([]string, 0, len(val.List))
|
|
||||||
v[k] = append(v[k], val.List...)
|
|
||||||
}
|
|
||||||
raw.Alias.Security = append(raw.Alias.Security, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*op = *(*OperationProps)(raw.Alias)
|
|
||||||
return nil
|
|
||||||
}
|
|
326
vendor/github.com/go-openapi/spec/parameter.go
generated
vendored
326
vendor/github.com/go-openapi/spec/parameter.go
generated
vendored
@ -1,326 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// QueryParam creates a query parameter
|
|
||||||
func QueryParam(name string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "query"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeaderParam creates a header parameter, this is always required by default
|
|
||||||
func HeaderParam(name string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "header", Required: true}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PathParam creates a path parameter, this is always required
|
|
||||||
func PathParam(name string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "path", Required: true}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BodyParam creates a body parameter
|
|
||||||
func BodyParam(name string, schema *Schema) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "body", Schema: schema}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormDataParam creates a body parameter
|
|
||||||
func FormDataParam(name string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "formData"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileParam creates a body parameter
|
|
||||||
func FileParam(name string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name, In: "formData"},
|
|
||||||
SimpleSchema: SimpleSchema{Type: "file"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SimpleArrayParam creates a param for a simple array (string, int, date etc)
|
|
||||||
func SimpleArrayParam(name, tpe, fmt string) *Parameter {
|
|
||||||
return &Parameter{ParamProps: ParamProps{Name: name},
|
|
||||||
SimpleSchema: SimpleSchema{Type: jsonArray, CollectionFormat: "csv",
|
|
||||||
Items: &Items{SimpleSchema: SimpleSchema{Type: tpe, Format: fmt}}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParamRef creates a parameter that's a json reference
|
|
||||||
func ParamRef(uri string) *Parameter {
|
|
||||||
p := new(Parameter)
|
|
||||||
p.Ref = MustCreateRef(uri)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParamProps describes the specific attributes of an operation parameter
|
|
||||||
//
|
|
||||||
// NOTE:
|
|
||||||
// - Schema is defined when "in" == "body": see validate
|
|
||||||
// - AllowEmptyValue is allowed where "in" == "query" || "formData"
|
|
||||||
type ParamProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
In string `json:"in,omitempty"`
|
|
||||||
Required bool `json:"required,omitempty"`
|
|
||||||
Schema *Schema `json:"schema,omitempty"`
|
|
||||||
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parameter a unique parameter is defined by a combination of a [name](#parameterName) and [location](#parameterIn).
|
|
||||||
//
|
|
||||||
// There are five possible parameter types.
|
|
||||||
// * Path - Used together with [Path Templating](#pathTemplating), where the parameter value is actually part
|
|
||||||
// of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`,
|
|
||||||
// the path parameter is `itemId`.
|
|
||||||
// * Query - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
|
|
||||||
// * Header - Custom headers that are expected as part of the request.
|
|
||||||
// * Body - The payload that's appended to the HTTP request. Since there can only be one payload, there can only be
|
|
||||||
// _one_ body parameter. The name of the body parameter has no effect on the parameter itself and is used for
|
|
||||||
// documentation purposes only. Since Form parameters are also in the payload, body and form parameters cannot exist
|
|
||||||
// together for the same operation.
|
|
||||||
// * Form - Used to describe the payload of an HTTP request when either `application/x-www-form-urlencoded` or
|
|
||||||
// `multipart/form-data` are used as the content type of the request (in Swagger's definition,
|
|
||||||
// the [`consumes`](#operationConsumes) property of an operation). This is the only parameter type that can be used
|
|
||||||
// to send files, thus supporting the `file` type. Since form parameters are sent in the payload, they cannot be
|
|
||||||
// declared together with a body parameter for the same operation. Form parameters have a different format based on
|
|
||||||
// the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4).
|
|
||||||
// * `application/x-www-form-urlencoded` - Similar to the format of Query parameters but as a payload.
|
|
||||||
// For example, `foo=1&bar=swagger` - both `foo` and `bar` are form parameters. This is normally used for simple
|
|
||||||
// parameters that are being transferred.
|
|
||||||
// * `multipart/form-data` - each parameter takes a section in the payload with an internal header.
|
|
||||||
// For example, for the header `Content-Disposition: form-data; name="submit-name"` the name of the parameter is
|
|
||||||
// `submit-name`. This type of form parameters is more commonly used for file transfers.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#parameterObject
|
|
||||||
type Parameter struct {
|
|
||||||
Refable
|
|
||||||
CommonValidations
|
|
||||||
SimpleSchema
|
|
||||||
VendorExtensible
|
|
||||||
ParamProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (p Parameter) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := p.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
if token == jsonRef {
|
|
||||||
return &p.Ref, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(p.CommonValidations, token)
|
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r != nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token)
|
|
||||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if r != nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(p.ParamProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDescription a fluent builder method for the description of the parameter
|
|
||||||
func (p *Parameter) WithDescription(description string) *Parameter {
|
|
||||||
p.Description = description
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// Named a fluent builder method to override the name of the parameter
|
|
||||||
func (p *Parameter) Named(name string) *Parameter {
|
|
||||||
p.Name = name
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithLocation a fluent builder method to override the location of the parameter
|
|
||||||
func (p *Parameter) WithLocation(in string) *Parameter {
|
|
||||||
p.In = in
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typed a fluent builder method for the type of the parameter value
|
|
||||||
func (p *Parameter) Typed(tpe, format string) *Parameter {
|
|
||||||
p.Type = tpe
|
|
||||||
p.Format = format
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectionOf a fluent builder method for an array parameter
|
|
||||||
func (p *Parameter) CollectionOf(items *Items, format string) *Parameter {
|
|
||||||
p.Type = jsonArray
|
|
||||||
p.Items = items
|
|
||||||
p.CollectionFormat = format
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDefault sets the default value on this parameter
|
|
||||||
func (p *Parameter) WithDefault(defaultValue interface{}) *Parameter {
|
|
||||||
p.AsOptional() // with default implies optional
|
|
||||||
p.Default = defaultValue
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowsEmptyValues flags this parameter as being ok with empty values
|
|
||||||
func (p *Parameter) AllowsEmptyValues() *Parameter {
|
|
||||||
p.AllowEmptyValue = true
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// NoEmptyValues flags this parameter as not liking empty values
|
|
||||||
func (p *Parameter) NoEmptyValues() *Parameter {
|
|
||||||
p.AllowEmptyValue = false
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsOptional flags this parameter as optional
|
|
||||||
func (p *Parameter) AsOptional() *Parameter {
|
|
||||||
p.Required = false
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsRequired flags this parameter as required
|
|
||||||
func (p *Parameter) AsRequired() *Parameter {
|
|
||||||
if p.Default != nil { // with a default required makes no sense
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
p.Required = true
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxLength sets a max length value
|
|
||||||
func (p *Parameter) WithMaxLength(max int64) *Parameter {
|
|
||||||
p.MaxLength = &max
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinLength sets a min length value
|
|
||||||
func (p *Parameter) WithMinLength(min int64) *Parameter {
|
|
||||||
p.MinLength = &min
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPattern sets a pattern value
|
|
||||||
func (p *Parameter) WithPattern(pattern string) *Parameter {
|
|
||||||
p.Pattern = pattern
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMultipleOf sets a multiple of value
|
|
||||||
func (p *Parameter) WithMultipleOf(number float64) *Parameter {
|
|
||||||
p.MultipleOf = &number
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaximum sets a maximum number value
|
|
||||||
func (p *Parameter) WithMaximum(max float64, exclusive bool) *Parameter {
|
|
||||||
p.Maximum = &max
|
|
||||||
p.ExclusiveMaximum = exclusive
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinimum sets a minimum number value
|
|
||||||
func (p *Parameter) WithMinimum(min float64, exclusive bool) *Parameter {
|
|
||||||
p.Minimum = &min
|
|
||||||
p.ExclusiveMinimum = exclusive
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithEnum sets a the enum values (replace)
|
|
||||||
func (p *Parameter) WithEnum(values ...interface{}) *Parameter {
|
|
||||||
p.Enum = append([]interface{}{}, values...)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxItems sets the max items
|
|
||||||
func (p *Parameter) WithMaxItems(size int64) *Parameter {
|
|
||||||
p.MaxItems = &size
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinItems sets the min items
|
|
||||||
func (p *Parameter) WithMinItems(size int64) *Parameter {
|
|
||||||
p.MinItems = &size
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// UniqueValues dictates that this array can only have unique items
|
|
||||||
func (p *Parameter) UniqueValues() *Parameter {
|
|
||||||
p.UniqueItems = true
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowDuplicates this array can have duplicates
|
|
||||||
func (p *Parameter) AllowDuplicates() *Parameter {
|
|
||||||
p.UniqueItems = false
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValidations is a fluent method to set parameter validations
|
|
||||||
func (p *Parameter) WithValidations(val CommonValidations) *Parameter {
|
|
||||||
p.SetValidations(SchemaValidations{CommonValidations: val})
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (p *Parameter) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &p.CommonValidations); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &p.Refable); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &p.SimpleSchema); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &p.ParamProps)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (p Parameter) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(p.CommonValidations)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(p.SimpleSchema)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b3, err := json.Marshal(p.Refable)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b4, err := json.Marshal(p.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b5, err := json.Marshal(p.ParamProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b3, b1, b2, b4, b5), nil
|
|
||||||
}
|
|
87
vendor/github.com/go-openapi/spec/path_item.go
generated
vendored
87
vendor/github.com/go-openapi/spec/path_item.go
generated
vendored
@ -1,87 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PathItemProps the path item specific properties
|
|
||||||
type PathItemProps struct {
|
|
||||||
Get *Operation `json:"get,omitempty"`
|
|
||||||
Put *Operation `json:"put,omitempty"`
|
|
||||||
Post *Operation `json:"post,omitempty"`
|
|
||||||
Delete *Operation `json:"delete,omitempty"`
|
|
||||||
Options *Operation `json:"options,omitempty"`
|
|
||||||
Head *Operation `json:"head,omitempty"`
|
|
||||||
Patch *Operation `json:"patch,omitempty"`
|
|
||||||
Parameters []Parameter `json:"parameters,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PathItem describes the operations available on a single path.
|
|
||||||
// A Path Item may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
|
|
||||||
// The path itself is still exposed to the documentation viewer but they will
|
|
||||||
// not know which operations and parameters are available.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#pathItemObject
|
|
||||||
type PathItem struct {
|
|
||||||
Refable
|
|
||||||
VendorExtensible
|
|
||||||
PathItemProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (p PathItem) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := p.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
if token == jsonRef {
|
|
||||||
return &p.Ref, nil
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(p.PathItemProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (p *PathItem) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &p.Refable); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &p.PathItemProps)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (p PathItem) MarshalJSON() ([]byte, error) {
|
|
||||||
b3, err := json.Marshal(p.Refable)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b4, err := json.Marshal(p.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b5, err := json.Marshal(p.PathItemProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
concated := swag.ConcatJSON(b3, b4, b5)
|
|
||||||
return concated, nil
|
|
||||||
}
|
|
97
vendor/github.com/go-openapi/spec/paths.go
generated
vendored
97
vendor/github.com/go-openapi/spec/paths.go
generated
vendored
@ -1,97 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Paths holds the relative paths to the individual endpoints.
|
|
||||||
// The path is appended to the [`basePath`](http://goo.gl/8us55a#swaggerBasePath) in order
|
|
||||||
// to construct the full URL.
|
|
||||||
// The Paths may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#pathsObject
|
|
||||||
type Paths struct {
|
|
||||||
VendorExtensible
|
|
||||||
Paths map[string]PathItem `json:"-"` // custom serializer to flatten this, each entry must start with "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (p Paths) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if pi, ok := p.Paths[token]; ok {
|
|
||||||
return &pi, nil
|
|
||||||
}
|
|
||||||
if ex, ok := p.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("object has no field %q", token)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (p *Paths) UnmarshalJSON(data []byte) error {
|
|
||||||
var res map[string]json.RawMessage
|
|
||||||
if err := json.Unmarshal(data, &res); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for k, v := range res {
|
|
||||||
if strings.HasPrefix(strings.ToLower(k), "x-") {
|
|
||||||
if p.Extensions == nil {
|
|
||||||
p.Extensions = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
var d interface{}
|
|
||||||
if err := json.Unmarshal(v, &d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.Extensions[k] = d
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(k, "/") {
|
|
||||||
if p.Paths == nil {
|
|
||||||
p.Paths = make(map[string]PathItem)
|
|
||||||
}
|
|
||||||
var pi PathItem
|
|
||||||
if err := json.Unmarshal(v, &pi); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.Paths[k] = pi
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (p Paths) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(p.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pths := make(map[string]PathItem)
|
|
||||||
for k, v := range p.Paths {
|
|
||||||
if strings.HasPrefix(k, "/") {
|
|
||||||
pths[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(pths)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
concated := swag.ConcatJSON(b1, b2)
|
|
||||||
return concated, nil
|
|
||||||
}
|
|
91
vendor/github.com/go-openapi/spec/properties.go
generated
vendored
91
vendor/github.com/go-openapi/spec/properties.go
generated
vendored
@ -1,91 +0,0 @@
|
|||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// OrderSchemaItem holds a named schema (e.g. from a property of an object)
|
|
||||||
type OrderSchemaItem struct {
|
|
||||||
Name string
|
|
||||||
Schema
|
|
||||||
}
|
|
||||||
|
|
||||||
// OrderSchemaItems is a sortable slice of named schemas.
|
|
||||||
// The ordering is defined by the x-order schema extension.
|
|
||||||
type OrderSchemaItems []OrderSchemaItem
|
|
||||||
|
|
||||||
// MarshalJSON produces a json object with keys defined by the name schemas
|
|
||||||
// of the OrderSchemaItems slice, keeping the original order of the slice.
|
|
||||||
func (items OrderSchemaItems) MarshalJSON() ([]byte, error) {
|
|
||||||
buf := bytes.NewBuffer(nil)
|
|
||||||
buf.WriteString("{")
|
|
||||||
for i := range items {
|
|
||||||
if i > 0 {
|
|
||||||
buf.WriteString(",")
|
|
||||||
}
|
|
||||||
buf.WriteString("\"")
|
|
||||||
buf.WriteString(items[i].Name)
|
|
||||||
buf.WriteString("\":")
|
|
||||||
bs, err := json.Marshal(&items[i].Schema)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf.Write(bs)
|
|
||||||
}
|
|
||||||
buf.WriteString("}")
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (items OrderSchemaItems) Len() int { return len(items) }
|
|
||||||
func (items OrderSchemaItems) Swap(i, j int) { items[i], items[j] = items[j], items[i] }
|
|
||||||
func (items OrderSchemaItems) Less(i, j int) (ret bool) {
|
|
||||||
ii, oki := items[i].Extensions.GetString("x-order")
|
|
||||||
ij, okj := items[j].Extensions.GetString("x-order")
|
|
||||||
if oki {
|
|
||||||
if okj {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
defer func() {
|
|
||||||
if err = recover(); err != nil {
|
|
||||||
ret = items[i].Name < items[j].Name
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
ret = reflect.ValueOf(ii).String() < reflect.ValueOf(ij).String()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return reflect.ValueOf(ii).Int() < reflect.ValueOf(ij).Int()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else if okj {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return items[i].Name < items[j].Name
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchemaProperties is a map representing the properties of a Schema object.
|
|
||||||
// It knows how to transform its keys into an ordered slice.
|
|
||||||
type SchemaProperties map[string]Schema
|
|
||||||
|
|
||||||
// ToOrderedSchemaItems transforms the map of properties into a sortable slice
|
|
||||||
func (properties SchemaProperties) ToOrderedSchemaItems() OrderSchemaItems {
|
|
||||||
items := make(OrderSchemaItems, 0, len(properties))
|
|
||||||
for k, v := range properties {
|
|
||||||
items = append(items, OrderSchemaItem{
|
|
||||||
Name: k,
|
|
||||||
Schema: v,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
sort.Sort(items)
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON produces properties as json, keeping their order.
|
|
||||||
func (properties SchemaProperties) MarshalJSON() ([]byte, error) {
|
|
||||||
if properties == nil {
|
|
||||||
return []byte("null"), nil
|
|
||||||
}
|
|
||||||
return json.Marshal(properties.ToOrderedSchemaItems())
|
|
||||||
}
|
|
193
vendor/github.com/go-openapi/spec/ref.go
generated
vendored
193
vendor/github.com/go-openapi/spec/ref.go
generated
vendored
@ -1,193 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/gob"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonreference"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Refable is a struct for things that accept a $ref property
|
|
||||||
type Refable struct {
|
|
||||||
Ref Ref
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals the ref to json
|
|
||||||
func (r Refable) MarshalJSON() ([]byte, error) {
|
|
||||||
return r.Ref.MarshalJSON()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshalss the ref from json
|
|
||||||
func (r *Refable) UnmarshalJSON(d []byte) error {
|
|
||||||
return json.Unmarshal(d, &r.Ref)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ref represents a json reference that is potentially resolved
|
|
||||||
type Ref struct {
|
|
||||||
jsonreference.Ref
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoteURI gets the remote uri part of the ref
|
|
||||||
func (r *Ref) RemoteURI() string {
|
|
||||||
if r.String() == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
u := *r.GetURL()
|
|
||||||
u.Fragment = ""
|
|
||||||
return u.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsValidURI returns true when the url the ref points to can be found
|
|
||||||
func (r *Ref) IsValidURI(basepaths ...string) bool {
|
|
||||||
if r.String() == "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
v := r.RemoteURI()
|
|
||||||
if v == "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.HasFullURL {
|
|
||||||
//nolint:noctx,gosec
|
|
||||||
rr, err := http.Get(v)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
defer rr.Body.Close()
|
|
||||||
|
|
||||||
return rr.StatusCode/100 == 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if !(r.HasFileScheme || r.HasFullFilePath || r.HasURLPathOnly) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for local file
|
|
||||||
pth := v
|
|
||||||
if r.HasURLPathOnly {
|
|
||||||
base := "."
|
|
||||||
if len(basepaths) > 0 {
|
|
||||||
base = filepath.Dir(filepath.Join(basepaths...))
|
|
||||||
}
|
|
||||||
p, e := filepath.Abs(filepath.ToSlash(filepath.Join(base, pth)))
|
|
||||||
if e != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
pth = p
|
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := os.Stat(filepath.ToSlash(pth))
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return !fi.IsDir()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inherits creates a new reference from a parent and a child
|
|
||||||
// If the child cannot inherit from the parent, an error is returned
|
|
||||||
func (r *Ref) Inherits(child Ref) (*Ref, error) {
|
|
||||||
ref, err := r.Ref.Inherits(child.Ref)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Ref{Ref: *ref}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRef creates a new instance of a ref object
|
|
||||||
// returns an error when the reference uri is an invalid uri
|
|
||||||
func NewRef(refURI string) (Ref, error) {
|
|
||||||
ref, err := jsonreference.New(refURI)
|
|
||||||
if err != nil {
|
|
||||||
return Ref{}, err
|
|
||||||
}
|
|
||||||
return Ref{Ref: ref}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustCreateRef creates a ref object but panics when refURI is invalid.
|
|
||||||
// Use the NewRef method for a version that returns an error.
|
|
||||||
func MustCreateRef(refURI string) Ref {
|
|
||||||
return Ref{Ref: jsonreference.MustCreateRef(refURI)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals this ref into a JSON object
|
|
||||||
func (r Ref) MarshalJSON() ([]byte, error) {
|
|
||||||
str := r.String()
|
|
||||||
if str == "" {
|
|
||||||
if r.IsRoot() {
|
|
||||||
return []byte(`{"$ref":""}`), nil
|
|
||||||
}
|
|
||||||
return []byte("{}"), nil
|
|
||||||
}
|
|
||||||
v := map[string]interface{}{"$ref": str}
|
|
||||||
return json.Marshal(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals this ref from a JSON object
|
|
||||||
func (r *Ref) UnmarshalJSON(d []byte) error {
|
|
||||||
var v map[string]interface{}
|
|
||||||
if err := json.Unmarshal(d, &v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return r.fromMap(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobEncode provides a safe gob encoder for Ref
|
|
||||||
func (r Ref) GobEncode() ([]byte, error) {
|
|
||||||
var b bytes.Buffer
|
|
||||||
raw, err := r.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobDecode provides a safe gob decoder for Ref
|
|
||||||
func (r *Ref) GobDecode(b []byte) error {
|
|
||||||
var raw []byte
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
err := gob.NewDecoder(buf).Decode(&raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(raw, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Ref) fromMap(v map[string]interface{}) error {
|
|
||||||
if v == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if vv, ok := v["$ref"]; ok {
|
|
||||||
if str, ok := vv.(string); ok {
|
|
||||||
ref, err := jsonreference.New(str)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*r = Ref{Ref: ref}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
127
vendor/github.com/go-openapi/spec/resolver.go
generated
vendored
127
vendor/github.com/go-openapi/spec/resolver.go
generated
vendored
@ -1,127 +0,0 @@
|
|||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
func resolveAnyWithBase(root interface{}, ref *Ref, result interface{}, options *ExpandOptions) error {
|
|
||||||
options = optionsOrDefault(options)
|
|
||||||
resolver := defaultSchemaLoader(root, options, nil, nil)
|
|
||||||
|
|
||||||
if err := resolver.Resolve(ref, result, options.RelativeBase); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveRefWithBase resolves a reference against a context root with preservation of base path
|
|
||||||
func ResolveRefWithBase(root interface{}, ref *Ref, options *ExpandOptions) (*Schema, error) {
|
|
||||||
result := new(Schema)
|
|
||||||
|
|
||||||
if err := resolveAnyWithBase(root, ref, result, options); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveRef resolves a reference for a schema against a context root
|
|
||||||
// ref is guaranteed to be in root (no need to go to external files)
|
|
||||||
//
|
|
||||||
// ResolveRef is ONLY called from the code generation module
|
|
||||||
func ResolveRef(root interface{}, ref *Ref) (*Schema, error) {
|
|
||||||
res, _, err := ref.GetPointer().Get(root)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch sch := res.(type) {
|
|
||||||
case Schema:
|
|
||||||
return &sch, nil
|
|
||||||
case *Schema:
|
|
||||||
return sch, nil
|
|
||||||
case map[string]interface{}:
|
|
||||||
newSch := new(Schema)
|
|
||||||
if err = swag.DynamicJSONToStruct(sch, newSch); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return newSch, nil
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("type: %T: %w", sch, ErrUnknownTypeForReference)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveParameterWithBase resolves a parameter reference against a context root and base path
|
|
||||||
func ResolveParameterWithBase(root interface{}, ref Ref, options *ExpandOptions) (*Parameter, error) {
|
|
||||||
result := new(Parameter)
|
|
||||||
|
|
||||||
if err := resolveAnyWithBase(root, &ref, result, options); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveParameter resolves a parameter reference against a context root
|
|
||||||
func ResolveParameter(root interface{}, ref Ref) (*Parameter, error) {
|
|
||||||
return ResolveParameterWithBase(root, ref, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveResponseWithBase resolves response a reference against a context root and base path
|
|
||||||
func ResolveResponseWithBase(root interface{}, ref Ref, options *ExpandOptions) (*Response, error) {
|
|
||||||
result := new(Response)
|
|
||||||
|
|
||||||
err := resolveAnyWithBase(root, &ref, result, options)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveResponse resolves response a reference against a context root
|
|
||||||
func ResolveResponse(root interface{}, ref Ref) (*Response, error) {
|
|
||||||
return ResolveResponseWithBase(root, ref, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolvePathItemWithBase resolves response a path item against a context root and base path
|
|
||||||
func ResolvePathItemWithBase(root interface{}, ref Ref, options *ExpandOptions) (*PathItem, error) {
|
|
||||||
result := new(PathItem)
|
|
||||||
|
|
||||||
if err := resolveAnyWithBase(root, &ref, result, options); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolvePathItem resolves response a path item against a context root and base path
|
|
||||||
//
|
|
||||||
// Deprecated: use ResolvePathItemWithBase instead
|
|
||||||
func ResolvePathItem(root interface{}, ref Ref, options *ExpandOptions) (*PathItem, error) {
|
|
||||||
return ResolvePathItemWithBase(root, ref, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveItemsWithBase resolves parameter items reference against a context root and base path.
|
|
||||||
//
|
|
||||||
// NOTE: stricly speaking, this construct is not supported by Swagger 2.0.
|
|
||||||
// Similarly, $ref are forbidden in response headers.
|
|
||||||
func ResolveItemsWithBase(root interface{}, ref Ref, options *ExpandOptions) (*Items, error) {
|
|
||||||
result := new(Items)
|
|
||||||
|
|
||||||
if err := resolveAnyWithBase(root, &ref, result, options); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveItems resolves parameter items reference against a context root and base path.
|
|
||||||
//
|
|
||||||
// Deprecated: use ResolveItemsWithBase instead
|
|
||||||
func ResolveItems(root interface{}, ref Ref, options *ExpandOptions) (*Items, error) {
|
|
||||||
return ResolveItemsWithBase(root, ref, options)
|
|
||||||
}
|
|
152
vendor/github.com/go-openapi/spec/response.go
generated
vendored
152
vendor/github.com/go-openapi/spec/response.go
generated
vendored
@ -1,152 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResponseProps properties specific to a response
|
|
||||||
type ResponseProps struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Schema *Schema `json:"schema,omitempty"`
|
|
||||||
Headers map[string]Header `json:"headers,omitempty"`
|
|
||||||
Examples map[string]interface{} `json:"examples,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response describes a single response from an API Operation.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#responseObject
|
|
||||||
type Response struct {
|
|
||||||
Refable
|
|
||||||
ResponseProps
|
|
||||||
VendorExtensible
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (r Response) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := r.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
if token == "$ref" {
|
|
||||||
return &r.Ref, nil
|
|
||||||
}
|
|
||||||
ptr, _, err := jsonpointer.GetForToken(r.ResponseProps, token)
|
|
||||||
return ptr, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (r *Response) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &r.ResponseProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &r.Refable); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &r.VendorExtensible)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (r Response) MarshalJSON() ([]byte, error) {
|
|
||||||
var (
|
|
||||||
b1 []byte
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if r.Ref.String() == "" {
|
|
||||||
// when there is no $ref, empty description is rendered as an empty string
|
|
||||||
b1, err = json.Marshal(r.ResponseProps)
|
|
||||||
} else {
|
|
||||||
// when there is $ref inside the schema, description should be omitempty-ied
|
|
||||||
b1, err = json.Marshal(struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Schema *Schema `json:"schema,omitempty"`
|
|
||||||
Headers map[string]Header `json:"headers,omitempty"`
|
|
||||||
Examples map[string]interface{} `json:"examples,omitempty"`
|
|
||||||
}{
|
|
||||||
Description: r.ResponseProps.Description,
|
|
||||||
Schema: r.ResponseProps.Schema,
|
|
||||||
Examples: r.ResponseProps.Examples,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
b2, err := json.Marshal(r.Refable)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b3, err := json.Marshal(r.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2, b3), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewResponse creates a new response instance
|
|
||||||
func NewResponse() *Response {
|
|
||||||
return new(Response)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResponseRef creates a response as a json reference
|
|
||||||
func ResponseRef(url string) *Response {
|
|
||||||
resp := NewResponse()
|
|
||||||
resp.Ref = MustCreateRef(url)
|
|
||||||
return resp
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDescription sets the description on this response, allows for chaining
|
|
||||||
func (r *Response) WithDescription(description string) *Response {
|
|
||||||
r.Description = description
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithSchema sets the schema on this response, allows for chaining.
|
|
||||||
// Passing a nil argument removes the schema from this response
|
|
||||||
func (r *Response) WithSchema(schema *Schema) *Response {
|
|
||||||
r.Schema = schema
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddHeader adds a header to this response
|
|
||||||
func (r *Response) AddHeader(name string, header *Header) *Response {
|
|
||||||
if header == nil {
|
|
||||||
return r.RemoveHeader(name)
|
|
||||||
}
|
|
||||||
if r.Headers == nil {
|
|
||||||
r.Headers = make(map[string]Header)
|
|
||||||
}
|
|
||||||
r.Headers[name] = *header
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveHeader removes a header from this response
|
|
||||||
func (r *Response) RemoveHeader(name string) *Response {
|
|
||||||
delete(r.Headers, name)
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddExample adds an example to this response
|
|
||||||
func (r *Response) AddExample(mediaType string, example interface{}) *Response {
|
|
||||||
if r.Examples == nil {
|
|
||||||
r.Examples = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
r.Examples[mediaType] = example
|
|
||||||
return r
|
|
||||||
}
|
|
127
vendor/github.com/go-openapi/spec/responses.go
generated
vendored
127
vendor/github.com/go-openapi/spec/responses.go
generated
vendored
@ -1,127 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Responses is a container for the expected responses of an operation.
|
|
||||||
// The container maps a HTTP response code to the expected response.
|
|
||||||
// It is not expected from the documentation to necessarily cover all possible HTTP response codes,
|
|
||||||
// since they may not be known in advance. However, it is expected from the documentation to cover
|
|
||||||
// a successful operation response and any known errors.
|
|
||||||
//
|
|
||||||
// The `default` can be used a default response object for all HTTP codes that are not covered
|
|
||||||
// individually by the specification.
|
|
||||||
//
|
|
||||||
// The `Responses Object` MUST contain at least one response code, and it SHOULD be the response
|
|
||||||
// for a successful operation call.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#responsesObject
|
|
||||||
type Responses struct {
|
|
||||||
VendorExtensible
|
|
||||||
ResponsesProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (r Responses) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if token == "default" {
|
|
||||||
return r.Default, nil
|
|
||||||
}
|
|
||||||
if ex, ok := r.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
if i, err := strconv.Atoi(token); err == nil {
|
|
||||||
if scr, ok := r.StatusCodeResponses[i]; ok {
|
|
||||||
return scr, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("object has no field %q", token)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
|
||||||
func (r *Responses) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &r.ResponsesProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &r.VendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if reflect.DeepEqual(ResponsesProps{}, r.ResponsesProps) {
|
|
||||||
r.ResponsesProps = ResponsesProps{}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this items object to JSON
|
|
||||||
func (r Responses) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(r.ResponsesProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(r.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
concated := swag.ConcatJSON(b1, b2)
|
|
||||||
return concated, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResponsesProps describes all responses for an operation.
|
|
||||||
// It tells what is the default response and maps all responses with a
|
|
||||||
// HTTP status code.
|
|
||||||
type ResponsesProps struct {
|
|
||||||
Default *Response
|
|
||||||
StatusCodeResponses map[int]Response
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals responses as JSON
|
|
||||||
func (r ResponsesProps) MarshalJSON() ([]byte, error) {
|
|
||||||
toser := map[string]Response{}
|
|
||||||
if r.Default != nil {
|
|
||||||
toser["default"] = *r.Default
|
|
||||||
}
|
|
||||||
for k, v := range r.StatusCodeResponses {
|
|
||||||
toser[strconv.Itoa(k)] = v
|
|
||||||
}
|
|
||||||
return json.Marshal(toser)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals responses from JSON
|
|
||||||
func (r *ResponsesProps) UnmarshalJSON(data []byte) error {
|
|
||||||
var res map[string]Response
|
|
||||||
if err := json.Unmarshal(data, &res); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if v, ok := res["default"]; ok {
|
|
||||||
r.Default = &v
|
|
||||||
delete(res, "default")
|
|
||||||
}
|
|
||||||
for k, v := range res {
|
|
||||||
if nk, err := strconv.Atoi(k); err == nil {
|
|
||||||
if r.StatusCodeResponses == nil {
|
|
||||||
r.StatusCodeResponses = map[int]Response{}
|
|
||||||
}
|
|
||||||
r.StatusCodeResponses[nk] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
646
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
646
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
@ -1,646 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BooleanProperty creates a boolean property
|
|
||||||
func BooleanProperty() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"boolean"}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BoolProperty creates a boolean property
|
|
||||||
func BoolProperty() *Schema { return BooleanProperty() }
|
|
||||||
|
|
||||||
// StringProperty creates a string property
|
|
||||||
func StringProperty() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CharProperty creates a string property
|
|
||||||
func CharProperty() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float64Property creates a float64/double property
|
|
||||||
func Float64Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "double"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Float32Property creates a float32/float property
|
|
||||||
func Float32Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"number"}, Format: "float"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int8Property creates an int8 property
|
|
||||||
func Int8Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int8"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int16Property creates an int16 property
|
|
||||||
func Int16Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int16"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int32Property creates an int32 property
|
|
||||||
func Int32Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int32"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int64Property creates an int64 property
|
|
||||||
func Int64Property() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int64"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StrFmtProperty creates a property for the named string format
|
|
||||||
func StrFmtProperty(format string) *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: format}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DateProperty creates a date property
|
|
||||||
func DateProperty() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DateTimeProperty creates a date time property
|
|
||||||
func DateTimeProperty() *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"string"}, Format: "date-time"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MapProperty creates a map property
|
|
||||||
func MapProperty(property *Schema) *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"object"},
|
|
||||||
AdditionalProperties: &SchemaOrBool{Allows: true, Schema: property}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RefProperty creates a ref property
|
|
||||||
func RefProperty(name string) *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RefSchema creates a ref property
|
|
||||||
func RefSchema(name string) *Schema {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Ref: MustCreateRef(name)}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ArrayProperty creates an array property
|
|
||||||
func ArrayProperty(items *Schema) *Schema {
|
|
||||||
if items == nil {
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Type: []string{"array"}}}
|
|
||||||
}
|
|
||||||
return &Schema{SchemaProps: SchemaProps{Items: &SchemaOrArray{Schema: items}, Type: []string{"array"}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ComposedSchema creates a schema with allOf
|
|
||||||
func ComposedSchema(schemas ...Schema) *Schema {
|
|
||||||
s := new(Schema)
|
|
||||||
s.AllOf = schemas
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchemaURL represents a schema url
|
|
||||||
type SchemaURL string
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (r SchemaURL) MarshalJSON() ([]byte, error) {
|
|
||||||
if r == "" {
|
|
||||||
return []byte("{}"), nil
|
|
||||||
}
|
|
||||||
v := map[string]interface{}{"$schema": string(r)}
|
|
||||||
return json.Marshal(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshal this from JSON
|
|
||||||
func (r *SchemaURL) UnmarshalJSON(data []byte) error {
|
|
||||||
var v map[string]interface{}
|
|
||||||
if err := json.Unmarshal(data, &v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return r.fromMap(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *SchemaURL) fromMap(v map[string]interface{}) error {
|
|
||||||
if v == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if vv, ok := v["$schema"]; ok {
|
|
||||||
if str, ok := vv.(string); ok {
|
|
||||||
u, err := url.Parse(str)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*r = SchemaURL(u.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchemaProps describes a JSON schema (draft 4)
|
|
||||||
type SchemaProps struct {
|
|
||||||
ID string `json:"id,omitempty"`
|
|
||||||
Ref Ref `json:"-"`
|
|
||||||
Schema SchemaURL `json:"-"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Type StringOrArray `json:"type,omitempty"`
|
|
||||||
Nullable bool `json:"nullable,omitempty"`
|
|
||||||
Format string `json:"format,omitempty"`
|
|
||||||
Title string `json:"title,omitempty"`
|
|
||||||
Default interface{} `json:"default,omitempty"`
|
|
||||||
Maximum *float64 `json:"maximum,omitempty"`
|
|
||||||
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
|
|
||||||
Minimum *float64 `json:"minimum,omitempty"`
|
|
||||||
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
|
|
||||||
MaxLength *int64 `json:"maxLength,omitempty"`
|
|
||||||
MinLength *int64 `json:"minLength,omitempty"`
|
|
||||||
Pattern string `json:"pattern,omitempty"`
|
|
||||||
MaxItems *int64 `json:"maxItems,omitempty"`
|
|
||||||
MinItems *int64 `json:"minItems,omitempty"`
|
|
||||||
UniqueItems bool `json:"uniqueItems,omitempty"`
|
|
||||||
MultipleOf *float64 `json:"multipleOf,omitempty"`
|
|
||||||
Enum []interface{} `json:"enum,omitempty"`
|
|
||||||
MaxProperties *int64 `json:"maxProperties,omitempty"`
|
|
||||||
MinProperties *int64 `json:"minProperties,omitempty"`
|
|
||||||
Required []string `json:"required,omitempty"`
|
|
||||||
Items *SchemaOrArray `json:"items,omitempty"`
|
|
||||||
AllOf []Schema `json:"allOf,omitempty"`
|
|
||||||
OneOf []Schema `json:"oneOf,omitempty"`
|
|
||||||
AnyOf []Schema `json:"anyOf,omitempty"`
|
|
||||||
Not *Schema `json:"not,omitempty"`
|
|
||||||
Properties SchemaProperties `json:"properties,omitempty"`
|
|
||||||
AdditionalProperties *SchemaOrBool `json:"additionalProperties,omitempty"`
|
|
||||||
PatternProperties SchemaProperties `json:"patternProperties,omitempty"`
|
|
||||||
Dependencies Dependencies `json:"dependencies,omitempty"`
|
|
||||||
AdditionalItems *SchemaOrBool `json:"additionalItems,omitempty"`
|
|
||||||
Definitions Definitions `json:"definitions,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SwaggerSchemaProps are additional properties supported by swagger schemas, but not JSON-schema (draft 4)
|
|
||||||
type SwaggerSchemaProps struct {
|
|
||||||
Discriminator string `json:"discriminator,omitempty"`
|
|
||||||
ReadOnly bool `json:"readOnly,omitempty"`
|
|
||||||
XML *XMLObject `json:"xml,omitempty"`
|
|
||||||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
|
||||||
Example interface{} `json:"example,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Schema the schema object allows the definition of input and output data types.
|
|
||||||
// These types can be objects, but also primitives and arrays.
|
|
||||||
// This object is based on the [JSON Schema Specification Draft 4](http://json-schema.org/)
|
|
||||||
// and uses a predefined subset of it.
|
|
||||||
// On top of this subset, there are extensions provided by this specification to allow for more complete documentation.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#schemaObject
|
|
||||||
type Schema struct {
|
|
||||||
VendorExtensible
|
|
||||||
SchemaProps
|
|
||||||
SwaggerSchemaProps
|
|
||||||
ExtraProps map[string]interface{} `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (s Schema) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := s.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if ex, ok := s.ExtraProps[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.SchemaProps, token)
|
|
||||||
if r != nil || (err != nil && !strings.HasPrefix(err.Error(), "object has no field")) {
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
r, _, err = jsonpointer.GetForToken(s.SwaggerSchemaProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithID sets the id for this schema, allows for chaining
|
|
||||||
func (s *Schema) WithID(id string) *Schema {
|
|
||||||
s.ID = id
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTitle sets the title for this schema, allows for chaining
|
|
||||||
func (s *Schema) WithTitle(title string) *Schema {
|
|
||||||
s.Title = title
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDescription sets the description for this schema, allows for chaining
|
|
||||||
func (s *Schema) WithDescription(description string) *Schema {
|
|
||||||
s.Description = description
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithProperties sets the properties for this schema
|
|
||||||
func (s *Schema) WithProperties(schemas map[string]Schema) *Schema {
|
|
||||||
s.Properties = schemas
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetProperty sets a property on this schema
|
|
||||||
func (s *Schema) SetProperty(name string, schema Schema) *Schema {
|
|
||||||
if s.Properties == nil {
|
|
||||||
s.Properties = make(map[string]Schema)
|
|
||||||
}
|
|
||||||
s.Properties[name] = schema
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithAllOf sets the all of property
|
|
||||||
func (s *Schema) WithAllOf(schemas ...Schema) *Schema {
|
|
||||||
s.AllOf = schemas
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxProperties sets the max number of properties an object can have
|
|
||||||
func (s *Schema) WithMaxProperties(max int64) *Schema {
|
|
||||||
s.MaxProperties = &max
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinProperties sets the min number of properties an object must have
|
|
||||||
func (s *Schema) WithMinProperties(min int64) *Schema {
|
|
||||||
s.MinProperties = &min
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Typed sets the type of this schema for a single value item
|
|
||||||
func (s *Schema) Typed(tpe, format string) *Schema {
|
|
||||||
s.Type = []string{tpe}
|
|
||||||
s.Format = format
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddType adds a type with potential format to the types for this schema
|
|
||||||
func (s *Schema) AddType(tpe, format string) *Schema {
|
|
||||||
s.Type = append(s.Type, tpe)
|
|
||||||
if format != "" {
|
|
||||||
s.Format = format
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsNullable flags this schema as nullable.
|
|
||||||
func (s *Schema) AsNullable() *Schema {
|
|
||||||
s.Nullable = true
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectionOf a fluent builder method for an array parameter
|
|
||||||
func (s *Schema) CollectionOf(items Schema) *Schema {
|
|
||||||
s.Type = []string{jsonArray}
|
|
||||||
s.Items = &SchemaOrArray{Schema: &items}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDefault sets the default value on this parameter
|
|
||||||
func (s *Schema) WithDefault(defaultValue interface{}) *Schema {
|
|
||||||
s.Default = defaultValue
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithRequired flags this parameter as required
|
|
||||||
func (s *Schema) WithRequired(items ...string) *Schema {
|
|
||||||
s.Required = items
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddRequired adds field names to the required properties array
|
|
||||||
func (s *Schema) AddRequired(items ...string) *Schema {
|
|
||||||
s.Required = append(s.Required, items...)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxLength sets a max length value
|
|
||||||
func (s *Schema) WithMaxLength(max int64) *Schema {
|
|
||||||
s.MaxLength = &max
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinLength sets a min length value
|
|
||||||
func (s *Schema) WithMinLength(min int64) *Schema {
|
|
||||||
s.MinLength = &min
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPattern sets a pattern value
|
|
||||||
func (s *Schema) WithPattern(pattern string) *Schema {
|
|
||||||
s.Pattern = pattern
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMultipleOf sets a multiple of value
|
|
||||||
func (s *Schema) WithMultipleOf(number float64) *Schema {
|
|
||||||
s.MultipleOf = &number
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaximum sets a maximum number value
|
|
||||||
func (s *Schema) WithMaximum(max float64, exclusive bool) *Schema {
|
|
||||||
s.Maximum = &max
|
|
||||||
s.ExclusiveMaximum = exclusive
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinimum sets a minimum number value
|
|
||||||
func (s *Schema) WithMinimum(min float64, exclusive bool) *Schema {
|
|
||||||
s.Minimum = &min
|
|
||||||
s.ExclusiveMinimum = exclusive
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithEnum sets a the enum values (replace)
|
|
||||||
func (s *Schema) WithEnum(values ...interface{}) *Schema {
|
|
||||||
s.Enum = append([]interface{}{}, values...)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMaxItems sets the max items
|
|
||||||
func (s *Schema) WithMaxItems(size int64) *Schema {
|
|
||||||
s.MaxItems = &size
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMinItems sets the min items
|
|
||||||
func (s *Schema) WithMinItems(size int64) *Schema {
|
|
||||||
s.MinItems = &size
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// UniqueValues dictates that this array can only have unique items
|
|
||||||
func (s *Schema) UniqueValues() *Schema {
|
|
||||||
s.UniqueItems = true
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowDuplicates this array can have duplicates
|
|
||||||
func (s *Schema) AllowDuplicates() *Schema {
|
|
||||||
s.UniqueItems = false
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToAllOf adds a schema to the allOf property
|
|
||||||
func (s *Schema) AddToAllOf(schemas ...Schema) *Schema {
|
|
||||||
s.AllOf = append(s.AllOf, schemas...)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDiscriminator sets the name of the discriminator field
|
|
||||||
func (s *Schema) WithDiscriminator(discriminator string) *Schema {
|
|
||||||
s.Discriminator = discriminator
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsReadOnly flags this schema as readonly
|
|
||||||
func (s *Schema) AsReadOnly() *Schema {
|
|
||||||
s.ReadOnly = true
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsWritable flags this schema as writeable (not read-only)
|
|
||||||
func (s *Schema) AsWritable() *Schema {
|
|
||||||
s.ReadOnly = false
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithExample sets the example for this schema
|
|
||||||
func (s *Schema) WithExample(example interface{}) *Schema {
|
|
||||||
s.Example = example
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithExternalDocs sets/removes the external docs for/from this schema.
|
|
||||||
// When you pass empty strings as params the external documents will be removed.
|
|
||||||
// When you pass non-empty string as one value then those values will be used on the external docs object.
|
|
||||||
// So when you pass a non-empty description, you should also pass the url and vice versa.
|
|
||||||
func (s *Schema) WithExternalDocs(description, url string) *Schema {
|
|
||||||
if description == "" && url == "" {
|
|
||||||
s.ExternalDocs = nil
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.ExternalDocs == nil {
|
|
||||||
s.ExternalDocs = &ExternalDocumentation{}
|
|
||||||
}
|
|
||||||
s.ExternalDocs.Description = description
|
|
||||||
s.ExternalDocs.URL = url
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithXMLName sets the xml name for the object
|
|
||||||
func (s *Schema) WithXMLName(name string) *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Name = name
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithXMLNamespace sets the xml namespace for the object
|
|
||||||
func (s *Schema) WithXMLNamespace(namespace string) *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Namespace = namespace
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithXMLPrefix sets the xml prefix for the object
|
|
||||||
func (s *Schema) WithXMLPrefix(prefix string) *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Prefix = prefix
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsXMLAttribute flags this object as xml attribute
|
|
||||||
func (s *Schema) AsXMLAttribute() *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Attribute = true
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsXMLElement flags this object as an xml node
|
|
||||||
func (s *Schema) AsXMLElement() *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Attribute = false
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsWrappedXML flags this object as wrapped, this is mostly useful for array types
|
|
||||||
func (s *Schema) AsWrappedXML() *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Wrapped = true
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsUnwrappedXML flags this object as an xml node
|
|
||||||
func (s *Schema) AsUnwrappedXML() *Schema {
|
|
||||||
if s.XML == nil {
|
|
||||||
s.XML = new(XMLObject)
|
|
||||||
}
|
|
||||||
s.XML.Wrapped = false
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetValidations defines all schema validations.
|
|
||||||
//
|
|
||||||
// NOTE: Required, ReadOnly, AllOf, AnyOf, OneOf and Not are not considered.
|
|
||||||
func (s *Schema) SetValidations(val SchemaValidations) {
|
|
||||||
s.Maximum = val.Maximum
|
|
||||||
s.ExclusiveMaximum = val.ExclusiveMaximum
|
|
||||||
s.Minimum = val.Minimum
|
|
||||||
s.ExclusiveMinimum = val.ExclusiveMinimum
|
|
||||||
s.MaxLength = val.MaxLength
|
|
||||||
s.MinLength = val.MinLength
|
|
||||||
s.Pattern = val.Pattern
|
|
||||||
s.MaxItems = val.MaxItems
|
|
||||||
s.MinItems = val.MinItems
|
|
||||||
s.UniqueItems = val.UniqueItems
|
|
||||||
s.MultipleOf = val.MultipleOf
|
|
||||||
s.Enum = val.Enum
|
|
||||||
s.MinProperties = val.MinProperties
|
|
||||||
s.MaxProperties = val.MaxProperties
|
|
||||||
s.PatternProperties = val.PatternProperties
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValidations is a fluent method to set schema validations
|
|
||||||
func (s *Schema) WithValidations(val SchemaValidations) *Schema {
|
|
||||||
s.SetValidations(val)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validations returns a clone of the validations for this schema
|
|
||||||
func (s Schema) Validations() SchemaValidations {
|
|
||||||
return SchemaValidations{
|
|
||||||
CommonValidations: CommonValidations{
|
|
||||||
Maximum: s.Maximum,
|
|
||||||
ExclusiveMaximum: s.ExclusiveMaximum,
|
|
||||||
Minimum: s.Minimum,
|
|
||||||
ExclusiveMinimum: s.ExclusiveMinimum,
|
|
||||||
MaxLength: s.MaxLength,
|
|
||||||
MinLength: s.MinLength,
|
|
||||||
Pattern: s.Pattern,
|
|
||||||
MaxItems: s.MaxItems,
|
|
||||||
MinItems: s.MinItems,
|
|
||||||
UniqueItems: s.UniqueItems,
|
|
||||||
MultipleOf: s.MultipleOf,
|
|
||||||
Enum: s.Enum,
|
|
||||||
},
|
|
||||||
MinProperties: s.MinProperties,
|
|
||||||
MaxProperties: s.MaxProperties,
|
|
||||||
PatternProperties: s.PatternProperties,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (s Schema) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(s.SchemaProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("schema props %v", err)
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(s.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("vendor props %v", err)
|
|
||||||
}
|
|
||||||
b3, err := s.Ref.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("ref prop %v", err)
|
|
||||||
}
|
|
||||||
b4, err := s.Schema.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("schema prop %v", err)
|
|
||||||
}
|
|
||||||
b5, err := json.Marshal(s.SwaggerSchemaProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("common validations %v", err)
|
|
||||||
}
|
|
||||||
var b6 []byte
|
|
||||||
if s.ExtraProps != nil {
|
|
||||||
jj, err := json.Marshal(s.ExtraProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("extra props %v", err)
|
|
||||||
}
|
|
||||||
b6 = jj
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2, b3, b4, b5, b6), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON marshal this from JSON
|
|
||||||
func (s *Schema) UnmarshalJSON(data []byte) error {
|
|
||||||
props := struct {
|
|
||||||
SchemaProps
|
|
||||||
SwaggerSchemaProps
|
|
||||||
}{}
|
|
||||||
if err := json.Unmarshal(data, &props); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sch := Schema{
|
|
||||||
SchemaProps: props.SchemaProps,
|
|
||||||
SwaggerSchemaProps: props.SwaggerSchemaProps,
|
|
||||||
}
|
|
||||||
|
|
||||||
var d map[string]interface{}
|
|
||||||
if err := json.Unmarshal(data, &d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = sch.Ref.fromMap(d)
|
|
||||||
_ = sch.Schema.fromMap(d)
|
|
||||||
|
|
||||||
delete(d, "$ref")
|
|
||||||
delete(d, "$schema")
|
|
||||||
for _, pn := range swag.DefaultJSONNameProvider.GetJSONNames(s) {
|
|
||||||
delete(d, pn)
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, vv := range d {
|
|
||||||
lk := strings.ToLower(k)
|
|
||||||
if strings.HasPrefix(lk, "x-") {
|
|
||||||
if sch.Extensions == nil {
|
|
||||||
sch.Extensions = map[string]interface{}{}
|
|
||||||
}
|
|
||||||
sch.Extensions[k] = vv
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if sch.ExtraProps == nil {
|
|
||||||
sch.ExtraProps = map[string]interface{}{}
|
|
||||||
}
|
|
||||||
sch.ExtraProps[k] = vv
|
|
||||||
}
|
|
||||||
|
|
||||||
*s = sch
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
331
vendor/github.com/go-openapi/spec/schema_loader.go
generated
vendored
331
vendor/github.com/go-openapi/spec/schema_loader.go
generated
vendored
@ -1,331 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/url"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PathLoader is a function to use when loading remote refs.
|
|
||||||
//
|
|
||||||
// This is a package level default. It may be overridden or bypassed by
|
|
||||||
// specifying the loader in ExpandOptions.
|
|
||||||
//
|
|
||||||
// NOTE: if you are using the go-openapi/loads package, it will override
|
|
||||||
// this value with its own default (a loader to retrieve YAML documents as
|
|
||||||
// well as JSON ones).
|
|
||||||
var PathLoader = func(pth string) (json.RawMessage, error) {
|
|
||||||
data, err := swag.LoadFromFileOrHTTP(pth)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return json.RawMessage(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// resolverContext allows to share a context during spec processing.
|
|
||||||
// At the moment, it just holds the index of circular references found.
|
|
||||||
type resolverContext struct {
|
|
||||||
// circulars holds all visited circular references, to shortcircuit $ref resolution.
|
|
||||||
//
|
|
||||||
// This structure is privately instantiated and needs not be locked against
|
|
||||||
// concurrent access, unless we chose to implement a parallel spec walking.
|
|
||||||
circulars map[string]bool
|
|
||||||
basePath string
|
|
||||||
loadDoc func(string) (json.RawMessage, error)
|
|
||||||
rootID string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newResolverContext(options *ExpandOptions) *resolverContext {
|
|
||||||
expandOptions := optionsOrDefault(options)
|
|
||||||
|
|
||||||
// path loader may be overridden by options
|
|
||||||
var loader func(string) (json.RawMessage, error)
|
|
||||||
if expandOptions.PathLoader == nil {
|
|
||||||
loader = PathLoader
|
|
||||||
} else {
|
|
||||||
loader = expandOptions.PathLoader
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resolverContext{
|
|
||||||
circulars: make(map[string]bool),
|
|
||||||
basePath: expandOptions.RelativeBase, // keep the root base path in context
|
|
||||||
loadDoc: loader,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type schemaLoader struct {
|
|
||||||
root interface{}
|
|
||||||
options *ExpandOptions
|
|
||||||
cache ResolutionCache
|
|
||||||
context *resolverContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) transitiveResolver(basePath string, ref Ref) *schemaLoader {
|
|
||||||
if ref.IsRoot() || ref.HasFragmentOnly {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
baseRef := MustCreateRef(basePath)
|
|
||||||
currentRef := normalizeRef(&ref, basePath)
|
|
||||||
if strings.HasPrefix(currentRef.String(), baseRef.String()) {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// set a new root against which to resolve
|
|
||||||
rootURL := currentRef.GetURL()
|
|
||||||
rootURL.Fragment = ""
|
|
||||||
root, _ := r.cache.Get(rootURL.String())
|
|
||||||
|
|
||||||
// shallow copy of resolver options to set a new RelativeBase when
|
|
||||||
// traversing multiple documents
|
|
||||||
newOptions := r.options
|
|
||||||
newOptions.RelativeBase = rootURL.String()
|
|
||||||
|
|
||||||
return defaultSchemaLoader(root, newOptions, r.cache, r.context)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) updateBasePath(transitive *schemaLoader, basePath string) string {
|
|
||||||
if transitive != r {
|
|
||||||
if transitive.options != nil && transitive.options.RelativeBase != "" {
|
|
||||||
return normalizeBase(transitive.options.RelativeBase)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return basePath
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath string) error {
|
|
||||||
tgt := reflect.ValueOf(target)
|
|
||||||
if tgt.Kind() != reflect.Ptr {
|
|
||||||
return ErrResolveRefNeedsAPointer
|
|
||||||
}
|
|
||||||
|
|
||||||
if ref.GetURL() == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
res interface{}
|
|
||||||
data interface{}
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
// Resolve against the root if it isn't nil, and if ref is pointing at the root, or has a fragment only which means
|
|
||||||
// it is pointing somewhere in the root.
|
|
||||||
root := r.root
|
|
||||||
if (ref.IsRoot() || ref.HasFragmentOnly) && root == nil && basePath != "" {
|
|
||||||
if baseRef, erb := NewRef(basePath); erb == nil {
|
|
||||||
root, _, _, _ = r.load(baseRef.GetURL())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ref.IsRoot() || ref.HasFragmentOnly) && root != nil {
|
|
||||||
data = root
|
|
||||||
} else {
|
|
||||||
baseRef := normalizeRef(ref, basePath)
|
|
||||||
data, _, _, err = r.load(baseRef.GetURL())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res = data
|
|
||||||
if ref.String() != "" {
|
|
||||||
res, _, err = ref.GetPointer().Get(data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return swag.DynamicJSONToStruct(res, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error) {
|
|
||||||
debugLog("loading schema from url: %s", refURL)
|
|
||||||
toFetch := *refURL
|
|
||||||
toFetch.Fragment = ""
|
|
||||||
|
|
||||||
var err error
|
|
||||||
pth := toFetch.String()
|
|
||||||
normalized := normalizeBase(pth)
|
|
||||||
debugLog("loading doc from: %s", normalized)
|
|
||||||
|
|
||||||
data, fromCache := r.cache.Get(normalized)
|
|
||||||
if fromCache {
|
|
||||||
return data, toFetch, fromCache, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := r.context.loadDoc(normalized)
|
|
||||||
if err != nil {
|
|
||||||
return nil, url.URL{}, false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var doc interface{}
|
|
||||||
if err := json.Unmarshal(b, &doc); err != nil {
|
|
||||||
return nil, url.URL{}, false, err
|
|
||||||
}
|
|
||||||
r.cache.Set(normalized, doc)
|
|
||||||
|
|
||||||
return doc, toFetch, fromCache, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isCircular detects cycles in sequences of $ref.
|
|
||||||
//
|
|
||||||
// It relies on a private context (which needs not be locked).
|
|
||||||
func (r *schemaLoader) isCircular(ref *Ref, basePath string, parentRefs ...string) (foundCycle bool) {
|
|
||||||
normalizedRef := normalizeURI(ref.String(), basePath)
|
|
||||||
if _, ok := r.context.circulars[normalizedRef]; ok {
|
|
||||||
// circular $ref has been already detected in another explored cycle
|
|
||||||
foundCycle = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
foundCycle = swag.ContainsStrings(parentRefs, normalizedRef) // normalized windows url's are lower cased
|
|
||||||
if foundCycle {
|
|
||||||
r.context.circulars[normalizedRef] = true
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve resolves a reference against basePath and stores the result in target.
|
|
||||||
//
|
|
||||||
// Resolve is not in charge of following references: it only resolves ref by following its URL.
|
|
||||||
//
|
|
||||||
// If the schema the ref is referring to holds nested refs, Resolve doesn't resolve them.
|
|
||||||
//
|
|
||||||
// If basePath is an empty string, ref is resolved against the root schema stored in the schemaLoader struct
|
|
||||||
func (r *schemaLoader) Resolve(ref *Ref, target interface{}, basePath string) error {
|
|
||||||
return r.resolveRef(ref, target, basePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) deref(input interface{}, parentRefs []string, basePath string) error {
|
|
||||||
var ref *Ref
|
|
||||||
switch refable := input.(type) {
|
|
||||||
case *Schema:
|
|
||||||
ref = &refable.Ref
|
|
||||||
case *Parameter:
|
|
||||||
ref = &refable.Ref
|
|
||||||
case *Response:
|
|
||||||
ref = &refable.Ref
|
|
||||||
case *PathItem:
|
|
||||||
ref = &refable.Ref
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unsupported type: %T: %w", input, ErrDerefUnsupportedType)
|
|
||||||
}
|
|
||||||
|
|
||||||
curRef := ref.String()
|
|
||||||
if curRef == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
normalizedRef := normalizeRef(ref, basePath)
|
|
||||||
normalizedBasePath := normalizedRef.RemoteURI()
|
|
||||||
|
|
||||||
if r.isCircular(normalizedRef, basePath, parentRefs...) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.resolveRef(ref, input, basePath); r.shouldStopOnError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if ref.String() == "" || ref.String() == curRef {
|
|
||||||
// done with rereferencing
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
parentRefs = append(parentRefs, normalizedRef.String())
|
|
||||||
return r.deref(input, parentRefs, normalizedBasePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) shouldStopOnError(err error) bool {
|
|
||||||
if err != nil && !r.options.ContinueOnError {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *schemaLoader) setSchemaID(target interface{}, id, basePath string) (string, string) {
|
|
||||||
debugLog("schema has ID: %s", id)
|
|
||||||
|
|
||||||
// handling the case when id is a folder
|
|
||||||
// remember that basePath has to point to a file
|
|
||||||
var refPath string
|
|
||||||
if strings.HasSuffix(id, "/") {
|
|
||||||
// ensure this is detected as a file, not a folder
|
|
||||||
refPath = fmt.Sprintf("%s%s", id, "placeholder.json")
|
|
||||||
} else {
|
|
||||||
refPath = id
|
|
||||||
}
|
|
||||||
|
|
||||||
// updates the current base path
|
|
||||||
// * important: ID can be a relative path
|
|
||||||
// * registers target to be fetchable from the new base proposed by this id
|
|
||||||
newBasePath := normalizeURI(refPath, basePath)
|
|
||||||
|
|
||||||
// store found IDs for possible future reuse in $ref
|
|
||||||
r.cache.Set(newBasePath, target)
|
|
||||||
|
|
||||||
// the root document has an ID: all $ref relative to that ID may
|
|
||||||
// be rebased relative to the root document
|
|
||||||
if basePath == r.context.basePath {
|
|
||||||
debugLog("root document is a schema with ID: %s (normalized as:%s)", id, newBasePath)
|
|
||||||
r.context.rootID = newBasePath
|
|
||||||
}
|
|
||||||
|
|
||||||
return newBasePath, refPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultSchemaLoader(
|
|
||||||
root interface{},
|
|
||||||
expandOptions *ExpandOptions,
|
|
||||||
cache ResolutionCache,
|
|
||||||
context *resolverContext) *schemaLoader {
|
|
||||||
|
|
||||||
if expandOptions == nil {
|
|
||||||
expandOptions = &ExpandOptions{}
|
|
||||||
}
|
|
||||||
|
|
||||||
cache = cacheOrDefault(cache)
|
|
||||||
|
|
||||||
if expandOptions.RelativeBase == "" {
|
|
||||||
// if no relative base is provided, assume the root document
|
|
||||||
// contains all $ref, or at least, that the relative documents
|
|
||||||
// may be resolved from the current working directory.
|
|
||||||
expandOptions.RelativeBase = baseForRoot(root, cache)
|
|
||||||
}
|
|
||||||
debugLog("effective expander options: %#v", expandOptions)
|
|
||||||
|
|
||||||
if context == nil {
|
|
||||||
context = newResolverContext(expandOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &schemaLoader{
|
|
||||||
root: root,
|
|
||||||
options: expandOptions,
|
|
||||||
cache: cache,
|
|
||||||
context: context,
|
|
||||||
}
|
|
||||||
}
|
|
170
vendor/github.com/go-openapi/spec/security_scheme.go
generated
vendored
170
vendor/github.com/go-openapi/spec/security_scheme.go
generated
vendored
@ -1,170 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
basic = "basic"
|
|
||||||
apiKey = "apiKey"
|
|
||||||
oauth2 = "oauth2"
|
|
||||||
implicit = "implicit"
|
|
||||||
password = "password"
|
|
||||||
application = "application"
|
|
||||||
accessCode = "accessCode"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BasicAuth creates a basic auth security scheme
|
|
||||||
func BasicAuth() *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{Type: basic}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// APIKeyAuth creates an api key auth security scheme
|
|
||||||
func APIKeyAuth(fieldName, valueSource string) *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{Type: apiKey, Name: fieldName, In: valueSource}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth2Implicit creates an implicit flow oauth2 security scheme
|
|
||||||
func OAuth2Implicit(authorizationURL string) *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{
|
|
||||||
Type: oauth2,
|
|
||||||
Flow: implicit,
|
|
||||||
AuthorizationURL: authorizationURL,
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth2Password creates a password flow oauth2 security scheme
|
|
||||||
func OAuth2Password(tokenURL string) *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{
|
|
||||||
Type: oauth2,
|
|
||||||
Flow: password,
|
|
||||||
TokenURL: tokenURL,
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth2Application creates an application flow oauth2 security scheme
|
|
||||||
func OAuth2Application(tokenURL string) *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{
|
|
||||||
Type: oauth2,
|
|
||||||
Flow: application,
|
|
||||||
TokenURL: tokenURL,
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth2AccessToken creates an access token flow oauth2 security scheme
|
|
||||||
func OAuth2AccessToken(authorizationURL, tokenURL string) *SecurityScheme {
|
|
||||||
return &SecurityScheme{SecuritySchemeProps: SecuritySchemeProps{
|
|
||||||
Type: oauth2,
|
|
||||||
Flow: accessCode,
|
|
||||||
AuthorizationURL: authorizationURL,
|
|
||||||
TokenURL: tokenURL,
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecuritySchemeProps describes a swagger security scheme in the securityDefinitions section
|
|
||||||
type SecuritySchemeProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Name string `json:"name,omitempty"` // api key
|
|
||||||
In string `json:"in,omitempty"` // api key
|
|
||||||
Flow string `json:"flow,omitempty"` // oauth2
|
|
||||||
AuthorizationURL string `json:"authorizationUrl"` // oauth2
|
|
||||||
TokenURL string `json:"tokenUrl,omitempty"` // oauth2
|
|
||||||
Scopes map[string]string `json:"scopes,omitempty"` // oauth2
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddScope adds a scope to this security scheme
|
|
||||||
func (s *SecuritySchemeProps) AddScope(scope, description string) {
|
|
||||||
if s.Scopes == nil {
|
|
||||||
s.Scopes = make(map[string]string)
|
|
||||||
}
|
|
||||||
s.Scopes[scope] = description
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecurityScheme allows the definition of a security scheme that can be used by the operations.
|
|
||||||
// Supported schemes are basic authentication, an API key (either as a header or as a query parameter)
|
|
||||||
// and OAuth2's common flows (implicit, password, application and access code).
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#securitySchemeObject
|
|
||||||
type SecurityScheme struct {
|
|
||||||
VendorExtensible
|
|
||||||
SecuritySchemeProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (s SecurityScheme) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := s.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.SecuritySchemeProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (s SecurityScheme) MarshalJSON() ([]byte, error) {
|
|
||||||
var (
|
|
||||||
b1 []byte
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if s.Type == oauth2 && (s.Flow == "implicit" || s.Flow == "accessCode") {
|
|
||||||
// when oauth2 for implicit or accessCode flows, empty AuthorizationURL is added as empty string
|
|
||||||
b1, err = json.Marshal(s.SecuritySchemeProps)
|
|
||||||
} else {
|
|
||||||
// when not oauth2, empty AuthorizationURL should be omitted
|
|
||||||
b1, err = json.Marshal(struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Name string `json:"name,omitempty"` // api key
|
|
||||||
In string `json:"in,omitempty"` // api key
|
|
||||||
Flow string `json:"flow,omitempty"` // oauth2
|
|
||||||
AuthorizationURL string `json:"authorizationUrl,omitempty"` // oauth2
|
|
||||||
TokenURL string `json:"tokenUrl,omitempty"` // oauth2
|
|
||||||
Scopes map[string]string `json:"scopes,omitempty"` // oauth2
|
|
||||||
}{
|
|
||||||
Description: s.Description,
|
|
||||||
Type: s.Type,
|
|
||||||
Name: s.Name,
|
|
||||||
In: s.In,
|
|
||||||
Flow: s.Flow,
|
|
||||||
AuthorizationURL: s.AuthorizationURL,
|
|
||||||
TokenURL: s.TokenURL,
|
|
||||||
Scopes: s.Scopes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
b2, err := json.Marshal(s.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON marshal this from JSON
|
|
||||||
func (s *SecurityScheme) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &s.SecuritySchemeProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &s.VendorExtensible)
|
|
||||||
}
|
|
78
vendor/github.com/go-openapi/spec/spec.go
generated
vendored
78
vendor/github.com/go-openapi/spec/spec.go
generated
vendored
@ -1,78 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:generate curl -L --progress -o ./schemas/v2/schema.json http://swagger.io/v2/schema.json
|
|
||||||
//go:generate curl -L --progress -o ./schemas/jsonschema-draft-04.json http://json-schema.org/draft-04/schema
|
|
||||||
//go:generate go-bindata -pkg=spec -prefix=./schemas -ignore=.*\.md ./schemas/...
|
|
||||||
//go:generate perl -pi -e s,Json,JSON,g bindata.go
|
|
||||||
|
|
||||||
const (
|
|
||||||
// SwaggerSchemaURL the url for the swagger 2.0 schema to validate specs
|
|
||||||
SwaggerSchemaURL = "http://swagger.io/v2/schema.json#"
|
|
||||||
// JSONSchemaURL the url for the json schema schema
|
|
||||||
JSONSchemaURL = "http://json-schema.org/draft-04/schema#"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MustLoadJSONSchemaDraft04 panics when Swagger20Schema returns an error
|
|
||||||
func MustLoadJSONSchemaDraft04() *Schema {
|
|
||||||
d, e := JSONSchemaDraft04()
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONSchemaDraft04 loads the json schema document for json shema draft04
|
|
||||||
func JSONSchemaDraft04() (*Schema, error) {
|
|
||||||
b, err := Asset("jsonschema-draft-04.json")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
schema := new(Schema)
|
|
||||||
if err := json.Unmarshal(b, schema); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return schema, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustLoadSwagger20Schema panics when Swagger20Schema returns an error
|
|
||||||
func MustLoadSwagger20Schema() *Schema {
|
|
||||||
d, e := Swagger20Schema()
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swagger20Schema loads the swagger 2.0 schema from the embedded assets
|
|
||||||
func Swagger20Schema() (*Schema, error) {
|
|
||||||
|
|
||||||
b, err := Asset("v2/schema.json")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
schema := new(Schema)
|
|
||||||
if err := json.Unmarshal(b, schema); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return schema, nil
|
|
||||||
}
|
|
448
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
448
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
@ -1,448 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/gob"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Swagger this is the root document object for the API specification.
|
|
||||||
// It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier)
|
|
||||||
// together into one document.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#swagger-object-
|
|
||||||
type Swagger struct {
|
|
||||||
VendorExtensible
|
|
||||||
SwaggerProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup look up a value by the json property name
|
|
||||||
func (s Swagger) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := s.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.SwaggerProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals this swagger structure to json
|
|
||||||
func (s Swagger) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(s.SwaggerProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(s.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals a swagger spec from json
|
|
||||||
func (s *Swagger) UnmarshalJSON(data []byte) error {
|
|
||||||
var sw Swagger
|
|
||||||
if err := json.Unmarshal(data, &sw.SwaggerProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &sw.VendorExtensible); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*s = sw
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobEncode provides a safe gob encoder for Swagger, including extensions
|
|
||||||
func (s Swagger) GobEncode() ([]byte, error) {
|
|
||||||
var b bytes.Buffer
|
|
||||||
raw := struct {
|
|
||||||
Props SwaggerProps
|
|
||||||
Ext VendorExtensible
|
|
||||||
}{
|
|
||||||
Props: s.SwaggerProps,
|
|
||||||
Ext: s.VendorExtensible,
|
|
||||||
}
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobDecode provides a safe gob decoder for Swagger, including extensions
|
|
||||||
func (s *Swagger) GobDecode(b []byte) error {
|
|
||||||
var raw struct {
|
|
||||||
Props SwaggerProps
|
|
||||||
Ext VendorExtensible
|
|
||||||
}
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
err := gob.NewDecoder(buf).Decode(&raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s.SwaggerProps = raw.Props
|
|
||||||
s.VendorExtensible = raw.Ext
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SwaggerProps captures the top-level properties of an Api specification
|
|
||||||
//
|
|
||||||
// NOTE: validation rules
|
|
||||||
// - the scheme, when present must be from [http, https, ws, wss]
|
|
||||||
// - BasePath must start with a leading "/"
|
|
||||||
// - Paths is required
|
|
||||||
type SwaggerProps struct {
|
|
||||||
ID string `json:"id,omitempty"`
|
|
||||||
Consumes []string `json:"consumes,omitempty"`
|
|
||||||
Produces []string `json:"produces,omitempty"`
|
|
||||||
Schemes []string `json:"schemes,omitempty"`
|
|
||||||
Swagger string `json:"swagger,omitempty"`
|
|
||||||
Info *Info `json:"info,omitempty"`
|
|
||||||
Host string `json:"host,omitempty"`
|
|
||||||
BasePath string `json:"basePath,omitempty"`
|
|
||||||
Paths *Paths `json:"paths"`
|
|
||||||
Definitions Definitions `json:"definitions,omitempty"`
|
|
||||||
Parameters map[string]Parameter `json:"parameters,omitempty"`
|
|
||||||
Responses map[string]Response `json:"responses,omitempty"`
|
|
||||||
SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"`
|
|
||||||
Security []map[string][]string `json:"security,omitempty"`
|
|
||||||
Tags []Tag `json:"tags,omitempty"`
|
|
||||||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type swaggerPropsAlias SwaggerProps
|
|
||||||
|
|
||||||
type gobSwaggerPropsAlias struct {
|
|
||||||
Security []map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}
|
|
||||||
Alias *swaggerPropsAlias
|
|
||||||
SecurityIsEmpty bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobEncode provides a safe gob encoder for SwaggerProps, including empty security requirements
|
|
||||||
func (o SwaggerProps) GobEncode() ([]byte, error) {
|
|
||||||
raw := gobSwaggerPropsAlias{
|
|
||||||
Alias: (*swaggerPropsAlias)(&o),
|
|
||||||
}
|
|
||||||
|
|
||||||
var b bytes.Buffer
|
|
||||||
if o.Security == nil {
|
|
||||||
// nil security requirement
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(o.Security) == 0 {
|
|
||||||
// empty, but non-nil security requirement
|
|
||||||
raw.SecurityIsEmpty = true
|
|
||||||
raw.Alias.Security = nil
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
raw.Security = make([]map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}, 0, len(o.Security))
|
|
||||||
for _, req := range o.Security {
|
|
||||||
v := make(map[string]struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}, len(req))
|
|
||||||
for k, val := range req {
|
|
||||||
v[k] = struct {
|
|
||||||
List []string
|
|
||||||
Pad bool
|
|
||||||
}{
|
|
||||||
List: val,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raw.Security = append(raw.Security, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := gob.NewEncoder(&b).Encode(raw)
|
|
||||||
return b.Bytes(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GobDecode provides a safe gob decoder for SwaggerProps, including empty security requirements
|
|
||||||
func (o *SwaggerProps) GobDecode(b []byte) error {
|
|
||||||
var raw gobSwaggerPropsAlias
|
|
||||||
|
|
||||||
buf := bytes.NewBuffer(b)
|
|
||||||
err := gob.NewDecoder(buf).Decode(&raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if raw.Alias == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case raw.SecurityIsEmpty:
|
|
||||||
// empty, but non-nil security requirement
|
|
||||||
raw.Alias.Security = []map[string][]string{}
|
|
||||||
case len(raw.Alias.Security) == 0:
|
|
||||||
// nil security requirement
|
|
||||||
raw.Alias.Security = nil
|
|
||||||
default:
|
|
||||||
raw.Alias.Security = make([]map[string][]string, 0, len(raw.Security))
|
|
||||||
for _, req := range raw.Security {
|
|
||||||
v := make(map[string][]string, len(req))
|
|
||||||
for k, val := range req {
|
|
||||||
v[k] = make([]string, 0, len(val.List))
|
|
||||||
v[k] = append(v[k], val.List...)
|
|
||||||
}
|
|
||||||
raw.Alias.Security = append(raw.Alias.Security, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*o = *(*SwaggerProps)(raw.Alias)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dependencies represent a dependencies property
|
|
||||||
type Dependencies map[string]SchemaOrStringArray
|
|
||||||
|
|
||||||
// SchemaOrBool represents a schema or boolean value, is biased towards true for the boolean property
|
|
||||||
type SchemaOrBool struct {
|
|
||||||
Allows bool
|
|
||||||
Schema *Schema
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (s SchemaOrBool) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if token == "allows" {
|
|
||||||
return s.Allows, nil
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.Schema, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var jsTrue = []byte("true")
|
|
||||||
var jsFalse = []byte("false")
|
|
||||||
|
|
||||||
// MarshalJSON convert this object to JSON
|
|
||||||
func (s SchemaOrBool) MarshalJSON() ([]byte, error) {
|
|
||||||
if s.Schema != nil {
|
|
||||||
return json.Marshal(s.Schema)
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.Schema == nil && !s.Allows {
|
|
||||||
return jsFalse, nil
|
|
||||||
}
|
|
||||||
return jsTrue, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON converts this bool or schema object from a JSON structure
|
|
||||||
func (s *SchemaOrBool) UnmarshalJSON(data []byte) error {
|
|
||||||
var nw SchemaOrBool
|
|
||||||
if len(data) >= 4 {
|
|
||||||
if data[0] == '{' {
|
|
||||||
var sch Schema
|
|
||||||
if err := json.Unmarshal(data, &sch); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nw.Schema = &sch
|
|
||||||
}
|
|
||||||
nw.Allows = !(data[0] == 'f' && data[1] == 'a' && data[2] == 'l' && data[3] == 's' && data[4] == 'e')
|
|
||||||
}
|
|
||||||
*s = nw
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchemaOrStringArray represents a schema or a string array
|
|
||||||
type SchemaOrStringArray struct {
|
|
||||||
Schema *Schema
|
|
||||||
Property []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (s SchemaOrStringArray) JSONLookup(token string) (interface{}, error) {
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.Schema, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this schema object or array into JSON structure
|
|
||||||
func (s SchemaOrStringArray) MarshalJSON() ([]byte, error) {
|
|
||||||
if len(s.Property) > 0 {
|
|
||||||
return json.Marshal(s.Property)
|
|
||||||
}
|
|
||||||
if s.Schema != nil {
|
|
||||||
return json.Marshal(s.Schema)
|
|
||||||
}
|
|
||||||
return []byte("null"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON converts this schema object or array from a JSON structure
|
|
||||||
func (s *SchemaOrStringArray) UnmarshalJSON(data []byte) error {
|
|
||||||
var first byte
|
|
||||||
if len(data) > 1 {
|
|
||||||
first = data[0]
|
|
||||||
}
|
|
||||||
var nw SchemaOrStringArray
|
|
||||||
if first == '{' {
|
|
||||||
var sch Schema
|
|
||||||
if err := json.Unmarshal(data, &sch); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nw.Schema = &sch
|
|
||||||
}
|
|
||||||
if first == '[' {
|
|
||||||
if err := json.Unmarshal(data, &nw.Property); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*s = nw
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Definitions contains the models explicitly defined in this spec
|
|
||||||
// An object to hold data types that can be consumed and produced by operations.
|
|
||||||
// These data types can be primitives, arrays or models.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#definitionsObject
|
|
||||||
type Definitions map[string]Schema
|
|
||||||
|
|
||||||
// SecurityDefinitions a declaration of the security schemes available to be used in the specification.
|
|
||||||
// This does not enforce the security schemes on the operations and only serves to provide
|
|
||||||
// the relevant details for each scheme.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#securityDefinitionsObject
|
|
||||||
type SecurityDefinitions map[string]*SecurityScheme
|
|
||||||
|
|
||||||
// StringOrArray represents a value that can either be a string
|
|
||||||
// or an array of strings. Mainly here for serialization purposes
|
|
||||||
type StringOrArray []string
|
|
||||||
|
|
||||||
// Contains returns true when the value is contained in the slice
|
|
||||||
func (s StringOrArray) Contains(value string) bool {
|
|
||||||
for _, str := range s {
|
|
||||||
if str == value {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (s SchemaOrArray) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if _, err := strconv.Atoi(token); err == nil {
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.Schemas, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
r, _, err := jsonpointer.GetForToken(s.Schema, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals this string or array object from a JSON array or JSON string
|
|
||||||
func (s *StringOrArray) UnmarshalJSON(data []byte) error {
|
|
||||||
var first byte
|
|
||||||
if len(data) > 1 {
|
|
||||||
first = data[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if first == '[' {
|
|
||||||
var parsed []string
|
|
||||||
if err := json.Unmarshal(data, &parsed); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*s = StringOrArray(parsed)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var single interface{}
|
|
||||||
if err := json.Unmarshal(data, &single); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if single == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
switch v := single.(type) {
|
|
||||||
case string:
|
|
||||||
*s = StringOrArray([]string{v})
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("only string or array is allowed, not %T", single)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this string or array to a JSON array or JSON string
|
|
||||||
func (s StringOrArray) MarshalJSON() ([]byte, error) {
|
|
||||||
if len(s) == 1 {
|
|
||||||
return json.Marshal([]string(s)[0])
|
|
||||||
}
|
|
||||||
return json.Marshal([]string(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SchemaOrArray represents a value that can either be a Schema
|
|
||||||
// or an array of Schema. Mainly here for serialization purposes
|
|
||||||
type SchemaOrArray struct {
|
|
||||||
Schema *Schema
|
|
||||||
Schemas []Schema
|
|
||||||
}
|
|
||||||
|
|
||||||
// Len returns the number of schemas in this property
|
|
||||||
func (s SchemaOrArray) Len() int {
|
|
||||||
if s.Schema != nil {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return len(s.Schemas)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContainsType returns true when one of the schemas is of the specified type
|
|
||||||
func (s *SchemaOrArray) ContainsType(name string) bool {
|
|
||||||
if s.Schema != nil {
|
|
||||||
return s.Schema.Type != nil && s.Schema.Type.Contains(name)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON converts this schema object or array into JSON structure
|
|
||||||
func (s SchemaOrArray) MarshalJSON() ([]byte, error) {
|
|
||||||
if len(s.Schemas) > 0 {
|
|
||||||
return json.Marshal(s.Schemas)
|
|
||||||
}
|
|
||||||
return json.Marshal(s.Schema)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON converts this schema object or array from a JSON structure
|
|
||||||
func (s *SchemaOrArray) UnmarshalJSON(data []byte) error {
|
|
||||||
var nw SchemaOrArray
|
|
||||||
var first byte
|
|
||||||
if len(data) > 1 {
|
|
||||||
first = data[0]
|
|
||||||
}
|
|
||||||
if first == '{' {
|
|
||||||
var sch Schema
|
|
||||||
if err := json.Unmarshal(data, &sch); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nw.Schema = &sch
|
|
||||||
}
|
|
||||||
if first == '[' {
|
|
||||||
if err := json.Unmarshal(data, &nw.Schemas); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*s = nw
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim:set ft=go noet sts=2 sw=2 ts=2:
|
|
75
vendor/github.com/go-openapi/spec/tag.go
generated
vendored
75
vendor/github.com/go-openapi/spec/tag.go
generated
vendored
@ -1,75 +0,0 @@
|
|||||||
// Copyright 2015 go-swagger maintainers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package spec
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/go-openapi/jsonpointer"
|
|
||||||
"github.com/go-openapi/swag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TagProps describe a tag entry in the top level tags section of a swagger spec
|
|
||||||
type TagProps struct {
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTag creates a new tag
|
|
||||||
func NewTag(name, description string, externalDocs *ExternalDocumentation) Tag {
|
|
||||||
return Tag{TagProps: TagProps{Description: description, Name: name, ExternalDocs: externalDocs}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag allows adding meta data to a single tag that is used by the
|
|
||||||
// [Operation Object](http://goo.gl/8us55a#operationObject).
|
|
||||||
// It is not mandatory to have a Tag Object per tag used there.
|
|
||||||
//
|
|
||||||
// For more information: http://goo.gl/8us55a#tagObject
|
|
||||||
type Tag struct {
|
|
||||||
VendorExtensible
|
|
||||||
TagProps
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONLookup implements an interface to customize json pointer lookup
|
|
||||||
func (t Tag) JSONLookup(token string) (interface{}, error) {
|
|
||||||
if ex, ok := t.Extensions[token]; ok {
|
|
||||||
return &ex, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r, _, err := jsonpointer.GetForToken(t.TagProps, token)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshal this to JSON
|
|
||||||
func (t Tag) MarshalJSON() ([]byte, error) {
|
|
||||||
b1, err := json.Marshal(t.TagProps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b2, err := json.Marshal(t.VendorExtensible)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return swag.ConcatJSON(b1, b2), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON marshal this from JSON
|
|
||||||
func (t *Tag) UnmarshalJSON(data []byte) error {
|
|
||||||
if err := json.Unmarshal(data, &t.TagProps); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return json.Unmarshal(data, &t.VendorExtensible)
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user