Skip to content

Example value feature is broken in swagger ui for body parameters #507

Closed
@serggl

Description

@serggl

In particular it is broken for parameters which data type is Grape::Entity

Here is a maple API and entities definition:

class Rest::Sales::Root < Grape::API
  prefix :sales

  version 'v1', using: :path

  module Entities
    class A < Grape::Entity
      expose :a, documentation: {type: 'string'}
      expose :b, documentation: {type: 'number'}
    end
  end

  desc 'Create a new something' do
    success Entities::A
  end

  params do
    optional :data, type: Entities::A
  end

  post 'something' do
    {}
  end

  add_swagger_documentation hide_documentation_path: true, add_version: true, models: [Entities::A]
end

And here is how it looks like in swagger:

2016-09-29 16 24 10

2016-09-29 16 25 00

One the last screenshot you can also notice that data type names are quite different, but they should represent the same type.

Here is a swagger json generated for this API class:

{
    "info": {
        "title": "API title",
        "version": "0.0.1"
    },
    "swagger": "2.0",
    "produces": [
        "application/json"
    ],
    "host": "localhost:3000",
    "basePath": "/api",
    "tags": [
        {
            "name": "something",
            "description": "Operations about somethings"
        }
    ],
    "paths": {
        "/sales/v1/something": {
            "post": {
                "summary": "Create a new something",
                "description": "Create a new something",
                "produces": [
                    "application/json"
                ],
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "SalesV1Something",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/postSalesV1Something"
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Create a new something",
                        "schema": {
                            "$ref": "#/definitions/A"
                        }
                    }
                },
                "tags": [
                    "something"
                ],
                "operationId": "postSalesV1Something"
            }
        }
    },
    "definitions": {
        "postSalesV1Something": {
            "type": "object",
            "properties": {
                "data": {
                    "type": "Rest::Sales::Root::A"
                }
            },
            "description": "Create a new something"
        },
        "A": {
            "type": "object",
            "properties": {
                "a": {
                    "type": "string"
                },
                "b": {
                    "type": "number"
                }
            },
            "description": "Create a new something"
        }
    }
}

Seems like a proper data type link should be "$ref": "#/definitions/A" instead of "type": "Rest::Sales::Root::A"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions