Fnlb was moved to its own repo: fnproject/lb (#702)

* Fnlb was moved to its own repo: fnproject/lb

* Clean up fnlb leftovers

* Newer deps
This commit is contained in:
Denis Makogon
2018-01-23 00:17:29 +02:00
committed by Reed Allman
parent 4ffa3d5005
commit d3be603e54
8310 changed files with 457462 additions and 1749312 deletions

View File

@@ -0,0 +1,42 @@
swagger: '2.0'
info:
title: Something
contact:
name: Somebody
url: https://url.com
email: email@url.com
description: Something
version: v1
host: security.sonusnet.com
schemes:
- https
- http
basePath: /api
produces:
- application/json
- plain/text
paths:
/whatnot:
get:
description: Get something
responses:
200:
description: The something
schema:
$ref: '#/definitions/Something'
500:
description: Oops
definitions:
Something:
description: A collection of service events
type: object
properties:
page:
$ref: '../../../../shared/definitions/page.yaml#/definitions/Page'
something:
#type: array
#description: An array of something
#items:
$ref: '../../../../shared/something.yaml#/definitions/Something'

View File

@@ -0,0 +1,18 @@
definitions:
Page:
description: A description of a paged result
type: object
properties:
page:
type: integer
description: the page that was requested
pages:
type: integer
description: the total number of pages available
total_items:
type: integer
description: the total number of items available
format: int64
page_items:
type: integer
description: the number of items per page requested

View File

@@ -0,0 +1,44 @@
swagger: '2.0'
info:
title: Something definitions
contact:
name: Somebody
url: https://url.com
email: email@url.com
description: Something
version: v1
host: security.sonusnet.com
schemes:
- https
- http
basePath: /api/something/definitions
produces:
- application/json
- plain/text
paths:
/shared:
get:
operationId: Get
tags:
- Shared
responses:
200:
description: OK
schema:
properties:
name:
type: string
definitions:
Something:
description: Something
type: object
properties:
p1:
type: string
description: A string
p2:
type: integer
description: An integer

View File

@@ -0,0 +1,38 @@
swagger: "2.0"
info:
version: 0.1.1
title: test 1
description: recursively following JSON references
contact:
name: Fred
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/getAll:
get:
operationId: getAll
parameters:
- name: a
in: body
description: max number of results
required: false
schema:
$ref: '#/definitions/a'
responses:
'200':
description: Success
schema:
$ref: '#/definitions/b'
definitions:
a:
type: string
b:
$ref: './test3-ter-model-schema.json#/definitions/b'

View File

@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "./test3-model-schema.json",
"title": "test3-model-schema",
"description": "Test schema responses",
"definitions": {
"b": {
"type": "array",
"items": {
"type": "string"
}
}
}
}

View File

