Skip to content

Commit

Permalink
Update gnostic to use yaml.v3 (#194)
Browse files Browse the repository at this point in the history
* small steps toward yaml.v3 conversion

* Read and write json schemas with yaml.v3

* rewrite helpers to yaml.v3 (project fails to compile)

* major rework, compiles and passes some tests

* passing most of the core tests

* ugly-passing all unit tests

(requires hand-editing the generated main.go files for extensions, to-fix next)

* cleaner passing of unit tests, all generated files are propertly generated now.

* many type assertions eliminated

* minor renaming

* Update company name.

* regenerate OpenAPIv2.go to remove experimental code (accidentally added)

* fix openapiv3.proto to maintain Info field order, go mod tidy, regen go.sum

* Add new ParseDocument() functions to directly read OpenAPI v2 and v3 docs from bytes.
  • Loading branch information
timburks authored Jul 14, 2020
1 parent 9cb6370 commit 40cf3c0
Show file tree
Hide file tree
Showing 83 changed files with 4,615 additions and 3,923 deletions.
2 changes: 1 addition & 1 deletion COMPILE-PROTOS.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2016 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/disco/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google Inc. All Rights Reserved.
// Copyright 2019 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/petstore-builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func testBuilder(version string, t *testing.T) {
// Verify that the generated text matches our reference.
err = exec.Command("diff", textFile, textReference).Run()
if err != nil {
t.Logf("Diff failed: %+v", err)
t.Logf("Diff %s vs %s failed: %+v", textFile, textReference, err)
t.FailNow()
}

Expand Down
2 changes: 1 addition & 1 deletion apps/petstore-builder/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/petstore-builder/petstore-v2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/petstore-builder/petstore-v3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/report-messages/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google Inc. All Rights Reserved.
// Copyright 2018 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.
Expand Down
2 changes: 1 addition & 1 deletion apps/report/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand Down
14 changes: 6 additions & 8 deletions compiler/extension-handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc. All Rights Reserved.
// Copyright 2017 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.
Expand All @@ -16,26 +16,25 @@ package compiler

import (
"bytes"
"errors"
"fmt"
"os/exec"

"strings"

"errors"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"
ext_plugin "github.com/googleapis/gnostic/extensions"
yaml "gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v3"
)

// ExtensionHandler describes a binary that is called by the compiler to handle specification extensions.
type ExtensionHandler struct {
Name string
}

// HandleExtension calls a binary extension handler.
func HandleExtension(context *Context, in interface{}, extensionName string) (bool, *any.Any, error) {
// CallExtension calls a binary extension handler.
func CallExtension(context *Context, in *yaml.Node, extensionName string) (bool, *any.Any, error) {
handled := false
var errFromPlugin error
var outFromPlugin *any.Any
Expand All @@ -54,7 +53,7 @@ func HandleExtension(context *Context, in interface{}, extensionName string) (bo
return handled, outFromPlugin, errFromPlugin
}

func (extensionHandlers *ExtensionHandler) handle(in interface{}, extensionName string) (*any.Any, error) {
func (extensionHandlers *ExtensionHandler) handle(in *yaml.Node, extensionName string) (*any.Any, error) {
if extensionHandlers.Name != "" {
binary, _ := yaml.Marshal(in)

Expand All @@ -76,7 +75,6 @@ func (extensionHandlers *ExtensionHandler) handle(in interface{}, extensionName
cmd := exec.Command(extensionHandlers.Name)
cmd.Stdin = bytes.NewReader(requestBytes)
output, err := cmd.Output()

if err != nil {
fmt.Printf("Error: %+v\n", err)
return nil, err
Expand Down
Loading

0 comments on commit 40cf3c0

Please sign in to comment.