syntax = "proto3";

package pait.api;
import "google/protobuf/descriptor.proto";

message ApiRule {

  oneof http_method {
    // Maps to HTTP GET. Used for listing and getting information about
    // resources.
    HttpMethod get = 2;

    // Maps to HTTP PUT. Used for replacing a resource.
    HttpMethod put = 3;

    // Maps to HTTP POST. Used for creating a resource or performing an action.
    HttpMethod post = 4;

    // Maps to HTTP DELETE. Used for deleting a resource.
    HttpMethod delete = 5;

    // Maps to HTTP PATCH. Used for updating a resource.
    HttpMethod patch = 6;

    // The custom pattern is used for specifying an HTTP method that is not
    // included in the `pattern` field, such as HEAD, or "*" to leave the
    // HTTP method unspecified for this rule. The wild-card rule is useful
    // for services that provide content to Web (HTML) clients.
    CustomHttpPattern custom = 8;

    // Automatically generated by gRPC Gateway
    HttpMethod any = 9;
  }

  // The name of the request field whose value is mapped to the HTTP request
  // body, or `*` for mapping all request fields not captured by the path
  // pattern to the HTTP body, or omitted for not having any HTTP request body.
  //
  // NOTE: the referred field must be present at the top-level of the request
  // message type.
  string body = 7;

  // Optional. The name of the response field whose value is mapped to the HTTP
  // response body. When omitted, the entire response message will be used
  // as the HTTP response body.
  //
  // NOTE: The referred field must be present at the top-level of the response
  // message type.
  string response_body = 12;

  // Additional HTTP bindings for the selector. Nested bindings must
  // not contain an `additional_bindings` field themselves (that is,
  // the nesting may only be one level deep).
  repeated ApiRule additional_bindings = 11;

  // the group to which the method belongs
  string group = 21;
  // The tag corresponding to this method and the description of the tag
  repeated Tag tag = 22;
  // a summary of the method
  string summary = 23;
  // documentation for the use of this method
  string desc = 24;
  // whether to map the method
  bool not_enable= 25;
}

// A custom pattern is used for defining custom HTTP verb.
message CustomHttpPattern {
  // The name of this custom HTTP verb.
  HttpMethod kind = 1;

  // The path matched by this custom verb.
  HttpMethod path = 2;
}

message Tag {
  string name = 1;
  string  desc = 2;
}

message HttpMethod {
  oneof http_url {
    // The specified http url, if empty, it will be generated by gRPC Gateway
    // example: /api/user/create
    //          /api/user/delete
    string url = 1;
    // If the value is True, the url is the url corresponding to the rpc method
    bool default = 2;
  }
}

extend google.protobuf.MethodOptions {
  // design like google.api.http
  ApiRule http = 72295729;
}
