Bumping k8s dependencies to 1.13

This commit is contained in:
Cheng Xing
2018-11-16 14:08:25 -08:00
parent 305407125c
commit b4c0b68ec7
8002 changed files with 884099 additions and 276228 deletions

View File

@@ -1,6 +1,7 @@
package gnostic_plugin_v1
import (
"errors"
"flag"
"fmt"
"io"
@@ -10,9 +11,12 @@ import (
"path"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"
openapiv2 "github.com/googleapis/gnostic/OpenAPIv2"
openapiv3 "github.com/googleapis/gnostic/OpenAPIv3"
discovery "github.com/googleapis/gnostic/discovery"
surface "github.com/googleapis/gnostic/surface"
)
// Environment contains the environment of a plugin call.
@@ -77,7 +81,7 @@ When the -plugin option is specified, these flags are ignored.`)
}
// Log the invocation.
log.Printf("Running plugin %s", env.Invocation)
//log.Printf("Running plugin %s", env.Invocation)
env.Request = request
@@ -98,20 +102,36 @@ When the -plugin option is specified, these flags are ignored.`)
documentv2 := &openapiv2.Document{}
err = proto.Unmarshal(apiData, documentv2)
if err == nil {
env.Request.Openapi2 = documentv2
} else {
// ignore deserialization errors
env.Request.AddModel("openapi.v2.Document", documentv2)
// include experimental API surface model
surfaceModel, err := surface.NewModelFromOpenAPI2(documentv2)
if err != nil {
env.Request.AddModel("surface.v1.Model", surfaceModel)
}
return env, err
}
// Then try to unmarshal OpenAPI v3.
// If that failed, ignore deserialization errors and try to unmarshal OpenAPI v3.
documentv3 := &openapiv3.Document{}
err = proto.Unmarshal(apiData, documentv3)
if err == nil {
env.Request.Openapi3 = documentv3
} else {
// ignore deserialization errors
env.Request.AddModel("openapi.v3.Document", documentv3)
// include experimental API surface model
surfaceModel, err := surface.NewModelFromOpenAPI3(documentv3)
if err != nil {
env.Request.AddModel("surface.v1.Model", surfaceModel)
}
return env, err
}
// If that failed, ignore deserialization errors and try to unmarshal a Discovery document.
discoveryDocument := &discovery.Document{}
err = proto.Unmarshal(apiData, discoveryDocument)
if err == nil {
env.Request.AddModel("discovery.v1.Document", discoveryDocument)
return env, err
}
// If we get here, we don't know what we got
err = errors.New("Unrecognized format for input")
return env, err
}
return env, err
}
@@ -172,6 +192,12 @@ func HandleResponse(response *Response, outputLocation string) error {
return nil
}
func (request *Request) AddModel(modelType string, model proto.Message) error {
modelBytes, err := proto.Marshal(model)
request.Models = append(request.Models, &any.Any{TypeUrl: modelType, Value: modelBytes})
return err
}
func isFile(path string) bool {
fileInfo, err := os.Stat(path)
if err != nil {

View File

@@ -30,9 +30,12 @@ import (
"path"
"strings"
"github.com/golang/protobuf/proto"
plugins "github.com/googleapis/gnostic/plugins"
"github.com/googleapis/gnostic/plugins/gnostic-analyze/statistics"
"github.com/golang/protobuf/proto"
openapiv2 "github.com/googleapis/gnostic/OpenAPIv2"
openapiv3 "github.com/googleapis/gnostic/OpenAPIv3"
plugins "github.com/googleapis/gnostic/plugins"
)
// Record an error, then serialize and return a response.
@@ -56,14 +59,24 @@ func main() {
env.RespondAndExitIfError(err)
var stats *statistics.DocumentStatistics
if env.Request.Openapi2 != nil {
// Analyze the API document.
stats = statistics.NewDocumentStatistics(env.Request.SourceName, env.Request.Openapi2)
}
if env.Request.Openapi3 != nil {
// Analyze the API document.
stats = statistics.NewDocumentStatisticsV3(env.Request.SourceName, env.Request.Openapi3)
for _, model := range env.Request.Models {
switch model.TypeUrl {
case "openapi.v2.Document":
documentv2 := &openapiv2.Document{}
err = proto.Unmarshal(model.Value, documentv2)
if err == nil {
// Analyze the API document.
stats = statistics.NewDocumentStatistics(env.Request.SourceName, documentv2)
}
case "openapi.v3.Document":
documentv3 := &openapiv3.Document{}
err = proto.Unmarshal(model.Value, documentv3)
if err == nil {
// Analyze the API document.
stats = statistics.NewDocumentStatisticsV3(env.Request.SourceName, documentv3)
}
}
}
if stats != nil {

View File

@@ -1,9 +1,13 @@
// +build ignore
// This file is omitted when getting with `go get github.com/googleapis/gnostic/...`
package main
import (
"fmt"
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/apis_guru/apis_guru"
"sort"
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/apis_guru/apis_guru"
)
func main() {

View File

@@ -0,0 +1,19 @@
/*
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 bookstore exists to allow this repo to work with recursive go get.
// It will be filled in with auto generated code.
package bookstore

View File

@@ -0,0 +1,20 @@
build:
go get golang.org/x/tools/cmd/goimports
go install github.com/googleapis/gnostic
go install github.com/googleapis/gnostic/plugins/gnostic-go-generator
rm -f $(GOPATH)/bin/gnostic-go-client $(GOPATH)/bin/gnostic-go-server
ln -s $(GOPATH)/bin/gnostic-go-generator $(GOPATH)/bin/gnostic-go-client
ln -s $(GOPATH)/bin/gnostic-go-generator $(GOPATH)/bin/gnostic-go-server
all: build
gnostic sample.yaml --go-generator-out=sample
clean:
rm -rf sample service/service
test: all
killall service; true # ignore errors due to no matching processes
cd service; go get .; go build; ./service &
go test
killall service

View File

@@ -0,0 +1,24 @@
# API Sample
This directory contains an OpenAPI description of a sample API
that exercises various OpenAPI features.
Use this example to try the `gnostic-go-generator` plugin, which implements
`gnostic-go-client` and `gnostic-go-server` for generating API client and
server code, respectively.
Run "make all" to build and install `gnostic` and the Go plugins.
It will generate both client and server code. The API client and
server code will be in the `sample` package.
The `service` directory contains additional code that completes the server.
To build and run the service, `cd service` and do the following:
go get .
go build
./service &
To test the service with the generated client, go back up to the top-level
directory and run `go test`. The test in `sample_test.go` uses client
code generated in `sample` to verify the service.

View File

@@ -0,0 +1,67 @@
swagger: '2.0'
schemes:
- https
host: sample.io
basePath: /
info:
title: sample.io
version: '1.0'
consumes:
- application/json
produces:
- application/json;charset=UTF-8
securityDefinitions:
api_key:
in: query
name: key
type: apiKey
paths:
/sample/{id}:
get:
operationId: "GetSample"
parameters:
- description: identifier
in: path
name: id
required: true
type: string
responses:
'200':
description: sample response
schema:
$ref: '#/definitions/Sample'
'401':
description: User doesn't have a valid session.
schema:
$ref: '#/definitions/APIError'
'404':
description: Unable to find supplied extractor ID.
schema:
$ref: '#/definitions/APIError'
security:
- api_key: []
summary: Get a sample response
tags:
- sample
- demo
definitions:
APIError:
properties:
code:
description: Internal error code
format: int
type: integer
message:
description: A message containing a brief description of the error
type: string
type: object
Sample:
properties:
id:
type: string
thing:
type: object
count:
format: int32
type: integer
type: object

View File

@@ -0,0 +1,19 @@
/*
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 sample exists to allow this repo to work with recursive go get.
// It will be filled in with auto generated code.
package sample

View File

@@ -0,0 +1,68 @@
/*
Copyright 2018 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 test
import (
"fmt"
"net/http"
"strings"
"testing"
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/sample/sample"
)
const service = "http://localhost:8080"
func TestSample(t *testing.T) {
// create a client
s := sample.NewClient(service, nil)
// verify a sample request
{
message := "hello world"
response, err := s.GetSample(message)
if err != nil {
t.Log("get sample failed")
t.Fail()
}
if response.OK.Id != message || response.OK.Count != int32(len(message)) {
t.Log(fmt.Sprintf("get sample received %+v", response.OK))
t.Fail()
}
if (response == nil) || (response.OK == nil) {
t.Log(fmt.Sprintf("get sample failed %+v", response.OK))
t.Fail()
}
}
// verify the handling of an invalid request
{
req, err := http.NewRequest("GET", service+"/unsupported", strings.NewReader(""))
if err != nil {
t.Log("bad request failed")
return
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
// we expect a 404 (Not Found) code
if resp.StatusCode != 404 {
t.Log("bad request failed")
t.Fail()
}
return
}
}

View File

@@ -0,0 +1,9 @@
application: sample
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
- url: /
static_dir: static

View File

@@ -0,0 +1,27 @@
/*
Copyright 2018 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 (
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/sample/sample"
)
// init() is called when the package is loaded
// this allows this app to be trivially deployed to Google App Engine, which does not call main()
func init() {
sample.Initialize(NewService())
}

View File

@@ -0,0 +1,34 @@
// +build !appengine
// This file is omitted when the app is built for Google App Engine
/*
Copyright 2018 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 (
"log"
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/sample/sample"
)
func main() {
err := sample.ServeHTTP(":8080")
if err != nil {
log.Printf("%v", err)
}
}

View File

@@ -0,0 +1,38 @@
/*
Copyright 2018 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 (
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/sample/sample"
)
//
// The Service type implements a sample service.
//
type Service struct{}
func NewService() *Service {
return &Service{}
}
func (service *Service) GetSample(parameters *sample.GetSampleParameters, responses *sample.GetSampleResponses) (err error) {
(*responses).OK = &sample.Sample{
Id: parameters.Id,
Thing: map[string]interface{}{"thing": 123},
Count: int32(len(parameters.Id))}
return err
}

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/googleapis/gnostic/plugins/gnostic-go-generator/examples/v2.0/xkcd/xkcd"
)

View File

@@ -0,0 +1,19 @@
/*
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 xkcd exists to allow this repo to work with recursive go get.
// It will be filled in with auto generated code.
package xkcd

View File

@@ -0,0 +1,19 @@
/*
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 bookstore exists to allow this repo to work with recursive go get.
// It will be filled in with auto generated code.
package bookstore

View File

@@ -0,0 +1,19 @@
/*
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 urlshortener exists to allow this repo to work with recursive go get.
// It will be filled in with auto generated code.
package urlshortener

View File

@@ -16,8 +16,8 @@ package main
import (
surface "github.com/googleapis/gnostic/surface"
"unicode"
"strings"
"unicode"
)
type GoLanguageModel struct{}
@@ -49,7 +49,7 @@ func (language *GoLanguageModel) Prepare(model *surface.Model) {
f.NativeType = "int64"
}
case "object":
f.NativeType = "{}interface"
f.NativeType = "interface{}"
case "string":
f.NativeType = "string"
default:
@@ -88,6 +88,8 @@ func goFieldName(name string) string {
// avoid integers
if name == "200" {
return "OK"
} else if unicode.IsDigit(rune(name[0])) {
return "Code" + name
}
return name
}

View File

@@ -21,7 +21,9 @@ import (
"errors"
"strings"
"github.com/golang/protobuf/proto"
plugins "github.com/googleapis/gnostic/plugins"
surface "github.com/googleapis/gnostic/surface"
)
// This is the main function for the code generation plugin.
@@ -42,30 +44,33 @@ func main() {
files = []string{"client.go", "server.go", "provider.go", "types.go", "constants.go"}
}
// Get the code surface model.
model := env.Request.Surface
for _, model := range env.Request.Models {
switch model.TypeUrl {
case "surface.v1.Model":
surfaceModel := &surface.Model{}
err = proto.Unmarshal(model.Value, surfaceModel)
if err == nil {
// Customize the code surface model for Go
NewGoLanguageModel().Prepare(surfaceModel)
if model == nil {
err = errors.New("No generated code surface model is available.")
env.RespondAndExitIfError(err)
modelJSON, _ := json.MarshalIndent(surfaceModel, "", " ")
modelFile := &plugins.File{Name: "model.json", Data: modelJSON}
env.Response.Files = append(env.Response.Files, modelFile)
// Create the renderer.
renderer, err := NewServiceRenderer(surfaceModel)
renderer.Package = packageName
env.RespondAndExitIfError(err)
// Run the renderer to generate files and add them to the response object.
err = renderer.Render(env.Response, files)
env.RespondAndExitIfError(err)
// Return with success.
env.RespondAndExit()
}
}
}
// Customize the code surface model for Go
NewGoLanguageModel().Prepare(model)
modelJSON, _ := json.MarshalIndent(model, "", " ")
modelFile := &plugins.File{Name: "model.json", Data: modelJSON}
env.Response.Files = append(env.Response.Files, modelFile)
// Create the renderer.
renderer, err := NewServiceRenderer(model)
renderer.Package = packageName
err = errors.New("No generated code surface model is available.")
env.RespondAndExitIfError(err)
// Run the renderer to generate files and add them to the response object.
err = renderer.Render(env.Response, files)
env.RespondAndExitIfError(err)
// Return with success.
env.RespondAndExit()
}

View File

@@ -109,7 +109,9 @@ func (renderer *Renderer) RenderClient() ([]byte, error) {
if method.Method == "POST" {
f.WriteLine(`body := new(bytes.Buffer)`)
f.WriteLine(`json.NewEncoder(body).Encode(` + parametersType.FieldWithPosition(surface.Position_BODY).Name + `)`)
if parametersType != nil {
f.WriteLine(`json.NewEncoder(body).Encode(` + parametersType.FieldWithPosition(surface.Position_BODY).Name + `)`)
}
f.WriteLine(`req, err := http.NewRequest("` + method.Method + `", path, body)`)
f.WriteLine(`reqHeaders := make(http.Header)`)
f.WriteLine(`reqHeaders.Set("Content-Type", "application/json")`)

View File

@@ -43,7 +43,7 @@ func (renderer *Renderer) RenderTypes() ([]byte, error) {
} else if modelType.Kind == surface.TypeKind_OBJECT {
f.WriteLine(`type ` + modelType.TypeName + ` map[string]` + modelType.ContentType)
} else {
f.WriteLine(`type ` + modelType.TypeName + ` struct {}`)
f.WriteLine(`type ` + modelType.TypeName + ` interface {}`)
}
}
return f.Bytes(), nil

View File

@@ -17,14 +17,17 @@
package main
import (
openapi2 "github.com/googleapis/gnostic/OpenAPIv2"
openapi3 "github.com/googleapis/gnostic/OpenAPIv3"
"log"
"github.com/golang/protobuf/proto"
openapiv2 "github.com/googleapis/gnostic/OpenAPIv2"
openapiv3 "github.com/googleapis/gnostic/OpenAPIv3"
plugins "github.com/googleapis/gnostic/plugins"
"github.com/googleapis/gnostic/printer"
)
// generate a simple report of an OpenAPI document's contents
func printDocumentV2(code *printer.Code, document *openapi2.Document) {
func printDocumentV2(code *printer.Code, document *openapiv2.Document) {
code.Print("Swagger: %+v", document.Swagger)
code.Print("Host: %+v", document.Host)
code.Print("BasePath: %+v", document.BasePath)
@@ -57,7 +60,7 @@ func printDocumentV2(code *printer.Code, document *openapi2.Document) {
}
// generate a simple report of an OpenAPI document's contents
func printDocumentV3(code *printer.Code, document *openapi3.Document) {
func printDocumentV3(code *printer.Code, document *openapiv3.Document) {
code.Print("OpenAPI: %+v", document.Openapi)
code.Print("Servers: %+v", document.Servers)
if document.Info != nil {
@@ -92,20 +95,28 @@ func printDocumentV3(code *printer.Code, document *openapi3.Document) {
func main() {
env, err := plugins.NewEnvironment()
env.RespondAndExitIfError(err)
code := &printer.Code{}
switch {
case env.Request.Openapi2 != nil:
printDocumentV2(code, env.Request.Openapi2)
case env.Request.Openapi3 != nil:
printDocumentV3(code, env.Request.Openapi3)
default:
for _, model := range env.Request.Models {
log.Printf("model %s", model.TypeUrl)
switch model.TypeUrl {
case "openapi.v2.Document":
documentv2 := &openapiv2.Document{}
err = proto.Unmarshal(model.Value, documentv2)
if err == nil {
printDocumentV2(code, documentv2)
}
case "openapi.v3.Document":
documentv3 := &openapiv3.Document{}
err = proto.Unmarshal(model.Value, documentv3)
if err == nil {
printDocumentV3(code, documentv3)
}
}
}
file := &plugins.File{
Name: "summary.txt",
Data: []byte(code.String()),
}
env.Response.Files = append(env.Response.Files, file)
env.RespondAndExit()
}

View File

@@ -1,11 +1,13 @@
BINDIR=.build/debug
all:
swift build
cp .build/debug/gnostic-swift-generator gnostic-swift-generator
rm -f gnostic-swift-client gnostic-swift-server
ln -s gnostic-swift-generator gnostic-swift-client
ln -s gnostic-swift-generator gnostic-swift-server
install: all
cp $(BINDIR)/gnostic-swift-generator $(GOPATH)/bin/gnostic-swift-generator
cp $(BINDIR)/gnostic-swift-generator $(GOPATH)/bin/gnostic-swift-client
cp $(BINDIR)/gnostic-swift-generator $(GOPATH)/bin/gnostic-swift-server
clean:
rm -rf .build Packages
rm -rf gnostic-swift-client gnostic-swift-server gnostic-swift-generator

View File

@@ -1,10 +1,10 @@
# OpenAPI Swift Generator Plugin
This directory contains an `openapic` plugin that can be used to generate a Swift client library and scaffolding for a Swift server for an API with an OpenAPI description.
This directory contains a `gnostic` plugin that can be used to generate a Swift client library and scaffolding for a Swift server for an API with an OpenAPI description.
The plugin can be invoked like this:
openapic bookstore.json --swift_generator_out=Bookstore
gnostic bookstore.json --swift-generator-out=Bookstore
Where `Bookstore` is the name of a directory where the generated code will be written.

View File

@@ -171,45 +171,11 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
/// Clears the value of `compilerVersion`. Subsequent reads from it will return its default value.
public mutating func clearCompilerVersion() {_storage._compilerVersion = nil}
/// OpenAPI v2 API representation
public var openapi2: Openapi_V2_Document {
get {return _storage._openapi2 ?? Openapi_V2_Document()}
set {_uniqueStorage()._openapi2 = newValue}
/// API models
public var models: [SwiftProtobuf.Google_Protobuf_Any] {
get {return _storage._models}
set {_uniqueStorage()._models = newValue}
}
/// Returns true if `openapi2` has been explicitly set.
public var hasOpenapi2: Bool {return _storage._openapi2 != nil}
/// Clears the value of `openapi2`. Subsequent reads from it will return its default value.
public mutating func clearOpenapi2() {_storage._openapi2 = nil}
/// OpenAPI v3 API representation
public var openapi3: Openapi_V3_Document {
get {return _storage._openapi3 ?? Openapi_V3_Document()}
set {_uniqueStorage()._openapi3 = newValue}
}
/// Returns true if `openapi3` has been explicitly set.
public var hasOpenapi3: Bool {return _storage._openapi3 != nil}
/// Clears the value of `openapi3`. Subsequent reads from it will return its default value.
public mutating func clearOpenapi3() {_storage._openapi3 = nil}
/// Discovery API representation
public var discovery: Discovery_V1_Document {
get {return _storage._discovery ?? Discovery_V1_Document()}
set {_uniqueStorage()._discovery = newValue}
}
/// Returns true if `discovery` has been explicitly set.
public var hasDiscovery: Bool {return _storage._discovery != nil}
/// Clears the value of `discovery`. Subsequent reads from it will return its default value.
public mutating func clearDiscovery() {_storage._discovery = nil}
/// generated code surface representation
public var surface: Surface_V1_Model {
get {return _storage._surface ?? Surface_V1_Model()}
set {_uniqueStorage()._surface = newValue}
}
/// Returns true if `surface` has been explicitly set.
public var hasSurface: Bool {return _storage._surface != nil}
/// Clears the value of `surface`. Subsequent reads from it will return its default value.
public mutating func clearSurface() {_storage._surface = nil}
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -228,10 +194,7 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
case 2: try decoder.decodeSingularStringField(value: &_storage._outputPath)
case 3: try decoder.decodeRepeatedMessageField(value: &_storage._parameters)
case 4: try decoder.decodeSingularMessageField(value: &_storage._compilerVersion)
case 5: try decoder.decodeSingularMessageField(value: &_storage._openapi2)
case 6: try decoder.decodeSingularMessageField(value: &_storage._openapi3)
case 7: try decoder.decodeSingularMessageField(value: &_storage._discovery)
case 8: try decoder.decodeSingularMessageField(value: &_storage._surface)
case 5: try decoder.decodeRepeatedMessageField(value: &_storage._models)
default: break
}
}
@@ -256,17 +219,8 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
if let v = _storage._compilerVersion {
try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
}
if let v = _storage._openapi2 {
try visitor.visitSingularMessageField(value: v, fieldNumber: 5)
}
if let v = _storage._openapi3 {
try visitor.visitSingularMessageField(value: v, fieldNumber: 6)
}
if let v = _storage._discovery {
try visitor.visitSingularMessageField(value: v, fieldNumber: 7)
}
if let v = _storage._surface {
try visitor.visitSingularMessageField(value: v, fieldNumber: 8)
if !_storage._models.isEmpty {
try visitor.visitRepeatedMessageField(value: _storage._models, fieldNumber: 5)
}
}
try unknownFields.traverse(visitor: &visitor)
@@ -284,13 +238,13 @@ public struct Gnostic_Plugin_V1_Response: SwiftProtobuf.Message {
/// even if it reports an error in this way.
///
/// This should be used to indicate errors which prevent the plugin from
/// operating as intended. Errors which indicate a problem in openapic
/// operating as intended. Errors which indicate a problem in gnostic
/// itself -- such as the input Document being unparseable -- should be
/// reported by writing a message to stderr and exiting with a non-zero
/// status code.
public var errors: [String] = []
/// file output, each file will be written by openapic to an appropriate location.
/// file output, each file will be written by gnostic to an appropriate location.
public var files: [Gnostic_Plugin_V1_File] = []
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -411,10 +365,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
2: .standard(proto: "output_path"),
3: .same(proto: "parameters"),
4: .standard(proto: "compiler_version"),
5: .same(proto: "openapi2"),
6: .same(proto: "openapi3"),
7: .same(proto: "discovery"),
8: .same(proto: "surface"),
5: .same(proto: "models"),
]
fileprivate class _StorageClass {
@@ -422,10 +373,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
var _outputPath: String = String()
var _parameters: [Gnostic_Plugin_V1_Parameter] = []
var _compilerVersion: Gnostic_Plugin_V1_Version? = nil
var _openapi2: Openapi_V2_Document? = nil
var _openapi3: Openapi_V3_Document? = nil
var _discovery: Discovery_V1_Document? = nil
var _surface: Surface_V1_Model? = nil
var _models: [SwiftProtobuf.Google_Protobuf_Any] = []
static let defaultInstance = _StorageClass()
@@ -436,10 +384,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
_outputPath = source._outputPath
_parameters = source._parameters
_compilerVersion = source._compilerVersion
_openapi2 = source._openapi2
_openapi3 = source._openapi3
_discovery = source._discovery
_surface = source._surface
_models = source._models
}
}
@@ -457,10 +402,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
if _storage._outputPath != other_storage._outputPath {return false}
if _storage._parameters != other_storage._parameters {return false}
if _storage._compilerVersion != other_storage._compilerVersion {return false}
if _storage._openapi2 != other_storage._openapi2 {return false}
if _storage._openapi3 != other_storage._openapi3 {return false}
if _storage._discovery != other_storage._discovery {return false}
if _storage._surface != other_storage._surface {return false}
if _storage._models != other_storage._models {return false}
return true
}
if !storagesAreEqual {return false}

View File

@@ -26,15 +26,24 @@ func main() throws {
let request = try Gnostic_Plugin_V1_Request(serializedData:rawRequest)
var response = Gnostic_Plugin_V1_Response()
var openapiv2 : Openapi_V2_Document?
var surface : Surface_V1_Model?
for model in request.models {
if model.typeURL == "openapi.v2.Document" {
openapiv2 = try Openapi_V2_Document(serializedData: model.value)
} else if model.typeURL == "surface.v1.Model" {
surface = try Surface_V1_Model(serializedData: model.value)
}
}
if request.hasOpenapi2 && request.hasSurface {
let document = request.openapi2
let surface = request.surface
Log("\(request.surface)")
if let openapiv2 = openapiv2,
let surface = surface {
// build the service renderer
let renderer = ServiceRenderer(surface:surface, document:document)
let renderer = ServiceRenderer(surface:surface, document:openapiv2)
// generate the desired files
var filenames : [String]

View File

@@ -1,7 +1,5 @@
all:
rm -f gnostic-swift-generator
ln -s ../../gnostic-swift-generator
gnostic bookstore.json --swift-generator-out=Sources/Bookstore
swift build

View File

@@ -2,11 +2,11 @@
This directory contains an OpenAPI description of a simple bookstore API.
Use this example to try the `openapi_swift_generator` plugin, which
Use this example to try the `gnostic-swift-generator` plugin, which
generates Swift code that implements an API client and server for
an OpenAPI description.
Run `make all` to build and install `openapic` and the Swift plugin.
Run `make all` to build and install `gnostic` and the Swift plugin.
It will generate both client and server code. The API client and
server code will be in the `Sources/Bookstore` package.

View File

@@ -1,7 +1,14 @@
TGT=gnostic-swift-sample
BINDIR=.build/debug
all:
swift build
install: all
cp $(BINDIR)/$(TGT) $(GOPATH)/bin/$(TGT)
clean :
rm -rf Packages
rm -rf .build

View File

@@ -171,45 +171,11 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
/// Clears the value of `compilerVersion`. Subsequent reads from it will return its default value.
public mutating func clearCompilerVersion() {_storage._compilerVersion = nil}
/// OpenAPI v2 API representation
public var openapi2: Openapi_V2_Document {
get {return _storage._openapi2 ?? Openapi_V2_Document()}
set {_uniqueStorage()._openapi2 = newValue}
/// API models
public var models: [SwiftProtobuf.Google_Protobuf_Any] {
get {return _storage._models}
set {_uniqueStorage()._models = newValue}
}
/// Returns true if `openapi2` has been explicitly set.
public var hasOpenapi2: Bool {return _storage._openapi2 != nil}
/// Clears the value of `openapi2`. Subsequent reads from it will return its default value.
public mutating func clearOpenapi2() {_storage._openapi2 = nil}
/// OpenAPI v3 API representation
public var openapi3: Openapi_V3_Document {
get {return _storage._openapi3 ?? Openapi_V3_Document()}
set {_uniqueStorage()._openapi3 = newValue}
}
/// Returns true if `openapi3` has been explicitly set.
public var hasOpenapi3: Bool {return _storage._openapi3 != nil}
/// Clears the value of `openapi3`. Subsequent reads from it will return its default value.
public mutating func clearOpenapi3() {_storage._openapi3 = nil}
/// Discovery API representation
public var discovery: Discovery_V1_Document {
get {return _storage._discovery ?? Discovery_V1_Document()}
set {_uniqueStorage()._discovery = newValue}
}
/// Returns true if `discovery` has been explicitly set.
public var hasDiscovery: Bool {return _storage._discovery != nil}
/// Clears the value of `discovery`. Subsequent reads from it will return its default value.
public mutating func clearDiscovery() {_storage._discovery = nil}
/// generated code surface representation
public var surface: Surface_V1_Model {
get {return _storage._surface ?? Surface_V1_Model()}
set {_uniqueStorage()._surface = newValue}
}
/// Returns true if `surface` has been explicitly set.
public var hasSurface: Bool {return _storage._surface != nil}
/// Clears the value of `surface`. Subsequent reads from it will return its default value.
public mutating func clearSurface() {_storage._surface = nil}
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -228,10 +194,7 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
case 2: try decoder.decodeSingularStringField(value: &_storage._outputPath)
case 3: try decoder.decodeRepeatedMessageField(value: &_storage._parameters)
case 4: try decoder.decodeSingularMessageField(value: &_storage._compilerVersion)
case 5: try decoder.decodeSingularMessageField(value: &_storage._openapi2)
case 6: try decoder.decodeSingularMessageField(value: &_storage._openapi3)
case 7: try decoder.decodeSingularMessageField(value: &_storage._discovery)
case 8: try decoder.decodeSingularMessageField(value: &_storage._surface)
case 5: try decoder.decodeRepeatedMessageField(value: &_storage._models)
default: break
}
}
@@ -256,17 +219,8 @@ public struct Gnostic_Plugin_V1_Request: SwiftProtobuf.Message {
if let v = _storage._compilerVersion {
try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
}
if let v = _storage._openapi2 {
try visitor.visitSingularMessageField(value: v, fieldNumber: 5)
}
if let v = _storage._openapi3 {
try visitor.visitSingularMessageField(value: v, fieldNumber: 6)
}
if let v = _storage._discovery {
try visitor.visitSingularMessageField(value: v, fieldNumber: 7)
}
if let v = _storage._surface {
try visitor.visitSingularMessageField(value: v, fieldNumber: 8)
if !_storage._models.isEmpty {
try visitor.visitRepeatedMessageField(value: _storage._models, fieldNumber: 5)
}
}
try unknownFields.traverse(visitor: &visitor)
@@ -284,13 +238,13 @@ public struct Gnostic_Plugin_V1_Response: SwiftProtobuf.Message {
/// even if it reports an error in this way.
///
/// This should be used to indicate errors which prevent the plugin from
/// operating as intended. Errors which indicate a problem in openapic
/// operating as intended. Errors which indicate a problem in gnostic
/// itself -- such as the input Document being unparseable -- should be
/// reported by writing a message to stderr and exiting with a non-zero
/// status code.
public var errors: [String] = []
/// file output, each file will be written by openapic to an appropriate location.
/// file output, each file will be written by gnostic to an appropriate location.
public var files: [Gnostic_Plugin_V1_File] = []
public var unknownFields = SwiftProtobuf.UnknownStorage()
@@ -411,10 +365,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
2: .standard(proto: "output_path"),
3: .same(proto: "parameters"),
4: .standard(proto: "compiler_version"),
5: .same(proto: "openapi2"),
6: .same(proto: "openapi3"),
7: .same(proto: "discovery"),
8: .same(proto: "surface"),
5: .same(proto: "models"),
]
fileprivate class _StorageClass {
@@ -422,10 +373,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
var _outputPath: String = String()
var _parameters: [Gnostic_Plugin_V1_Parameter] = []
var _compilerVersion: Gnostic_Plugin_V1_Version? = nil
var _openapi2: Openapi_V2_Document? = nil
var _openapi3: Openapi_V3_Document? = nil
var _discovery: Discovery_V1_Document? = nil
var _surface: Surface_V1_Model? = nil
var _models: [SwiftProtobuf.Google_Protobuf_Any] = []
static let defaultInstance = _StorageClass()
@@ -436,10 +384,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
_outputPath = source._outputPath
_parameters = source._parameters
_compilerVersion = source._compilerVersion
_openapi2 = source._openapi2
_openapi3 = source._openapi3
_discovery = source._discovery
_surface = source._surface
_models = source._models
}
}
@@ -457,10 +402,7 @@ extension Gnostic_Plugin_V1_Request: SwiftProtobuf._MessageImplementationBase, S
if _storage._outputPath != other_storage._outputPath {return false}
if _storage._parameters != other_storage._parameters {return false}
if _storage._compilerVersion != other_storage._compilerVersion {return false}
if _storage._openapi2 != other_storage._openapi2 {return false}
if _storage._openapi3 != other_storage._openapi3 {return false}
if _storage._discovery != other_storage._discovery {return false}
if _storage._surface != other_storage._surface {return false}
if _storage._models != other_storage._models {return false}
return true
}
if !storagesAreEqual {return false}

View File

@@ -55,16 +55,19 @@ func main() throws {
var response = Gnostic_Plugin_V1_Response()
let rawRequest = try Stdin.readall()
let request = try Gnostic_Plugin_V1_Request(serializedData: rawRequest)
if request.hasOpenapi2 {
let document = request.openapi2
let report = printDocument(document:document, name:request.sourceName)
if let reportData = report.data(using:.utf8) {
var file = Gnostic_Plugin_V1_File()
file.name = "report.txt"
file.data = reportData
response.files.append(file)
for model in request.models {
if model.typeURL == "openapi.v2.Document" {
let document = try Openapi_V2_Document(serializedData: model.value)
let report = printDocument(document:document, name:request.sourceName)
if let reportData = report.data(using:.utf8) {
var file = Gnostic_Plugin_V1_File()
file.name = "report.txt"
file.data = reportData
response.files.append(file)
}
}
}
}
let serializedResponse = try response.serializedData()
Stdout.write(bytes: serializedResponse)
}

View File

@@ -1,17 +1,18 @@
// Code generated by protoc-gen-go.
// source: plugin.proto
// DO NOT EDIT!
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: plugins/plugin.proto
/*
Package gnostic_plugin_v1 is a generated protocol buffer package.
It is generated from these files:
plugin.proto
plugins/plugin.proto
It has these top-level messages:
Version
Parameter
Request
Message
Messages
Response
File
*/
@@ -20,10 +21,7 @@ package gnostic_plugin_v1
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
import openapi_v3 "github.com/googleapis/gnostic/OpenAPIv3"
import discovery_v1 "github.com/googleapis/gnostic/discovery"
import surface_v1 "github.com/googleapis/gnostic/surface"
import google_protobuf "github.com/golang/protobuf/ptypes/any"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
@@ -36,6 +34,36 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Message_Level int32
const (
Message_UNKNOWN Message_Level = 0
Message_INFO Message_Level = 1
Message_WARNING Message_Level = 2
Message_ERROR Message_Level = 3
Message_FATAL Message_Level = 4
)
var Message_Level_name = map[int32]string{
0: "UNKNOWN",
1: "INFO",
2: "WARNING",
3: "ERROR",
4: "FATAL",
}
var Message_Level_value = map[string]int32{
"UNKNOWN": 0,
"INFO": 1,
"WARNING": 2,
"ERROR": 3,
"FATAL": 4,
}
func (x Message_Level) String() string {
return proto.EnumName(Message_Level_name, int32(x))
}
func (Message_Level) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{3, 0} }
// The version number of gnostic.
type Version struct {
Major int32 `protobuf:"varint,1,opt,name=major" json:"major,omitempty"`
@@ -116,14 +144,8 @@ type Request struct {
Parameters []*Parameter `protobuf:"bytes,3,rep,name=parameters" json:"parameters,omitempty"`
// The version number of gnostic.
CompilerVersion *Version `protobuf:"bytes,4,opt,name=compiler_version,json=compilerVersion" json:"compiler_version,omitempty"`
// OpenAPI v2 API representation
Openapi2 *openapi_v2.Document `protobuf:"bytes,5,opt,name=openapi2" json:"openapi2,omitempty"`
// OpenAPI v3 API representation
Openapi3 *openapi_v3.Document `protobuf:"bytes,6,opt,name=openapi3" json:"openapi3,omitempty"`
// Discovery API representation
Discovery *discovery_v1.Document `protobuf:"bytes,7,opt,name=discovery" json:"discovery,omitempty"`
// generated code surface representation
Surface *surface_v1.Model `protobuf:"bytes,8,opt,name=surface" json:"surface,omitempty"`
// API models
Models []*google_protobuf.Any `protobuf:"bytes,5,rep,name=models" json:"models,omitempty"`
}
func (m *Request) Reset() { *m = Request{} }
@@ -159,30 +181,70 @@ func (m *Request) GetCompilerVersion() *Version {
return nil
}
func (m *Request) GetOpenapi2() *openapi_v2.Document {
func (m *Request) GetModels() []*google_protobuf.Any {
if m != nil {
return m.Openapi2
return m.Models
}
return nil
}
func (m *Request) GetOpenapi3() *openapi_v3.Document {
// Plugins can return messages to be collated and reported by gnostic.
type Message struct {
// message severity
Level Message_Level `protobuf:"varint,1,opt,name=level,enum=gnostic.plugin.v1.Message_Level" json:"level,omitempty"`
// a unique message identifier
Code string `protobuf:"bytes,2,opt,name=code" json:"code,omitempty"`
// message text
Text string `protobuf:"bytes,3,opt,name=text" json:"text,omitempty"`
// an associated key path in an API description
Keys []string `protobuf:"bytes,4,rep,name=keys" json:"keys,omitempty"`
}
func (m *Message) Reset() { *m = Message{} }
func (m *Message) String() string { return proto.CompactTextString(m) }
func (*Message) ProtoMessage() {}
func (*Message) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *Message) GetLevel() Message_Level {
if m != nil {
return m.Openapi3
return m.Level
}
return Message_UNKNOWN
}
func (m *Message) GetCode() string {
if m != nil {
return m.Code
}
return ""
}
func (m *Message) GetText() string {
if m != nil {
return m.Text
}
return ""
}
func (m *Message) GetKeys() []string {
if m != nil {
return m.Keys
}
return nil
}
func (m *Request) GetDiscovery() *discovery_v1.Document {
if m != nil {
return m.Discovery
}
return nil
type Messages struct {
Messages []*Message `protobuf:"bytes,1,rep,name=messages" json:"messages,omitempty"`
}
func (m *Request) GetSurface() *surface_v1.Model {
func (m *Messages) Reset() { *m = Messages{} }
func (m *Messages) String() string { return proto.CompactTextString(m) }
func (*Messages) ProtoMessage() {}
func (*Messages) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
func (m *Messages) GetMessages() []*Message {
if m != nil {
return m.Surface
return m.Messages
}
return nil
}
@@ -194,19 +256,21 @@ type Response struct {
// even if it reports an error in this way.
//
// This should be used to indicate errors which prevent the plugin from
// operating as intended. Errors which indicate a problem in openapic
// operating as intended. Errors which indicate a problem in gnostic
// itself -- such as the input Document being unparseable -- should be
// reported by writing a message to stderr and exiting with a non-zero
// status code.
Errors []string `protobuf:"bytes,1,rep,name=errors" json:"errors,omitempty"`
// file output, each file will be written by openapic to an appropriate location.
// file output, each file will be written by gnostic to an appropriate location.
Files []*File `protobuf:"bytes,2,rep,name=files" json:"files,omitempty"`
// informational messages to be collected and reported by gnostic.
Messages []*Message `protobuf:"bytes,3,rep,name=messages" json:"messages,omitempty"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (*Response) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (*Response) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
func (m *Response) GetErrors() []string {
if m != nil {
@@ -222,6 +286,13 @@ func (m *Response) GetFiles() []*File {
return nil
}
func (m *Response) GetMessages() []*Message {
if m != nil {
return m.Messages
}
return nil
}
// File describes a file generated by a plugin.
type File struct {
// name of the file
@@ -233,7 +304,7 @@ type File struct {
func (m *File) Reset() { *m = File{} }
func (m *File) String() string { return proto.CompactTextString(m) }
func (*File) ProtoMessage() {}
func (*File) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
func (*File) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
func (m *File) GetName() string {
if m != nil {
@@ -253,44 +324,49 @@ func init() {
proto.RegisterType((*Version)(nil), "gnostic.plugin.v1.Version")
proto.RegisterType((*Parameter)(nil), "gnostic.plugin.v1.Parameter")
proto.RegisterType((*Request)(nil), "gnostic.plugin.v1.Request")
proto.RegisterType((*Message)(nil), "gnostic.plugin.v1.Message")
proto.RegisterType((*Messages)(nil), "gnostic.plugin.v1.Messages")
proto.RegisterType((*Response)(nil), "gnostic.plugin.v1.Response")
proto.RegisterType((*File)(nil), "gnostic.plugin.v1.File")
proto.RegisterEnum("gnostic.plugin.v1.Message_Level", Message_Level_name, Message_Level_value)
}
func init() { proto.RegisterFile("plugin.proto", fileDescriptor0) }
func init() { proto.RegisterFile("plugins/plugin.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 499 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x8f, 0xd3, 0x3c,
0x10, 0xc6, 0xd5, 0xa6, 0x7f, 0xa7, 0xfb, 0xbe, 0xb0, 0xd6, 0x6a, 0xb1, 0x56, 0x48, 0x5b, 0xf5,
0x42, 0x25, 0x84, 0x4b, 0x1b, 0x10, 0x17, 0x2e, 0xac, 0x80, 0x15, 0x07, 0x76, 0x83, 0x0f, 0x5c,
0x2b, 0x6f, 0xea, 0xa6, 0x46, 0x49, 0x6c, 0x6c, 0x27, 0x82, 0x4f, 0xc2, 0x9d, 0x4f, 0x8a, 0x62,
0x27, 0x4d, 0xc5, 0x56, 0x68, 0x4f, 0x9d, 0xe7, 0xd1, 0xfc, 0x9e, 0xb8, 0x33, 0x03, 0x27, 0x2a,
0x2d, 0x12, 0x91, 0x13, 0xa5, 0xa5, 0x95, 0xe8, 0x34, 0xc9, 0xa5, 0xb1, 0x22, 0x26, 0xb5, 0x5b,
0x2e, 0x2f, 0xde, 0x24, 0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f, 0x47, 0x2e, 0x3f, 0xea, 0xfc, 0xee, 0x06, 0xd7, 0x37, 0xb7,
0x77, 0x03, 0x77, 0xe8, 0xe1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x40, 0x96, 0xff, 0x27, 0xeb,
0x03, 0x00, 0x00,
// 539 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xc1, 0x6e, 0xd3, 0x40,
0x10, 0xc5, 0xb1, 0xdd, 0xc4, 0x13, 0x28, 0x66, 0x55, 0x81, 0xa9, 0x90, 0x1a, 0xf9, 0x42, 0x0e,
0xe0, 0xa8, 0x41, 0xf4, 0xc4, 0x25, 0x91, 0x9a, 0xa8, 0xa2, 0x38, 0xd1, 0x0a, 0xe8, 0x31, 0xda,
0x3a, 0x1b, 0xc7, 0x60, 0x7b, 0xcd, 0xee, 0x3a, 0x6a, 0x3e, 0x81, 0xdf, 0xe0, 0x4b, 0xf8, 0x32,
0x84, 0x76, 0xd7, 0x89, 0x8a, 0x08, 0x07, 0x4e, 0x7e, 0xf3, 0xf4, 0xfc, 0x66, 0xe6, 0xed, 0xc0,
0x49, 0x95, 0xd7, 0x69, 0x56, 0x8a, 0x81, 0xf9, 0x46, 0x15, 0x67, 0x92, 0xa1, 0x27, 0x69, 0xc9,
0x84, 0xcc, 0x92, 0xa8, 0x61, 0x37, 0xe7, 0xa7, 0xcf, 0x53, 0xc6, 0xd2, 0x9c, 0x0e, 0xb4, 0xe0,
0xb6, 0x5e, 0x0d, 0x48, 0xb9, 0x35, 0xea, 0x30, 0x81, 0xf6, 0x67, 0xca, 0x45, 0xc6, 0x4a, 0x74,
0x02, 0x6e, 0x41, 0xbe, 0x30, 0x1e, 0x58, 0x3d, 0xab, 0xef, 0x62, 0x53, 0x68, 0x36, 0x2b, 0x19,
0x0f, 0x5a, 0x0d, 0xab, 0x0a, 0xc5, 0x56, 0x44, 0x26, 0x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0x17, 0xf0, 0xe6, 0x77, 0x00, 0x00,
0x00, 0xff, 0xff, 0x97, 0xa0, 0x65, 0xe7, 0xd5, 0x03, 0x00, 0x00,
}

View File

@@ -22,10 +22,7 @@
syntax = "proto3";
import "github.com/googleapis/gnostic/OpenAPIv2/OpenAPIv2.proto";
import "github.com/googleapis/gnostic/OpenAPIv3/OpenAPIv3.proto";
import "github.com/googleapis/gnostic/discovery/discovery.proto";
import "github.com/googleapis/gnostic/surface/surface.proto";
import "google/protobuf/any.proto";
package gnostic.plugin.v1;
@@ -85,17 +82,36 @@ message Request {
// The version number of gnostic.
Version compiler_version = 4;
// OpenAPI v2 API representation
openapi.v2.Document openapi2 = 5;
// API models
repeated google.protobuf.Any models = 5;
}
// OpenAPI v3 API representation
openapi.v3.Document openapi3 = 6;
// Plugins can return messages to be collated and reported by gnostic.
message Message {
// Discovery API representation
discovery.v1.Document discovery = 7;
// generated code surface representation
surface.v1.Model surface = 8;
enum Level {
UNKNOWN = 0;
INFO = 1;
WARNING = 2;
ERROR = 3;
FATAL = 4;
}
// message severity
Level level = 1;
// a unique message identifier
string code = 2;
// message text
string text = 3;
// an associated key path in an API description
repeated string keys = 4;
}
message Messages {
repeated Message messages = 1;
}
// The plugin writes an encoded Response to stdout.
@@ -106,14 +122,17 @@ message Response {
// even if it reports an error in this way.
//
// This should be used to indicate errors which prevent the plugin from
// operating as intended. Errors which indicate a problem in openapic
// operating as intended. Errors which indicate a problem in gnostic
// itself -- such as the input Document being unparseable -- should be
// reported by writing a message to stderr and exiting with a non-zero
// status code.
repeated string errors = 1;
// file output, each file will be written by openapic to an appropriate location.
// file output, each file will be written by gnostic to an appropriate location.
repeated File files = 2;
// informational messages to be collected and reported by gnostic.
repeated Message messages = 3;
}
// File describes a file generated by a plugin.