Updated vednor files

This commit is contained in:
Serguei Bezverkhi
2018-02-15 08:50:31 -05:00
parent 18a4ce4439
commit 1f1e8cea37
3299 changed files with 834 additions and 1051200 deletions

View File

@ -1,5 +0,0 @@
# OpenAPI Builder Sample
This directory contains a simple sample application that builds
and exports an OpenAPI 2.0 description of a sample API.

View File

@ -1,82 +0,0 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// 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 main
import (
"fmt"
"io/ioutil"
"os"
"path"
"github.com/golang/protobuf/proto"
)
func usage() string {
return fmt.Sprintf(`
Usage: %s [OPTIONS]
Options:
--v2
Generate an OpenAPI v2 description.
--v3
Generate an OpenAPI v3 description.
`, path.Base(os.Args[0]))
}
func main() {
openAPIv2 := false
openAPIv3 := false
for i, arg := range os.Args {
if i == 0 {
continue // skip the tool name
}
if arg == "--v2" {
openAPIv2 = true
} else if arg == "--v3" {
openAPIv3 = true
} else {
fmt.Printf("Unknown option: %s.\n%s\n", arg, usage())
os.Exit(-1)
}
}
if !openAPIv2 && !openAPIv3 {
openAPIv2 = true
}
if openAPIv2 {
document := buildDocumentV2()
bytes, err := proto.Marshal(document)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("petstore-v2.pb", bytes, 0644)
if err != nil {
panic(err)
}
}
if openAPIv3 {
document := buildDocumentV3()
bytes, err := proto.Marshal(document)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("petstore-v3.pb", bytes, 0644)
if err != nil {
panic(err)
}
}
}

View File

