From 5d9e2938927153968aa3d18d428ec74e07c468f0 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Sun, 15 Sep 2024 17:57:25 -0700 Subject: [PATCH] fix(lint): use buf plugins for lint and fixes for AEP compliance. Using buf plugins for linting is a more ergonomic approach, avoiding the need to manually clone googleapis. Fixes to reach AEP compliance: - removing apply method as it is not an official AEP at the moment. --- .github/workflows/test.yml | 9 +++-- buf.lock | 8 ++-- buf.yaml | 6 ++- example/bookstore/v1/bookstore.yaml | 2 +- schema/resourcedefinition.proto | 58 ++++++++++++++++++++++++++--- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1aa5c8..9491169 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,13 +21,14 @@ jobs: - name: "test: no change to generated files." run: | - go install github.com/bufbuild/buf/cmd/buf@v1.38.0 + go install github.com/bufbuild/buf/cmd/buf@v1.42.0 ./scripts/verify-goldens.sh - name: "test: example server function" run: | ./scripts/test_http_api.sh - # - name: Run script - # run: | - # ./scripts/run-api-linter.sh + - name: run api-linter + run: | + go install github.com/aep-dev/api-linter/cmd/buf-plugin-aep@latest + buf lint --path example/bookstore/v1/bookstore.proto diff --git a/buf.lock b/buf.lock index 6c4355d..c83a0ee 100644 --- a/buf.lock +++ b/buf.lock @@ -1,8 +1,6 @@ # Generated by buf. DO NOT EDIT. -version: v1 +version: v2 deps: - - remote: buf.build - owner: googleapis - repository: googleapis + - name: buf.build/googleapis/googleapis commit: 28151c0d0a1641bf938a7672c500e01d - digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de + digest: b5:93b70089baa4fc05a92d3e52db91a4b7812db3b57b9664f6cb301733938cb630e377a938e8a56779388171c749c1d42a2e9a6c6230f2ff45f127a8102a6a27d0 diff --git a/buf.yaml b/buf.yaml index 204dbaa..ea81f26 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,9 +1,11 @@ -version: v1 +version: v2 breaking: use: - FILE lint: use: - - DEFAULT + - AEP +plugins: + - plugin: buf-plugin-aep deps: - buf.build/googleapis/googleapis:28151c0d0a1641bf938a7672c500e01d diff --git a/example/bookstore/v1/bookstore.yaml b/example/bookstore/v1/bookstore.yaml index f9a36d8..8cd0a1a 100644 --- a/example/bookstore/v1/bookstore.yaml +++ b/example/bookstore/v1/bookstore.yaml @@ -29,7 +29,7 @@ resources: update: {} delete: {} list: {} - apply: {} +# apply: {} # do not uncomment until there is an AEP on apply. # - kind: "Publisher" # plural: "publishers" # methods: diff --git a/schema/resourcedefinition.proto b/schema/resourcedefinition.proto index c02d1b2..02b0300 100644 --- a/schema/resourcedefinition.proto +++ b/schema/resourcedefinition.proto @@ -1,20 +1,24 @@ // resourcedefinition contains the // schema of the resource definition. -// regenerate with -// -// protoc ./aepc/schema/resourcedefinition.proto --go_opt paths=source_relative\ +// regenerate with: +// protoc ./aepc/schema/resourcedefinition.proto --go_opt paths=source_relative\ // --go_out=. syntax = "proto3"; option go_package = "/schema"; +// An API service. message Service { + // The name of the API service. string name = 1; + + // The resources that the API service exposes. repeated Resource resources = 2; // These are additional objects (list of properties) that may be referenced from another property. repeated Object objects = 3; } +// A resource. message Resource { // The type of the resource. Used to programmatically // refer to and identify the resource. @@ -23,32 +27,51 @@ message Resource { string plural = 2; // The list of parent resources, referred to via the kind. repeated string parents = 3; - // Properties + // Properties of the resource. Also often referred to as it's schema. map properties = 4; - // method support + // methods support by the resource. Methods methods = 5; } +// An object is a collection of properties, that does not have methods of it's +// on in the API. It is currently only used as a property of a resource. message Object { + // The name of the object. string kind = 1; + // The properties of the object. map properties = 2; } +// Methods supported by a resource. message Methods { + // The properties of the create method. message CreateMethod {} + // The properties of the read method. message ReadMethod {} + // The properties of the update method. message UpdateMethod {} + // The properties of the delete method. message DeleteMethod {} + // The properties of the list method. message ListMethod {} + // THe properties of the global list method. message GlobalListMethod {} + // THe properties of the apply method. message ApplyMethod {} + // Specific properties of the create method for the resource. CreateMethod create = 1; + // Specific properties of the read method for the resource. ReadMethod read = 2; + // Specific properties of the update method for the resource. UpdateMethod update = 3; + // Specific properties of the delete emethod for the resource. DeleteMethod delete = 4; + // Specific properties of the list for the resource. ListMethod list = 5; + // Specific properties of the global_list for the resource. GlobalListMethod global_list = 6; + // Specific properties of the apply for the resource. ApplyMethod apply = 7; } @@ -62,6 +85,7 @@ enum Type { BOOLEAN = 6; } +// A property represents a field in a resource or object. message Property { oneof types { Type type = 1; @@ -71,7 +95,9 @@ message Property { // field number used for protobuf or other systems where fields must // be explicitly enumerated. int32 number = 2; + // true if the property is read only. bool readOnly = 3; + // true if the property is required. bool required = 4; } @@ -87,3 +113,25 @@ message ArrayType { ObjectType object_type = 2; } } + +// The pritimive types supported by the schema. +enum Type { + // The type is unspecified. + TYPE_UNSPECIFIED = 0; + // The type is a string. + STRING = 1; + // The type is an int32. + INT32 = 2; + // The type is an int64. + INT64 = 3; + // The type is a double. + DOUBLE = 4; + // The type is a float. + FLOAT = 5; + // The type is a boolean. + BOOLEAN = 6; + // The type is an object. + OBJECT = 7; + // The type is an array. + ARRAY = 8; +} \ No newline at end of file