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

Array $ref is ignored and instead uses a not-repeated type #125

Open
JustinDFuller opened this issue Jan 17, 2020 · 0 comments
Open

Array $ref is ignored and instead uses a not-repeated type #125

JustinDFuller opened this issue Jan 17, 2020 · 0 comments

Comments

@JustinDFuller
Copy link

I am using a $ref to an array type in my swagger. It's not generating a repeated type. It only generates the repeated type if I inline the array $ref.

Here's an example.

swagger: "2.0"
info:
  description: "Problem With Arrays Example"
  version: "1.0.0"
  title: "Array Response"
host: "localhost:3000"
basePath: "/v1"
schemes:
- "https"
- "http"
paths:
  /cats:
    get:
      summary: "Get All Cats"
      produces:
      - "application/json"
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              cats:
                $ref: "#/definitions/Cats"
definitions:
  Cat:
    type: object
    properties:
      name:
        type: string
      color:
        type: string
  Cats:
    type: array
    items:
      $ref: "#/definitions/Cat"                  

Here is the output. Note that cats in GetCatsResponse is not repeated.

syntax = "proto3";

package arrayresponse;

import "google/protobuf/empty.proto";

message Cat {
    string color = 1;
    string name = 2;
}

message GetCatsResponse {
    Cat cats = 1; // Notice that cats is not repeated - but it should be
}

service ArrayResponseService {
    // Get All Cats
    rpc GetCats(google.protobuf.Empty) returns (GetCatsResponse) {}
}

If I make a small adjustment to the api.yaml by inlining the array $ref, like this:

swagger: "2.0"
info:
  description: "Problem With Arrays Example"
  version: "1.0.0"
  title: "Array Response"
host: "localhost:3000"
basePath: "/v1"
schemes:
- "https"
- "http"
paths:
  /cats:
    get:
      summary: "Get All Cats"
      produces:
      - "application/json"
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              cats:
                type: array
                items:
                  $ref: "#/definitions/Cat"    
definitions:
  Cat:
    type: object
    properties:
      name:
        type: string
      color:
        type: string

Now, cats is repeated in GetCatsResponse.

syntax = "proto3";

package arrayresponse;

import "google/protobuf/empty.proto";

message Cat {
    string color = 1;
    string name = 2;
}

message GetCatsResponse {
    repeated Cat cats = 1; // cats is now repeated
}

service ArrayResponseService {
    // Get All Cats
    rpc GetCats(google.protobuf.Empty) returns (GetCatsResponse) {}
}

Why is this happening? Swagger is interpreting it correctly in swagger UI. It seems like the $ref should produce the repeated type, just like the inline version.

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

1 participant