@@ -20,8 +20,6 @@ import (
"fmt"
"net/url"
"path/filepath"
"github.com/go-openapi/analysis"
"github.com/go-openapi/spec"
"github.com/go-openapi/swag"
@@ -92,6 +90,22 @@ type Document struct {
raw json.RawMessage
}
// Embedded returns a Document based on embedded specs. No analysis is required
func Embedded(orig, flat json.RawMessage) (*Document, error) {
var origSpec, flatSpec spec.Swagger
if err := json.Unmarshal(orig, &origSpec); err != nil {
return nil, err
}
if err := json.Unmarshal(flat, &flatSpec); err != nil {
return nil, err
}
return &Document{
raw: orig,
origSpec: &origSpec,
spec: &flatSpec,
}, nil
}
// Spec loads a new spec document
func Spec(path string) (*Document, error) {
specURL, err := url.Parse(path)
@@ -186,10 +200,10 @@ func (d *Document) Expanded(options ...*spec.ExpandOptions) (*Document, error) {
var expandOptions *spec.ExpandOptions
if len(options) > 0 {
expandOptions = options[1]
expandOptions = options[0]
} else {
expandOptions = &spec.ExpandOptions{
RelativeBase: filepath.Dir(d.specFilePath),
RelativeBase: d.specFilePath,
}
}
@@ -198,11 +212,12 @@ func (d *Document) Expanded(options ...*spec.ExpandOptions) (*Document, error) {
}
dd := &Document{
Analyzer: analysis.New(swspec),
spec: swspec,
schema: spec.MustLoadSwagger20Schema(),
raw: d.raw,
origSpec: d.origSpec,
Analyzer: analysis.New(swspec),
spec: swspec,
specFilePath: d.specFilePath,
schema: spec.MustLoadSwagger20Schema(),
raw: d.raw,
origSpec: d.origSpec,
}
return dd, nil
}

View File

@@ -32,6 +32,31 @@ func TestLoadsYAMLContent(t *testing.T) {
}
}
// for issue 11
func TestRegressionExpand(t *testing.T) {
swaggerFile := "fixtures/yaml/swagger/1/2/3/4/swagger.yaml"
document, err := Spec(swaggerFile)
assert.NoError(t, err)
assert.NotNil(t, document)
d, err := document.Expanded()
assert.NoError(t, err)
assert.NotNil(t, d)
b, _ := d.Spec().MarshalJSON()
assert.JSONEq(t, expectedExpanded, string(b))
}
func TestCascadingRefExpand(t *testing.T) {
swaggerFile := "fixtures/yaml/swagger/spec.yml"
document, err := Spec(swaggerFile)
assert.NoError(t, err)
assert.NotNil(t, document)
d, err := document.Expanded()
assert.NoError(t, err)
assert.NotNil(t, d)
b, _ := d.Spec().MarshalJSON()
assert.JSONEq(t, cascadeRefExpanded, string(b))
}
func TestFailsInvalidJSON(t *testing.T) {
_, err := Analyzed(json.RawMessage([]byte("{]")), "")
@@ -499,3 +524,194 @@ const PetStore20 = `{
}
}
`
const expectedExpanded = `
{
"produces":[
"application/json",
"plain/text"
],
"schemes":[
"https",
"http"
],
"swagger":"2.0",
"info":{
"description":"Something",
"title":"Something",
"contact":{
"name":"Somebody",
"url":"https://url.com",
"email":"email@url.com"
},
"version":"v1"
},
"host":"security.sonusnet.com",
"basePath":"/api",
"paths":{
"/whatnot":{
"get":{
"description":"Get something",
"responses":{
"200":{
"description":"The something",
"schema":{
"description":"A collection of service events",
"type":"object",
"properties":{
"page":{
"description":"A description of a paged result",
"type":"object",
"properties":{
"page":{
"description":"the page that was requested",
"type":"integer"
},
"page_items":{
"description":"the number of items per page requested",
"type":"integer"
},
"pages":{
"description":"the total number of pages available",
"type":"integer"
},
"total_items":{
"description":"the total number of items available",
"type":"integer",
"format":"int64"
}
}
},
"something":{
"description":"Something",
"type":"object",
"properties":{
"p1":{
"description":"A string",
"type":"string"
},
"p2":{
"description":"An integer",
"type":"integer"
}
}
}
}
}
},
"500":{
"description":"Oops"
}
}
}
}
},
"definitions":{
"Something":{
"description":"A collection of service events",
"type":"object",
"properties":{
"page":{
"description":"A description of a paged result",
"type":"object",
"properties":{
"page":{
"description":"the page that was requested",
"type":"integer"
},
"page_items":{
"description":"the number of items per page requested",
"type":"integer"
},
"pages":{
"description":"the total number of pages available",
"type":"integer"
},
"total_items":{
"description":"the total number of items available",
"type":"integer",
"format":"int64"
}
}
},
"something":{
"description":"Something",
"type":"object",
"properties":{
"p1":{
"description":"A string",
"type":"string"
},
"p2":{
"description":"An integer",
"type":"integer"
}
}
}
}
}
}
}
`
const cascadeRefExpanded = `
{
"swagger": "2.0",
"consumes":[
"application/json"
],
"produces":[
"application/json"
],
"schemes":[
"http"
],
"info":{
"description":"recursively following JSON references",
"title":"test 1",
"contact":{
"name":"Fred"
},
"version":"0.1.1"
},
"paths":{
"/getAll":{
"get":{
"operationId":"getAll",
"parameters":[
{
"description":"max number of results",
"name":"a",
"in":"body",
"schema":{
"type":"string"
}
}
],
"responses":{
"200":{
"description":"Success",
"schema":{
"type":"array",
"items":{
"type":"string"
}
}
}
}
}
}
},
"definitions":{
"a":{
"type":"string"
},
"b":{
"type":"array",
"items":{
"type":"string"
}
}
}
}
`