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

Allow period in path URL templates when generating Swagger templates. #143

Merged
merged 1 commit into from
May 9, 2016

Conversation

ivucica
Copy link
Collaborator

@ivucica ivucica commented May 7, 2016

This allows for the templates to contain references to request proto
messages' fields.

Some test code that I played with seems to indicate that
gRPC-Gateway does support dots to reach values
inside values.

In my interpretation, RFC 6570 does not forbid this, but
does not seem to explain exactly what happens.

Swagger spec also does not seem to forbid it. (It's very
nonspecific about how templates are to be parsed,
generally.)

Example proto:

syntax = "proto3";

import "google/api/annotations.proto";

package toy;

service Toy3 {
  rpc Build (Toy3BuildRequest) returns (Toy3BuildReply) {
    option (google.api.http) = {
      post: "/toy3/v1/{what.shape}/{what.color}/{what.class}"
      body: "where"
    };
  }
}

message Toy3BuildRequest {
  Toy3BuildWhat what = 1;
  string where = 2;
}

message Toy3BuildWhat {
  string shape = 1;
  string color = 2;
  string class = 3;
}

message Toy3BuildReply {
  string construction_id = 1;
}

Broken output snippet:

    "/toy3/v1/{what}/{what}/{what}": {
      "post": {
        "summary": "Toy3.Build",
        "operationId": "Build",
        "responses": {
          "default": {
            "description": "Description",
            "schema": {
              "$ref": "#/definitions/toyToy3BuildReply"
            }
          }
        },
        "parameters": [
          {
            "name": "what.shape",
            "in": "path",
            "required": true,
            "type": "string",
            "format": "string"
          },
          {
            "name": "what.color",
            "in": "path",
            "required": true,
            "type": "string",
            "format": "string"
          },
          {
            "name": "what.class",
            "in": "path",
            "required": true,
            "type": "string",
            "format": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/toyToy3BuildRequest"
            }
          }
        ],
        "tags": [
          "Toy3"
        ]
      }
    }

Incidentally, this pull request would also update the examples to {be compatible with,use} a newer Go proto package.

@ivucica ivucica force-pushed the swagger_dot_in_path_template branch from a13c172 to cd17643 Compare May 7, 2016 21:26
This allows for the templates to contain references to request proto
messages' fields.
@ivucica ivucica force-pushed the swagger_dot_in_path_template branch from cd17643 to f720a41 Compare May 7, 2016 21:26
@yugui
Copy link
Member

yugui commented May 9, 2016

LGTM.

@yugui yugui merged commit f720a41 into grpc-ecosystem:master May 9, 2016
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

Successfully merging this pull request may close these issues.

2 participants