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

Better Support for 2 dimensional arrays #956

Closed
amitbansal012 opened this issue Sep 9, 2015 · 3 comments
Closed

Better Support for 2 dimensional arrays #956

amitbansal012 opened this issue Sep 9, 2015 · 3 comments
Labels
Milestone

Comments

@amitbansal012
Copy link

Hi team,
I am using io.springfox:springfox-swagger2:2.1.1 jar to generate swagger specs. I am having issues with 2D arrays and nested maps.

The generated swagger spec looks like:

{
    "basePath": "/",
    "definitions": {
        "Map«string,string»": {
            "additionalProperties": {
                "type": "string"
            },
            "type": "object"
        }
    },
    "host": "hostname:port",
    "info": {
        "contact": {
            "name": "springfox"
        },
        "description": "This is a Sample service just to see how springfox works",
        "license": {
            "name": "Apache License Version 2.0",
            "url": "https://github.com/springfox/springfox/blob/master/LICENSE"
        },
        "termsOfService": "http://springfox.io",
        "title": "MySampleService :) ",
        "version": "2.0"
    },
    "paths": {
        "/service/testService/getInnerMap": {
            "get": {
                "consumes": [
                    "application/json"
                ],
                "operationId": "getInnerMapUsingGET",
                "produces": [
                    "*/*"
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "additionalProperties": {
                                "$ref": "#/definitions/Map«string,string»"
                            },
                            "type": "object"
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                },
                "summary": "This is test service",
                "tags": [
                    "test"
                ]
            }
        },
        "/service/testService/getPrimitiveDouble3": {
            "get": {
                "consumes": [
                    "application/json"
                ],
                "operationId": "getPrimitiveDouble3UsingGET",
                "produces": [
                    "*/*"
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "items": {
                                "$ref": "#/definitions/Array"
                            },
                            "type": "array"
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                },
                "summary": "This is test service - getPrimitiveDouble3",
                "tags": [
                    "test"
                ]
            }
        }
    },
    "swagger": "2.0",
    "tags": [
        {
            "name": "test",
            "description": "Operations in test service"
        }
    ]
}

Issue with 2D arrays

My java method looks like :
Interface:
int[][] getPrimitiveDouble3();

Impl:

@Override
@ApiOperation(value = "This is test service - getPrimitiveDouble3")
@RequestMapping(value = "/getPrimitiveDouble3", method = GET)
@ResponseBody
public int[][] getPrimitiveDouble3() {
return null;
}

I confirmed with Swagger team, looks like this is not the correct spec for 2D arrays [https://github.com/swagger-api/swagger-codegen/issues/1202]. Please let me know if this a bug.

Generated Spec [Incorrect]

 "schema": {
              "type": "array",
              "items": {
                  "$ref": "#/definitions/Array"
                }
              }

Expected Spec [Correct]

  "schema": {
              "type": "array",
              "items": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/Pet"
                }
              }
          }

Issue with nested maps

My java method looks like :
Interface:
Map<String, Map<String, String>> getInnerMap();

Impl:

    @Override 
    @ApiOperation(value = "This is test service")
    @RequestMapping(value = "/getInnerMap", method = GET)
    @ResponseBody
    public Map<String, Map<String, String>> getInnerMap() {
          return null;
    }

I confirmed with Swagger team, looks like this is not the correct spec for nested maps. Please let me know if this a bug.

Thanks,
Amit Bansal

@dilipkrish
Copy link
Member

Thanks for reporting this is definitely a bug

@amitbansal012
Copy link
Author

Hi Dilip,
Thank you for responding. Can you please let me know if the bug is with both 2D arrays and nested Maps?

Thanks,
Amit Bansal

@dilipkrish dilipkrish modified the milestones: 2.4.0, 2.3.0 Oct 23, 2015
@dilipkrish dilipkrish changed the title Swagger Spec Generation Using Springfox-Swagger Better Support for 2 dimensional arrays Dec 28, 2015
@dilipkrish
Copy link
Member

@amitbansal012 Not sure what the issue is with Maps. It appears to work fine in 2.3.0. The nested arrays is definitely not supported.

dilipkrish added a commit that referenced this issue Jan 2, 2016
dilipkrish added a commit that referenced this issue Jan 2, 2016
Also rearranged methods to put public methods on top

related to #956
@dilipkrish dilipkrish modified the milestones: 2.4.0, 2.3.1 Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants