| 
75 | 75 |     - [Adding root element to responses ](#adding-root-element-to-responses-)  | 
76 | 76 |     - [Multiple present Response ](#multiple-present-response-)  | 
77 | 77 | - [Using Grape Entities ](#using-grape-entities-)  | 
 | 78 | +  - [Documented class/definition](#documented-classdefinition)  | 
78 | 79 |   - [Relationships](#relationships)  | 
79 | 80 |     - [1xN](#1xn)  | 
80 | 81 |     - [1x1](#1x1)  | 
@@ -1515,7 +1516,6 @@ The result will look like following:  | 
1515 | 1516 | Add the [grape-entity](https://github.com/ruby-grape/grape-entity) and [grape-swagger-entity](https://github.com/ruby-grape/grape-swagger-entity) gem to your Gemfile.  | 
1516 | 1517 | 
 
  | 
1517 | 1518 | The following example exposes statuses. And exposes statuses documentation adding :type, :desc and :required.  | 
1518 |  | -The documented class/definition name could be set via `#entity_name`.  | 
1519 | 1519 | 
 
  | 
1520 | 1520 | ```ruby  | 
1521 | 1521 | module API  | 
@@ -1558,6 +1558,57 @@ module API  | 
1558 | 1558 | end  | 
1559 | 1559 | ```  | 
1560 | 1560 | 
 
  | 
 | 1561 | +### Documented class/definition  | 
 | 1562 | + | 
 | 1563 | +You can set the name of the Entity when being documented via `#entity_name`:  | 
 | 1564 | + | 
 | 1565 | +```ruby  | 
 | 1566 | +module API  | 
 | 1567 | +  module Entities  | 
 | 1568 | +    class Status < Grape::Entity  | 
 | 1569 | +      expose :text, documentation: { type: 'string', desc: 'Status update text.', required: true }  | 
 | 1570 | +    end  | 
 | 1571 | + | 
 | 1572 | +    class Link < Grape::Entity  | 
 | 1573 | +      expose :href, documentation: { type: 'url' }  | 
 | 1574 | + | 
 | 1575 | +      def self.entity_name  | 
 | 1576 | +        'LinkedStatus'  | 
 | 1577 | +      end  | 
 | 1578 | + | 
 | 1579 | +    end  | 
 | 1580 | +  end  | 
 | 1581 | +end  | 
 | 1582 | +```  | 
 | 1583 | +Should generate the following definitions in your swagger json:  | 
 | 1584 | + | 
 | 1585 | +```json  | 
 | 1586 | +{  | 
 | 1587 | +  "definitions": {  | 
 | 1588 | +    "API_Entities_Status": {  | 
 | 1589 | +      "type": "object",  | 
 | 1590 | +      "properties": {  | 
 | 1591 | +        "text": {  | 
 | 1592 | +          "type": "string",  | 
 | 1593 | +          "description": "Status update text.",  | 
 | 1594 | +        },  | 
 | 1595 | +      },  | 
 | 1596 | +      "required": [  | 
 | 1597 | +        "text",  | 
 | 1598 | +      ],  | 
 | 1599 | +      "description": "API_Entities_Pet model"  | 
 | 1600 | +    },  | 
 | 1601 | +    "LinkedStatus": {  | 
 | 1602 | +      "type": "object",  | 
 | 1603 | +      "properties": {  | 
 | 1604 | +        "href": {  | 
 | 1605 | +          "type": "url",  | 
 | 1606 | +        },  | 
 | 1607 | +      "description": "LinkedStatus model"  | 
 | 1608 | +    }  | 
 | 1609 | +  }  | 
 | 1610 | +}  | 
 | 1611 | +```  | 
1561 | 1612 | 
 
  | 
1562 | 1613 | ### Relationships  | 
1563 | 1614 | 
 
  | 
 | 
0 commit comments