Skip to content

Commit a808e63

Browse files
Merge branch 'google:main' into main
2 parents a4bc9b4 + ad271d5 commit a808e63

File tree

8 files changed

+47
-20
lines changed

8 files changed

+47
-20
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ can import packages from `gnostic-models` instead of `gnostic`.
3737

3838
[google/gnostic-grpc](https://github.com/google/gnostic-grpc) contains a
3939
gnostic plugin that can generate an annotated Protocol Buffer description of an
40-
API that, when transcode, produces an API that conforms to a specified OpenAPI
40+
API that, when transcoded, produces an API that conforms to a specified OpenAPI
4141
document. To go from protobuf to OpenAPI, see the
4242
[protoc-gen-openapi](cmd/protoc-gen-openapi) tool in this project.
4343

@@ -69,12 +69,12 @@ and later.
6969
git clone https://github.com/google/gnostic
7070
cd gnostic
7171

72-
2. Verify that you have a local installation of `protoc`. You can get protoc
72+
2. Verify that you have a local installation of `protoc`. You can get `protoc`
7373
[here](https://github.com/protocolbuffers/protobuf).
7474

7575
3. Build **gnostic** with `make`. This uses
7676
[go generate](https://blog.golang.org/generate) to build support code
77-
including code generated by `protoc` and the Go protoc plugin, which is
77+
including code generated by `protoc` and the Go `protoc` plugin, which is
7878
automatically downloaded from
7979
[github.com/golang/protobuf](https://github.com/golang/protobuf) by the
8080
[COMPILE-PROTOS.sh](COMPILE-PROTOS.sh) script. This also builds all plugins

generate-gnostic/generate-extension.go

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ func generateExtension(schemaFile string, outDir string) error {
281281
return err
282282
}
283283
err = exec.Command(runtime.GOROOT()+"/bin/gofmt", "-w", goFilename).Run()
284+
if err != nil {
285+
return err
286+
}
284287

285288
// generate the main file.
286289

generate-gnostic/generate-extension_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func TestErrorExtensionGeneratorUnsupportedPrimitive(t *testing.T) {
1616
"test/x-unsupportedprimitives.json",
1717
"--out_dir=/tmp",
1818
).Output()
19+
if err != nil {
20+
t.Fatalf("error executing generate-gnostic: %v", err)
21+
}
1922

2023
outputFile := "x-unsupportedprimitives.errors"
2124
_ = ioutil.WriteFile(outputFile, output, 0644)
@@ -38,6 +41,9 @@ func TestErrorExtensionGeneratorNameCollision(t *testing.T) {
3841
"test/x-extension-name-collision.json",
3942
"--out_dir=/tmp",
4043
).Output()
44+
if err != nil {
45+
t.Fatalf("error executing generate-gnostic: %v", err)
46+
}
4147

4248
outputFile := "x-extension-name-collision.errors"
4349
_ = ioutil.WriteFile(outputFile, output, 0644)

jsonwriter/writer.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ import (
1818
"bytes"
1919
"errors"
2020
"fmt"
21-
"strings"
21+
"strconv"
2222

2323
"gopkg.in/yaml.v3"
2424
)
2525

26-
const indentation = " "
27-
28-
// basic escaping, will need to be improved or replaced
29-
func escape(s string) string {
30-
s = strings.Replace(s, "\n", "\\n", -1)
31-
s = strings.Replace(s, "\"", "\\\"", -1)
32-
return s
33-
}
26+
const (
27+
indentation = " "
28+
null = "null"
29+
)
3430

3531
type writer struct {
3632
b bytes.Buffer
@@ -85,15 +81,15 @@ func (w *writer) writeScalar(node *yaml.Node, indent string) {
8581
}
8682
switch node.Tag {
8783
case "!!str":
88-
w.writeString("\"")
89-
w.writeString(escape(node.Value))
90-
w.writeString("\"")
84+
w.writeString(strconv.Quote(node.Value))
9185
case "!!int":
9286
w.writeString(node.Value)
9387
case "!!float":
9488
w.writeString(node.Value)
9589
case "!!bool":
9690
w.writeString(node.Value)
91+
case "!!null":
92+
w.writeString(null)
9793
}
9894
}
9995

jsonwriter/writer_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func TestMarshal(t *testing.T) {
3737
scalarBoolTestCase(),
3838
scalarFloatTestCase(),
3939
scalarIntTestCase(),
40+
scalarStringTestCase(),
41+
scalarNullTestCase(),
4042
sequenceStringArrayTestCase(),
4143
sequenceBoolArrayTestCase(),
4244
sequenceFloatArrayTestCase(),
@@ -88,6 +90,22 @@ func scalarFloatTestCase() *MarshalTestCase {
8890
}
8991
}
9092

93+
func scalarStringTestCase() *MarshalTestCase {
94+
return &MarshalTestCase{
95+
Name: "scalar string",
96+
Node: compiler.NewScalarNodeForString("a\\b\nc\""),
97+
Expected: "\"a\\\\b\\nc\\\"\"\n",
98+
}
99+
}
100+
101+
func scalarNullTestCase() *MarshalTestCase {
102+
return &MarshalTestCase{
103+
Name: "scalar null",
104+
Node: compiler.NewNullNode(),
105+
Expected: "null\n",
106+
}
107+
}
108+
91109
func scalarIntTestCase() *MarshalTestCase {
92110
return &MarshalTestCase{
93111
Name: "scalar int",

metrics/vocabulary/vocabulary.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ func WriteCSV(v *metrics.Vocabulary, filename string) error {
4343
filename = "vocabulary-operation.csv"
4444
}
4545
f4, ferror := os.Create(filename)
46-
defer f4.Close()
4746
if ferror != nil {
4847
return ferror
4948
}
49+
defer f4.Close()
50+
5051
for _, s := range v.Schemas {
5152
temp := fmt.Sprintf("%s,\"%s\",%d\n", "schemas", s.Word, int(s.Count))
5253
f4.WriteString(temp)

openapiv3/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Gnostic applications and plugins can use OpenAPIv3.proto to generate Protocol
77
Buffer support code for their preferred languages.
88

99
OpenAPIv3.go is used by Gnostic to read JSON and YAML OpenAPI descriptions into
10-
the Protocol Buffer-based datastructures generated from OpenAPIv3.proto.
10+
the Protocol Buffer-based data structures generated from OpenAPIv3.proto.
1111

1212
OpenAPIv3.proto and OpenAPIv3.go are generated by the Gnostic compiler
13-
generator, and OpenAPIv3.pb.go is generated by protoc, the Protocol Buffer
14-
compiler, and protoc-gen-go, the Protocol Buffer Go code generation plugin.
13+
generator, and OpenAPIv3.pb.go is generated by `protoc`, the Protocol Buffer
14+
compiler, and `protoc-gen-go`, the Protocol Buffer Go code generation plugin.
1515

16-
openapi-3.1.json is a JSON schema for OpenAPI 3.1 that is automatically
16+
`openapi-3.1.json` is a JSON schema for OpenAPI 3.1 that is automatically
1717
generated from the OpenAPI 3.1 specification. It is not an official JSON Schema
1818
for OpenAPI.
1919

plugins/gnostic-analyze/summarize/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var stats []statistics.DocumentStatistics
3232

3333
// walker is called for each summary file found.
3434
func walker(p string, info os.FileInfo, err error) error {
35+
if err != nil {
36+
return err
37+
}
3538
basename := path.Base(p)
3639
if basename != "summary.json" {
3740
return nil

0 commit comments

Comments
 (0)