Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-format-int64
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks committed Feb 29, 2024
2 parents 2d26622 + ad271d5 commit 7ed1b36
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -37,7 +37,7 @@ can import packages from `gnostic-models` instead of `gnostic`.

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

Expand Down Expand Up @@ -69,12 +69,12 @@ and later.
git clone https://github.com/google/gnostic
cd gnostic

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

3. Build **gnostic** with `make`. This uses
[go generate](https://blog.golang.org/generate) to build support code
including code generated by `protoc` and the Go protoc plugin, which is
including code generated by `protoc` and the Go `protoc` plugin, which is
automatically downloaded from
[github.com/golang/protobuf](https://github.com/golang/protobuf) by the
[COMPILE-PROTOS.sh](COMPILE-PROTOS.sh) script. This also builds all plugins
Expand Down
3 changes: 3 additions & 0 deletions generate-gnostic/generate-extension.go
Expand Up @@ -281,6 +281,9 @@ func generateExtension(schemaFile string, outDir string) error {
return err
}
err = exec.Command(runtime.GOROOT()+"/bin/gofmt", "-w", goFilename).Run()
if err != nil {
return err
}

// generate the main file.

Expand Down
6 changes: 6 additions & 0 deletions generate-gnostic/generate-extension_test.go
Expand Up @@ -16,6 +16,9 @@ func TestErrorExtensionGeneratorUnsupportedPrimitive(t *testing.T) {
"test/x-unsupportedprimitives.json",
"--out_dir=/tmp",
).Output()
if err != nil {
t.Fatalf("error executing generate-gnostic: %v", err)
}

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

outputFile := "x-extension-name-collision.errors"
_ = ioutil.WriteFile(outputFile, output, 0644)
Expand Down
20 changes: 8 additions & 12 deletions jsonwriter/writer.go
Expand Up @@ -18,19 +18,15 @@ import (
"bytes"
"errors"
"fmt"
"strings"
"strconv"

"gopkg.in/yaml.v3"
)

const indentation = " "

// basic escaping, will need to be improved or replaced
func escape(s string) string {
s = strings.Replace(s, "\n", "\\n", -1)
s = strings.Replace(s, "\"", "\\\"", -1)
return s
}
const (
indentation = " "
null = "null"
)

type writer struct {
b bytes.Buffer
Expand Down Expand Up @@ -85,15 +81,15 @@ func (w *writer) writeScalar(node *yaml.Node, indent string) {
}
switch node.Tag {
case "!!str":
w.writeString("\"")
w.writeString(escape(node.Value))
w.writeString("\"")
w.writeString(strconv.Quote(node.Value))
case "!!int":
w.writeString(node.Value)
case "!!float":
w.writeString(node.Value)
case "!!bool":
w.writeString(node.Value)
case "!!null":
w.writeString(null)
}
}

Expand Down
18 changes: 18 additions & 0 deletions jsonwriter/writer_test.go
Expand Up @@ -37,6 +37,8 @@ func TestMarshal(t *testing.T) {
scalarBoolTestCase(),
scalarFloatTestCase(),
scalarIntTestCase(),
scalarStringTestCase(),
scalarNullTestCase(),
sequenceStringArrayTestCase(),
sequenceBoolArrayTestCase(),
sequenceFloatArrayTestCase(),
Expand Down Expand Up @@ -88,6 +90,22 @@ func scalarFloatTestCase() *MarshalTestCase {
}
}

func scalarStringTestCase() *MarshalTestCase {
return &MarshalTestCase{
Name: "scalar string",
Node: compiler.NewScalarNodeForString("a\\b\nc\""),
Expected: "\"a\\\\b\\nc\\\"\"\n",
}
}

func scalarNullTestCase() *MarshalTestCase {
return &MarshalTestCase{
Name: "scalar null",
Node: compiler.NewNullNode(),
Expected: "null\n",
}
}

func scalarIntTestCase() *MarshalTestCase {
return &MarshalTestCase{
Name: "scalar int",
Expand Down
3 changes: 2 additions & 1 deletion metrics/vocabulary/vocabulary.go
Expand Up @@ -43,10 +43,11 @@ func WriteCSV(v *metrics.Vocabulary, filename string) error {
filename = "vocabulary-operation.csv"
}
f4, ferror := os.Create(filename)
defer f4.Close()
if ferror != nil {
return ferror
}
defer f4.Close()

for _, s := range v.Schemas {
temp := fmt.Sprintf("%s,\"%s\",%d\n", "schemas", s.Word, int(s.Count))
f4.WriteString(temp)
Expand Down
8 changes: 4 additions & 4 deletions openapiv3/README.md
Expand Up @@ -7,13 +7,13 @@ Gnostic applications and plugins can use OpenAPIv3.proto to generate Protocol
Buffer support code for their preferred languages.

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

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

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

Expand Down
3 changes: 3 additions & 0 deletions plugins/gnostic-analyze/summarize/main.go
Expand Up @@ -32,6 +32,9 @@ var stats []statistics.DocumentStatistics

// walker is called for each summary file found.
func walker(p string, info os.FileInfo, err error) error {
if err != nil {
return err
}
basename := path.Base(p)
if basename != "summary.json" {
return nil
Expand Down

0 comments on commit 7ed1b36

Please sign in to comment.