2 Commits

Author SHA1 Message Date
68fe21362b add helpers for openapi document
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2022-02-02 02:08:41 +03:00
99369de1ee update openapi
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2022-02-02 00:13:17 +03:00
6 changed files with 8683 additions and 5 deletions

View File

@@ -4,11 +4,8 @@ package main
//go:generate protoc -I. -I./api --go_out=paths=source_relative:. ./api/http.proto
//go:generate protoc -I. -I./api --go_out=paths=source_relative:. ./api/field_behavior.proto
//go:generate protoc -I. -I./api --go_out=paths=source_relative:. ./api/httpbody.proto
<<<<<<< HEAD
//go:generate protoc -I. -I./api --go_out=paths=source_relative:. ./api/micro.proto
=======
//go:generate protoc -I. -I./api --go_out=paths=source_relative:. ./api/client.proto
>>>>>>> 75c244f1a60f (update)
//go:generate protoc -I. -I./openapiv2 --go_out=paths=source_relative:. ./openapiv2/annotations.proto
//go:generate protoc -I. -I./openapiv2 --go_out=paths=source_relative:. ./openapiv2/openapiv2.proto
//go:generate protoc -I. -I./openapiv3 --go_out=paths=source_relative:. ./openapiv3/annotations.proto

42
openapiv2/document.go Normal file
View File

@@ -0,0 +1,42 @@
// Copyright 2020 Google LLC. 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 openapiv2
import (
"gopkg.in/yaml.v3"
"github.com/google/gnostic/compiler"
)
// ParseDocument reads an OpenAPI v2 description from a YAML/JSON representation.
func ParseDocument(b []byte) (*Document, error) {
info, err := compiler.ReadInfoFromBytes("", b)
if err != nil {
return nil, err
}
root := info.Content[0]
return NewDocument(root, compiler.NewContextWithExtensions("$root", root, nil, nil))
}
// YAMLValue produces a serialized YAML representation of the document.
func (d *Document) YAMLValue(comment string) ([]byte, error) {
rawInfo := d.ToRawInfo()
rawInfo = &yaml.Node{
Kind: yaml.DocumentNode,
Content: []*yaml.Node{rawInfo},
HeadComment: comment,
}
return yaml.Marshal(rawInfo)
}

View File

@@ -1,3 +1,4 @@
package openapiv2 // import "go.unistack.org/micro-proto/v3/openapiv2"
// Copyright 2020 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +15,6 @@
// THIS FILE IS AUTOMATICALLY GENERATED.
package openapiv2
import (
"fmt"
"regexp"

View File

@@ -663,3 +663,4 @@ message Xml {
bool wrapped = 5;
repeated NamedAny vendor_extension = 6;
}

42
openapiv3/document.go Normal file
View File

@@ -0,0 +1,42 @@
// Copyright 2020 Google LLC. 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 openapiv3
import (
"gopkg.in/yaml.v3"
"github.com/google/gnostic/compiler"
)
// ParseDocument reads an OpenAPI v3 description from a YAML/JSON representation.
func ParseDocument(b []byte) (*Document, error) {
info, err := compiler.ReadInfoFromBytes("", b)
if err != nil {
return nil, err
}
root := info.Content[0]
return NewDocument(root, compiler.NewContextWithExtensions("$root", root, nil, nil))
}
// YAMLValue produces a serialized YAML representation of the document.
func (d *Document) YAMLValue(comment string) ([]byte, error) {
rawInfo := d.ToRawInfo()
rawInfo = &yaml.Node{
Kind: yaml.DocumentNode,
Content: []*yaml.Node{rawInfo},
HeadComment: comment,
}
return yaml.Marshal(rawInfo)
}

File diff suppressed because it is too large Load Diff