Skip to content

documentation isn't respected when generated definitions include nested entities #962

@hollabaq86

Description

@hollabaq86

(using grape-swagger v 2.1.2)

This is a real edge case scenario, so apologies in advance!

I have an Entity(Report) that exposes an array of objects(bar) generated using another Entity(Foo) as part of the API response. However, the contents of Foo can change depending on the object (polymorphism). For the sake of keeping our documentation simple, I'm trying to overwrite the properties for bar within the swagger schema definition of Report to a generic type like Array[Object] :

class Report < Grape::Entity
  expose :foo,
    as: :bar,
    using: Entities::Foo,
    documentation: {
      type: "Array[Object]",
      desc: "The bar in your report",
      example: {
        "id": "string",
        "type": "string",
        "status": "string"
      },
    }
end

class Foo < Grape::Entity
  expose :baz, documentation: { hidden: true }
end

However, when I try to create the swagger JSON file, I receive the following error:

"Empty model Entities_Foo, swagger 2.0 doesn't support empty definitions."

I think what's happening is the documentation options specified for bar are being overwritten or not respected because they're called within a Proc, and as a result I get the error because the Entity Foo doesn't have anything formally documented. But I could be widely off-base where this is happening, since we're working with multiple libraries (grape-swagger, grape-entity, maybe even grape-swagger-entity?) and I have no problem admitting my lack of knowledge in these libraries 😄

For now I'm not blocked because specifying hidden: true in documentation works, so I'm opting to just hide this one attribute in my response model's documentation. But I'd love to be able to display it- anyone have thoughts on potential workarounds? Or could this be a bug?

Thanks in advance! Appreciate everyone's work

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