@ -1,260 +0,0 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// 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 main
import (
v2 "github.com/googleapis/gnostic/OpenAPIv2"
)
func buildDocumentV2() *v2.Document {
d := &v2.Document{}
d.Swagger = "2.0"
d.Info = &v2.Info{
Title: "Swagger Petstore",
Version: "1.0.0",
License: &v2.License{Name: "MIT"},
}
d.Host = "petstore.swagger.io"
d.BasePath = "/v1"
d.Schemes = []string{"http"}
d.Consumes = []string{"application/json"}
d.Produces = []string{"application/json"}
d.Paths = &v2.Paths{}
d.Paths.Path = append(d.Paths.Path,
&v2.NamedPathItem{
Name: "/pets",
Value: &v2.PathItem{
Get: &v2.Operation{
Summary: "List all pets",
OperationId: "listPets",
Tags: []string{"pets"},
Parameters: []*v2.ParametersItem{
&v2.ParametersItem{
Oneof: &v2.ParametersItem_Parameter{
Parameter: &v2.Parameter{
Oneof: &v2.Parameter_NonBodyParameter{
NonBodyParameter: &v2.NonBodyParameter{
Oneof: &v2.NonBodyParameter_QueryParameterSubSchema{
QueryParameterSubSchema: &v2.QueryParameterSubSchema{
Name: "limit",
In: "query",
Description: "How many items to return at one time (max 100)",
Required: false,
Type: "integer",
Format: "int32",
},
},
},
},
},
},
},
},
Responses: &v2.Responses{
ResponseCode: []*v2.NamedResponseValue{
&v2.NamedResponseValue{
Name: "200",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "An paged array of pets", // [sic] match other examples
Schema: &v2.SchemaItem{
Oneof: &v2.SchemaItem_Schema{
Schema: &v2.Schema{
XRef: "#/definitions/Pets",
},
},
},
Headers: &v2.Headers{
AdditionalProperties: []*v2.NamedHeader{
&v2.NamedHeader{
Name: "x-next",
Value: &v2.Header{
Type: "string",
Description: "A link to the next page of responses",
},
},
},
},
},
},
},
},
&v2.NamedResponseValue{
Name: "default",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "unexpected error",
Schema: &v2.SchemaItem{
Oneof: &v2.SchemaItem_Schema{
Schema: &v2.Schema{
XRef: "#/definitions/Error",
},
},
},
},
},
},
},
},
},
},
Post: &v2.Operation{
Summary: "Create a pet",
OperationId: "createPets",
Tags: []string{"pets"},
Parameters: []*v2.ParametersItem{},
Responses: &v2.Responses{
ResponseCode: []*v2.NamedResponseValue{
&v2.NamedResponseValue{
Name: "201",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "Null response",
},
},
},
},
&v2.NamedResponseValue{
Name: "default",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "unexpected error",
Schema: &v2.SchemaItem{
Oneof: &v2.SchemaItem_Schema{
Schema: &v2.Schema{
XRef: "#/definitions/Error",
},
},
},
},
},
},
},
},
},
},
}})
d.Paths.Path = append(d.Paths.Path,
&v2.NamedPathItem{
Name: "/pets/{petId}",
Value: &v2.PathItem{
Get: &v2.Operation{
Summary: "Info for a specific pet",
OperationId: "showPetById",
Tags: []string{"pets"},
Parameters: []*v2.ParametersItem{
&v2.ParametersItem{
Oneof: &v2.ParametersItem_Parameter{
Parameter: &v2.Parameter{
Oneof: &v2.Parameter_NonBodyParameter{
NonBodyParameter: &v2.NonBodyParameter{
Oneof: &v2.NonBodyParameter_PathParameterSubSchema{
PathParameterSubSchema: &v2.PathParameterSubSchema{
Name: "petId",
In: "path",
Description: "The id of the pet to retrieve",
Required: true,
Type: "string",
},
},
},
},
},
},
},
},
Responses: &v2.Responses{
ResponseCode: []*v2.NamedResponseValue{
&v2.NamedResponseValue{
Name: "200",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "Expected response to a valid request",
Schema: &v2.SchemaItem{
Oneof: &v2.SchemaItem_Schema{
Schema: &v2.Schema{
XRef: "#/definitions/Pets",
},
},
},
},
},
},
},
&v2.NamedResponseValue{
Name: "default",
Value: &v2.ResponseValue{
Oneof: &v2.ResponseValue_Response{
Response: &v2.Response{
Description: "unexpected error",
Schema: &v2.SchemaItem{
Oneof: &v2.SchemaItem_Schema{
Schema: &v2.Schema{
XRef: "#/definitions/Error",
},
},
},
},
},
},
},
},
},
},
}})
d.Definitions = &v2.Definitions{}
d.Definitions.AdditionalProperties = append(d.Definitions.AdditionalProperties,
&v2.NamedSchema{
Name: "Pet",
Value: &v2.Schema{
Required: []string{"id", "name"},
Properties: &v2.Properties{
AdditionalProperties: []*v2.NamedSchema{
&v2.NamedSchema{Name: "id", Value: &v2.Schema{
Type: &v2.TypeItem{[]string{"integer"}},
Format: "int64"}},
&v2.NamedSchema{Name: "name", Value: &v2.Schema{Type: &v2.TypeItem{[]string{"string"}}}},
&v2.NamedSchema{Name: "tag", Value: &v2.Schema{Type: &v2.TypeItem{[]string{"string"}}}},
},
},
}})
d.Definitions.AdditionalProperties = append(d.Definitions.AdditionalProperties,
&v2.NamedSchema{
Name: "Pets",
Value: &v2.Schema{
Type: &v2.TypeItem{[]string{"array"}},
Items: &v2.ItemsItem{[]*v2.Schema{&v2.Schema{XRef: "#/definitions/Pet"}}},
}})
d.Definitions.AdditionalProperties = append(d.Definitions.AdditionalProperties,
&v2.NamedSchema{
Name: "Error",
Value: &v2.Schema{
Required: []string{"code", "message"},
Properties: &v2.Properties{
AdditionalProperties: []*v2.NamedSchema{
&v2.NamedSchema{Name: "code", Value: &v2.Schema{
Type: &v2.TypeItem{[]string{"integer"}},
Format: "int32"}},
&v2.NamedSchema{Name: "message", Value: &v2.Schema{Type: &v2.TypeItem{[]string{"string"}}}},
},
},
}})
return d
}

View File

