go: vendor the oapi-codegen cmd
See the comment in tools.go, I cannot fully explain what's happening here. Somehow, Go 1.14 wants to use the vendored version of oapi-codegen but without this file, oapi-codegen isn't vendored so the generation fails. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
1a3cbb282a
commit
2241a8d9ed
75 changed files with 11211 additions and 0 deletions
77
vendor/github.com/deepmap/oapi-codegen/pkg/codegen/inline.go
generated
vendored
Normal file
77
vendor/github.com/deepmap/oapi-codegen/pkg/codegen/inline.go
generated
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2019 DeepMap, Inc.
|
||||
//
|
||||
// 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 codegen
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
)
|
||||
|
||||
// This generates a gzipped, base64 encoded JSON representation of the
|
||||
// swagger definition, which we embed inside the generated code.
|
||||
func GenerateInlinedSpec(t *template.Template, swagger *openapi3.Swagger) (string, error) {
|
||||
// Marshal to json
|
||||
encoded, err := swagger.MarshalJSON()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error marshaling swagger: %s", err)
|
||||
}
|
||||
|
||||
// gzip
|
||||
var buf bytes.Buffer
|
||||
zw, err := gzip.NewWriterLevel(&buf, gzip.BestCompression)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error creating gzip compressor: %s", err)
|
||||
}
|
||||
_, err = zw.Write(encoded)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error gzipping swagger file: %s", err)
|
||||
}
|
||||
err = zw.Close()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error gzipping swagger file: %s", err)
|
||||
}
|
||||
str := base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
|
||||
var parts []string
|
||||
const width = 80
|
||||
|
||||
// Chop up the string into an array of strings.
|
||||
for len(str) > width {
|
||||
part := str[0:width]
|
||||
parts = append(parts, part)
|
||||
str = str[width:]
|
||||
}
|
||||
if len(str) > 0 {
|
||||
parts = append(parts, str)
|
||||
}
|
||||
|
||||
// Generate inline code.
|
||||
buf.Reset()
|
||||
w := bufio.NewWriter(&buf)
|
||||
err = t.ExecuteTemplate(w, "inline.tmpl", parts)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error generating inlined spec: %s", err)
|
||||
}
|
||||
err = w.Flush()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error flushing output buffer for inlined spec: %s", err)
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue