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

aip-133: request-parent-required fires for a top-level resource #599

Closed
gajones155 opened this issue Aug 21, 2020 · 5 comments
Closed

aip-133: request-parent-required fires for a top-level resource #599

gajones155 opened this issue Aug 21, 2020 · 5 comments
Assignees

Comments

@gajones155
Copy link

gajones155 commented Aug 21, 2020

I see the error https://linter.aip.dev/133/request-parent-required for a top-level resource. https://google.aip.dev/133 states "A parent field must be included unless the resource being created is a top-level resource."

Is this a bug with the linter, or is there some way I should I be tagging my top level resources? To reproduce the error create a file file.proto with the following content:

syntax = "proto3";

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";

// Service to manage Books.
service BookService {
  // Creates a new book.
  rpc CreateBook(CreateBookRequest) returns (Book) {
    option (google.api.http) = {
      post: "/v1/books"
      body: "book"
    };
    option (google.api.method_signature) = "book";
  }
}

// Request for BookService.CreateBook.
message CreateBookRequest {
  // The book to create.
  Book book = 2 [(google.api.field_behavior) = REQUIRED];
}

// Book.
message Book {
  option (google.api.resource) = {
    type: "foo.com/Book"
    pattern: "books/{book}"
  };

  // Resource name of the book.
  string name = 1;
}

and run the api-linter to see the following problems:

$ api-linter file.proto
- file_path: file.proto
  problems:
  - message: The method signature for Create methods should be "parent,book".
    suggestion: option (google.api.method_signature) = "parent,book";
    location:
      start_position:
        line_number: 16
        column_number: 5
      end_position:
        line_number: 16
        column_number: 50
    rule_id: core::0133::method-signature
    rule_doc_uri: https://linter.aip.dev/133/method-signature
  - message: Create methods should include the `parent` field in the URI.
    location:
      start_position:
        line_number: 11
        column_number: 3
      end_position:
        line_number: 17
        column_number: 3
    rule_id: core::0133::http-uri-parent
    rule_doc_uri: https://linter.aip.dev/133/http-uri-parent
  - message: Message "CreateBookRequest" has no `parent` field
    location:
      start_position:
        line_number: 21
        column_number: 1
      end_position:
        line_number: 24
        column_number: 1
    rule_id: core::0133::request-parent-required
    rule_doc_uri: https://linter.aip.dev/133/request-parent-required
@lukesneeringer
Copy link
Contributor

This is a linter bug, yeah.

@lukesneeringer
Copy link
Contributor

Actually, we have code for this and a test for this. Are you using a current version?

Closing now, but feel free to reopen if appropriate.

@gajones155
Copy link
Author

I'm using /google/bin/releases/api-linter/api-linter. Is there a way to tell which version I'm running?

@lukesneeringer
Copy link
Contributor

What does --version say? (If it does not work, that means it is very old and we need to update that...)

@gajones155
Copy link
Author

$ /google/bin/releases/api-linter/api-linter --version
unknown flag: --version
Usage of api-linter...

lukesneeringer pushed a commit that referenced this issue Sep 2, 2020
Also, I rewrote the tests for these rules from scratch, as they
were in a weird state.

Fixes #599.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants