Skip to content

Commit

Permalink
feat: multiple nesting, deduped collection names
Browse files Browse the repository at this point in the history
The AEPs allow deduplicating collection names (for example, 
removing the "book" from "book-editions" in the path). Since
this is a fairly common practice, make it something that aepc
will do for you by default.

Also fixing a few places where multiple nested children was not working,
as well as additional issues that came from a hyphen in the resource singular.

Also started building out an internal/ package - eventually most packages
will move there, as aepc is a first and foremost a command-line interface
and intended to be used as a binary.

A utils library was added to do basic casing, as it is common to 
do so.
  • Loading branch information
toumorokoshi committed Oct 23, 2024
1 parent 87d0bfa commit 1d1bcb6
Show file tree
Hide file tree
Showing 16 changed files with 2,810 additions and 977 deletions.
1,413 changes: 971 additions & 442 deletions example/bookstore/v1/bookstore.pb.go

Large diffs are not rendered by default.

884 changes: 674 additions & 210 deletions example/bookstore/v1/bookstore.pb.gw.go

Large diffs are not rendered by default.

186 changes: 144 additions & 42 deletions example/bookstore/v1/bookstore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option go_package = "/bookstore";
// A service.
service Bookstore {
// An aep-compliant Create method for book.
rpc Createbook ( CreatebookRequest ) returns ( book ) {
rpc CreateBook ( CreateBookRequest ) returns ( Book ) {
option (google.api.http) = {
post: "/{parent=publishers/*}/books",
body: "book"
Expand All @@ -29,14 +29,14 @@ service Bookstore {
}

// An aep-compliant Get method for book.
rpc Getbook ( GetbookRequest ) returns ( book ) {
rpc GetBook ( GetBookRequest ) returns ( Book ) {
option (google.api.http) = { get: "/{path=publishers/*/books/*}" };

option (google.api.method_signature) = "path";
}

// An aep-compliant Update method for book.
rpc Updatebook ( UpdatebookRequest ) returns ( book ) {
rpc UpdateBook ( UpdateBookRequest ) returns ( Book ) {
option (google.api.http) = {
patch: "/{path=publishers/*/books/*}",
body: "book"
Expand All @@ -46,29 +46,62 @@ service Bookstore {
}

// An aep-compliant Delete method for book.
rpc Deletebook ( DeletebookRequest ) returns ( google.protobuf.Empty ) {
rpc DeleteBook ( DeleteBookRequest ) returns ( google.protobuf.Empty ) {
option (google.api.http) = { delete: "/{path=publishers/*/books/*}" };

option (google.api.method_signature) = "path";
}

// An aep-compliant List method for books.
rpc Listbook ( ListbookRequest ) returns ( ListbookResponse ) {
rpc ListBooks ( ListBooksRequest ) returns ( ListBooksResponse ) {
option (google.api.http) = { get: "/{parent=publishers/*}/books" };

option (google.api.method_signature) = "parent";
}

// An aep-compliant Apply method for books.
rpc Applybook ( ApplybookRequest ) returns ( book ) {
rpc ApplyBook ( ApplyBookRequest ) returns ( Book ) {
option (google.api.http) = {
put: "/{path=publishers/*/books/*}",
body: "book"
};
}

// An aep-compliant Create method for book-edition.
rpc CreateBookEdition ( CreateBookEditionRequest ) returns ( BookEdition ) {
option (google.api.http) = {
post: "/{parent=publishers/*/books/*}/editions",
body: "book_edition"
};

option (google.api.method_signature) = "parent,book_edition";
}

// An aep-compliant Get method for book-edition.
rpc GetBookEdition ( GetBookEditionRequest ) returns ( BookEdition ) {
option (google.api.http) = { get: "/{path=publishers/*/books/*/editions/*}" };

option (google.api.method_signature) = "path";
}

// An aep-compliant Delete method for book-edition.
rpc DeleteBookEdition ( DeleteBookEditionRequest ) returns ( google.protobuf.Empty ) {
option (google.api.http) = {
delete: "/{path=publishers/*/books/*/editions/*}"
};

option (google.api.method_signature) = "path";
}

// An aep-compliant List method for book-editions.
rpc ListBookEditions ( ListBookEditionsRequest ) returns ( ListBookEditionsResponse ) {
option (google.api.http) = { get: "/{parent=publishers/*/books/*}/editions" };

option (google.api.method_signature) = "parent";
}

// An aep-compliant Create method for publisher.
rpc Createpublisher ( CreatepublisherRequest ) returns ( publisher ) {
rpc CreatePublisher ( CreatePublisherRequest ) returns ( Publisher ) {
option (google.api.http) = {
post: "/{parent=publishers}",
body: "publisher"
Expand All @@ -78,14 +111,14 @@ service Bookstore {
}

// An aep-compliant Get method for publisher.
rpc Getpublisher ( GetpublisherRequest ) returns ( publisher ) {
rpc GetPublisher ( GetPublisherRequest ) returns ( Publisher ) {
option (google.api.http) = { get: "/{path=publishers/*}" };

option (google.api.method_signature) = "path";
}

// An aep-compliant Update method for publisher.
rpc Updatepublisher ( UpdatepublisherRequest ) returns ( publisher ) {
rpc UpdatePublisher ( UpdatePublisherRequest ) returns ( Publisher ) {
option (google.api.http) = {
patch: "/{path=publishers/*}",
body: "publisher"
Expand All @@ -95,27 +128,27 @@ service Bookstore {
}

// An aep-compliant Delete method for publisher.
rpc Deletepublisher ( DeletepublisherRequest ) returns ( google.protobuf.Empty ) {
rpc DeletePublisher ( DeletePublisherRequest ) returns ( google.protobuf.Empty ) {
option (google.api.http) = { delete: "/{path=publishers/*}" };

option (google.api.method_signature) = "path";
}

// An aep-compliant List method for publishers.
rpc Listpublisher ( ListpublisherRequest ) returns ( ListpublisherResponse ) {
rpc ListPublishers ( ListPublishersRequest ) returns ( ListPublishersResponse ) {
option (google.api.http) = { get: "/{parent=publishers}" };

option (google.api.method_signature) = "parent";
}

// An aep-compliant Apply method for publishers.
rpc Applypublisher ( ApplypublisherRequest ) returns ( publisher ) {
rpc ApplyPublisher ( ApplyPublisherRequest ) returns ( Publisher ) {
option (google.api.http) = { put: "/{path=publishers/*}", body: "publisher" };
}
}

// A book.
message book {
// A Book.
message Book {
// A Author.
message Author {
// Field for firstName.
Expand Down Expand Up @@ -148,7 +181,7 @@ message book {
}

// A Create request for a book resource.
message CreatebookRequest {
message CreateBookRequest {
// A field for the parent of book
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -159,35 +192,35 @@ message CreatebookRequest {
string id = 10014;

// The resource to perform the operation on.
book book = 10015 [(google.api.field_behavior) = REQUIRED];
Book book = 10015 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the Getbook method
message GetbookRequest {
message GetBookRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/book" }
];
}

// Request message for the Updatebook method
message UpdatebookRequest {
// Request message for the UpdateBook method
message UpdateBookRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/book" }
];

// The resource to perform the operation on.
book book = 10015 [(google.api.field_behavior) = REQUIRED];
Book book = 10015 [(google.api.field_behavior) = REQUIRED];

// The update mask for the resource
google.protobuf.FieldMask update_mask = 10012;
}

// Request message for the Deletebook method
message DeletebookRequest {
// Request message for the DeleteBook method
message DeleteBookRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -196,7 +229,7 @@ message DeletebookRequest {
}

// Request message for the Listbook method
message ListbookRequest {
message ListBooksRequest {
// A field for the parent of book
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -211,28 +244,97 @@ message ListbookRequest {
}

// Response message for the Listbook method
message ListbookResponse {
message ListBooksResponse {
// A list of books
repeated book results = 10016;
repeated Book results = 10016;

// The page token indicating the ending point of this response.
string next_page_token = 10011;
}

// Request message for the Applybook method
message ApplybookRequest {
message ApplyBookRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/book" }
];

// The resource to perform the operation on.
book book = 10015 [(google.api.field_behavior) = REQUIRED];
Book book = 10015 [(google.api.field_behavior) = REQUIRED];
}

// A BookEdition.
message BookEdition {
// Field for name.
string name = 1 [(google.api.field_behavior) = REQUIRED];

// Field for path.
string path = 10000;

// Field for id.
string id = 10001;
}

// A Create request for a book-edition resource.
message CreateBookEditionRequest {
// A field for the parent of book-edition
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { }
];

// An id that uniquely identifies the resource within the collection
string id = 10014;

// The resource to perform the operation on.
BookEdition book_edition = 10015 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the Getbook-edition method
message GetBookEditionRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/book-edition" }
];
}

// Request message for the DeleteBookEdition method
message DeleteBookEditionRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/book-edition" }
];
}

// Request message for the Listbook-edition method
message ListBookEditionsRequest {
// A field for the parent of book-edition
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { }
];

// The page token indicating the starting point of the page
string page_token = 10010;

// The maximum number of resources to return in a single page.
int32 max_page_size = 10017;
}

// Response message for the Listbook-edition method
message ListBookEditionsResponse {
// A list of book-editions
repeated BookEdition results = 10016;

// The page token indicating the ending point of this response.
string next_page_token = 10011;
}

// A publisher.
message publisher {
// A Publisher.
message Publisher {
// Field for description.
string description = 1;

Expand All @@ -244,7 +346,7 @@ message publisher {
}

// A Create request for a publisher resource.
message CreatepublisherRequest {
message CreatePublisherRequest {
// A field for the parent of publisher
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -255,35 +357,35 @@ message CreatepublisherRequest {
string id = 10014;

// The resource to perform the operation on.
publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];
Publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the Getpublisher method
message GetpublisherRequest {
message GetPublisherRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/publisher" }
];
}

// Request message for the Updatepublisher method
message UpdatepublisherRequest {
// Request message for the UpdatePublisher method
message UpdatePublisherRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/publisher" }
];

// The resource to perform the operation on.
publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];
Publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];

// The update mask for the resource
google.protobuf.FieldMask update_mask = 10012;
}

// Request message for the Deletepublisher method
message DeletepublisherRequest {
// Request message for the DeletePublisher method
message DeletePublisherRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -292,7 +394,7 @@ message DeletepublisherRequest {
}

// Request message for the Listpublisher method
message ListpublisherRequest {
message ListPublishersRequest {
// A field for the parent of publisher
string parent = 10013 [
(google.api.field_behavior) = REQUIRED,
Expand All @@ -307,22 +409,22 @@ message ListpublisherRequest {
}

// Response message for the Listpublisher method
message ListpublisherResponse {
message ListPublishersResponse {
// A list of publishers
repeated publisher results = 10016;
repeated Publisher results = 10016;

// The page token indicating the ending point of this response.
string next_page_token = 10011;
}

// Request message for the Applypublisher method
message ApplypublisherRequest {
message ApplyPublisherRequest {
// The globally unique identifier for the resource
string path = 10018 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = { type: "bookstore.example.com/publisher" }
];

// The resource to perform the operation on.
publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];
Publisher publisher = 10015 [(google.api.field_behavior) = REQUIRED];
}
Loading

0 comments on commit 1d1bcb6

Please sign in to comment.