@ -1,369 +0,0 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// 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 main
import (
v3 "github.com/googleapis/gnostic/OpenAPIv3"
)
func buildDocumentV3() *v3.Document {
d := &v3.Document{}
d.Openapi = "3.0"
d.Info = &v3.Info{
Title: "OpenAPI Petstore",
Version: "1.0.0",
License: &v3.License{Name: "MIT"},
}
d.Servers = append(d.Servers, &v3.Server{
Url: "https://petstore.openapis.org/v1",
Description: "Development server",
})
d.Paths = &v3.Paths{}
d.Paths.Path = append(d.Paths.Path,
&v3.NamedPathItem{
Name: "/pets",
Value: &v3.PathItem{
Get: &v3.Operation{
Summary: "List all pets",
OperationId: "listPets",
Tags: []string{"pets"},
Parameters: []*v3.ParameterOrReference{
&v3.ParameterOrReference{
Oneof: &v3.ParameterOrReference_Parameter{
Parameter: &v3.Parameter{
Name: "limit",
In: "query",
Description: "How many items to return at one time (max 100)",
Required: false,
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "integer",
Format: "int32",
},
},
},
},
},
},
},
Responses: &v3.Responses{
Default: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "unexpected error",
Content: &v3.MediaTypes{
AdditionalProperties: []*v3.NamedMediaType{
&v3.NamedMediaType{
Name: "application/json",
Value: &v3.MediaType{
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
},
},
ResponseOrReference: []*v3.NamedResponseOrReference{
&v3.NamedResponseOrReference{
Name: "200",
Value: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "An paged array of pets", // [sic] match other examples
Content: &v3.MediaTypes{
AdditionalProperties: []*v3.NamedMediaType{
&v3.NamedMediaType{
Name: "application/json",
Value: &v3.MediaType{
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Pets",
},
},
},
},
},
},
},
Headers: &v3.HeadersOrReferences{
AdditionalProperties: []*v3.NamedHeaderOrReference{
&v3.NamedHeaderOrReference{
Name: "x-next",
Value: &v3.HeaderOrReference{
Oneof: &v3.HeaderOrReference_Header{
Header: &v3.Header{
Description: "A link to the next page of responses",
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "string",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
Post: &v3.Operation{
Summary: "Create a pet",
OperationId: "createPets",
Tags: []string{"pets"},
Responses: &v3.Responses{
Default: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "unexpected error",
Content: &v3.MediaTypes{
AdditionalProperties: []*v3.NamedMediaType{
&v3.NamedMediaType{
Name: "application/json",
Value: &v3.MediaType{
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
},
},
ResponseOrReference: []*v3.NamedResponseOrReference{
&v3.NamedResponseOrReference{
Name: "201",
Value: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "Null response",
},
},
},
},
},
},
},
}},
&v3.NamedPathItem{
Name: "/pets/{petId}",
Value: &v3.PathItem{
Get: &v3.Operation{
Summary: "Info for a specific pet",
OperationId: "showPetById",
Tags: []string{"pets"},
Parameters: []*v3.ParameterOrReference{
&v3.ParameterOrReference{
Oneof: &v3.ParameterOrReference_Parameter{
Parameter: &v3.Parameter{
Name: "petId",
In: "path",
Description: "The id of the pet to retrieve",
Required: true,
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "string",
},
},
},
},
},
},
},
Responses: &v3.Responses{
Default: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "unexpected error",
Content: &v3.MediaTypes{
AdditionalProperties: []*v3.NamedMediaType{
&v3.NamedMediaType{
Name: "application/json",
Value: &v3.MediaType{
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Error",
},
},
},
},
},
},
},
},
},
},
ResponseOrReference: []*v3.NamedResponseOrReference{
&v3.NamedResponseOrReference{
Name: "200",
Value: &v3.ResponseOrReference{
Oneof: &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: "Expected response to a valid request",
Content: &v3.MediaTypes{
AdditionalProperties: []*v3.NamedMediaType{
&v3.NamedMediaType{
Name: "application/json",
Value: &v3.MediaType{
Schema: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Pets",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}})
d.Components = &v3.Components{
Schemas: &v3.SchemasOrReferences{
AdditionalProperties: []*v3.NamedSchemaOrReference{
&v3.NamedSchemaOrReference{
Name: "Pet",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Required: []string{"id", "name"},
Properties: &v3.Properties{
AdditionalProperties: []*v3.NamedSchemaOrReference{
&v3.NamedSchemaOrReference{
Name: "id",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "integer",
Format: "int64",
},
},
},
},
&v3.NamedSchemaOrReference{
Name: "name",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "string",
},
},
},
},
&v3.NamedSchemaOrReference{
Name: "tag",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "string",
},
},
},
},
},
},
},
},
},
},
&v3.NamedSchemaOrReference{
Name: "Pets",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "array",
Items: &v3.ItemsItem{
SchemaOrReference: []*v3.SchemaOrReference{
&v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Reference{
Reference: &v3.Reference{
XRef: "#/components/schemas/Pet",
},
},
},
},
},
},
},
},
},
&v3.NamedSchemaOrReference{
Name: "Error",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Required: []string{"code", "message"},
Properties: &v3.Properties{
AdditionalProperties: []*v3.NamedSchemaOrReference{
&v3.NamedSchemaOrReference{
Name: "code",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "integer",
Format: "int32",
},
},
},
},
&v3.NamedSchemaOrReference{
Name: "message",
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "string",
},
},
},
},
},
},
},
},
},
},
},
},
}
return d
}