Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a prototype for generating jsonschema files #112

Merged
merged 10 commits into from
Jul 31, 2023
6 changes: 6 additions & 0 deletions Dockerfile.jsonschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 3.18.2
FROM alpine@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70
RUN apk add --update protoc protobuf-dev go git
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
RUN go install github.com/chrusty/protoc-gen-jsonschema/cmd/[email protected]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if dependabot will suggest updates for Go dependencies in Dockerfiles? Otherwise we might want to add a hack like https://github.com/sigstore/rekor/blob/main/hack/tools/go.mod

# This is required to get the field_behavior.proto file
RUN git clone https://github.com/googleapis/googleapis.git
14 changes: 14 additions & 0 deletions Makefile
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

PROTOC_IMAGE=protobuf-specs-build
JSONSCHEMA_IMAGE=jsonschema-specs-build

# generate all language protobuf code
all: go python typescript ruby rust
Expand Down Expand Up @@ -58,6 +59,14 @@ rust: docker-image
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd gen/pb-rust/codegen && cargo run && rm -rf target/"

jsonschema: docker-image-jsonschema
@echo "Generating JSON schema files"
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
--entrypoint sh \
${JSONSCHEMA_IMAGE} \
-c "cd defs/gen/jsonschema && ./jsonschema.sh -I ../../protos -I /googleapis/ --jsonschema_out=schemas ../../protos/*.proto"

# docker already does its own caching so we can attempt a build every time
.PHONY: docker-image
Expand All @@ -73,6 +82,11 @@ docker-image-no-cache:
@echo "Building development docker image with disabled cache"
docker build --no-cache -t ${PROTOC_IMAGE} .

.PHONY: docker-image-jsonschema
docker-image-jsonschema:
@echo "Building docker image for generating JSON schema files"
docker build -t ${JSONSCHEMA_IMAGE} -f Dockerfile.jsonschema .

# clean up generated files (not working? try sudo make clean)
clean:
rm -rf gen/pb-go \
Expand Down
10 changes: 10 additions & 0 deletions gen/jsonschema/jsonschema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -u
set -e

protoc --plugin=/root/go/bin/protoc-gen-jsonschema \
--jsonschema_opt=enforce_oneof \
--jsonschema_opt=file_extension=schema.json \
--jsonschema_opt=disallow_additional_properties \
"$@"
35 changes: 35 additions & 0 deletions gen/jsonschema/schemas/Artifact.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/Artifact",
"definitions": {
"Artifact": {
"properties": {
"artifact_uri": {
"type": "string",
"description": "Location of the artifact"
},
"artifact": {
"type": "string",
"description": "The raw bytes of the artifact",
"format": "binary",
"binaryEncoding": "base64"
}
},
"additionalProperties": false,
"type": "object",
"oneOf": [
{
"required": [
"artifact_uri"
]
},
{
"required": [
"artifact"
]
}
],
"title": "Artifact"
}
}
}
Loading