-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: Migrate to new bufbuild/protovalidate (#2)
Signed-off-by: Oğuzhan Durgun <[email protected]>
- Loading branch information
1 parent
82a199c
commit 1600c74
Showing
28 changed files
with
328 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# protoc-gen-jsonschema | ||
|
||
`protoc-gen-jsonschema` generates json schema from | ||
[bufbuild/protovalidate](https://github.com/bufbuild/protovalidate) validation rules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2021-2023 Zenauth Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
pgs "github.com/lyft/protoc-gen-star/v2" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/types/pluginpb" | ||
|
||
"github.com/cerbos/protoc-gen-jsonschema/internal/module" | ||
) | ||
|
||
const ( | ||
debugEnv = "PGC_DEBUG" | ||
requestPath = "internal/test/code_generator_request.pb.bin" | ||
) | ||
|
||
func main() { | ||
if _, exists := os.LookupEnv(debugEnv); exists { | ||
if err := printRequest(requestPath); err != nil { | ||
log.Fatalf("failed to print request: %s", err.Error()) | ||
} | ||
} | ||
|
||
reqFile, err := os.Open(requestPath) | ||
if err != nil { | ||
log.Fatalf("failed to open code generator request file: %s", err.Error()) | ||
} | ||
|
||
resBytes := &bytes.Buffer{} | ||
pgs.Init( | ||
pgs.DebugEnv(debugEnv), | ||
pgs.ProtocInput(reqFile), | ||
pgs.ProtocOutput(resBytes), | ||
).RegisterModule(module.New()).Render() | ||
|
||
res := &pluginpb.CodeGeneratorResponse{} | ||
if err := proto.Unmarshal(resBytes.Bytes(), res); err != nil { | ||
log.Fatalf("failed to unmarshal code generator response: %s", err.Error()) | ||
} | ||
|
||
for _, f := range res.File { | ||
log.Printf("%s\n", *f.Name) | ||
log.Printf("\n%s", *f.Content) | ||
log.Printf("--------------------------------------\n") | ||
} | ||
} | ||
|
||
func printRequest(path string) error { | ||
f, err := os.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("failed to open code generator request file: %w", err) | ||
} | ||
|
||
reqBytes, err := io.ReadAll(f) | ||
if err != nil { | ||
return fmt.Errorf("failed to read code generator request bytes: %w", err) | ||
} | ||
|
||
req := &pluginpb.CodeGeneratorRequest{} | ||
if err := proto.Unmarshal(reqBytes, req); err != nil { | ||
return fmt.Errorf("failed to unmarshal code generator response: %w", err) | ||
} | ||
|
||
log.Printf("%s", protojson.Format(req)) | ||
log.Printf("--------------------------------------\n") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.