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

Support map types #140

Closed
kyleconroy opened this issue May 2, 2016 · 4 comments
Closed

Support map types #140

kyleconroy opened this issue May 2, 2016 · 4 comments

Comments

@kyleconroy
Copy link

The following proto file results in a swagger definition file that's incorrect.

syntax = "proto3";

package rpx;

import "google/api/annotations.proto";

service Foo {
  // Sends a greeting
  rpc Bar (BarRequest) returns (BarResponse) {
    option (google.api.http) = {
      post: "/bar"
      body: "*"
    };
  }
}

message BarRequest {
  map<string, string> labels = 3;
}

message BarResponse {
}

Maps should be represented as objects, not as arrays of objects with the key and value properties.

{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/bar": {
      "post": {
        "summary": "Foo.Bar",
        "operationId": "Bar",
        "responses": {
          "default": {
            "description": "Description",
            "schema": {
              "$ref": "#/definitions/rpxBarResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/rpxBarRequest"
            }
          }
        ],
        "tags": [
          "Foo"
        ]
      }
    }
  },
  "definitions": {
    "BarRequestLabelsEntry": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string",
          "format": "string"
        },
        "value": {
          "type": "string",
          "format": "string"
        }
      }
    },
    "rpxBarRequest": {
      "type": "object",
      "properties": {
        "labels": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/BarRequestLabelsEntry"
          }
        }
      }
    },
    "rpxBarResponse": {
      "type": "object"
    }
  }
}
@achew22
Copy link
Collaborator

achew22 commented May 2, 2016

Just as background, Maps represented as lists of key value pairs are a holdover from the days of proto2. The whole ecosystem is in a bit of a transitional phase right now.

I believe this is a dupe of #79. The current JSON encoder (if my memory serves me correctly) is doing things in the style of proto2. Changing the JSON encoder is kind of hard to do but I would welcome you to jump into the conversation on that other thread.

@t-yuki
Copy link
Contributor

t-yuki commented May 2, 2016

FYI, I've prototyped swagger support for map recently.
Should I make a pull request?
master...t-yuki:feature/map

@kyleconroy
Copy link
Author

@achew22 I don't think it's a dupe of #79. The proto3 JSON mapping says that maps should be encoded as objects, not arrays. More important, the generated swagger document is incorrect. The gateway that's generated from this proto file will not accept the labels property as an array of hashes: it requires an object.

@t-yuki Please do!

@achew22
Copy link
Collaborator

achew22 commented Jan 4, 2017

Looks like a PR that fixes this was merged. I'm going to close the issue now. If this isn't fixed feel free to reopen it or file another issue.

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

3 participants