|
4 | 4 | before :all do
|
5 | 5 | module MyAPI
|
6 | 6 | module Entities
|
7 |
| - class BaseEntity < Grape::Entity |
8 |
| - def self.entity_name |
9 |
| - name.sub(/^MyAPI::Entities::/, '') |
10 |
| - end |
| 7 | + class Kind < Grape::Entity |
| 8 | + expose :title, documentation: { type: 'string', desc: 'Title of the kind.' } |
11 | 9 | end
|
12 | 10 |
|
13 |
| - class Something < BaseEntity |
| 11 | + class Something < Grape::Entity |
14 | 12 | expose :text, documentation: { type: 'string', desc: 'Content of something.' }
|
| 13 | + expose :kind, using: Kind, documentation: { type: 'MyAPI::Kind', desc: 'The kind of this something.' } |
15 | 14 | end
|
16 | 15 |
|
17 |
| - class Error < BaseEntity |
| 16 | + class Error < Grape::Entity |
18 | 17 | expose :code, documentation: { type: 'string', desc: 'Error code' }
|
19 | 18 | expose :message, documentation: { type: 'string', desc: 'Error message' }
|
20 | 19 | end
|
@@ -59,22 +58,40 @@ def app
|
59 | 58 | {
|
60 | 59 | 'code' => 200,
|
61 | 60 | 'message' => 'OK',
|
62 |
| - 'responseModel' => 'Something' |
| 61 | + 'responseModel' => 'MyAPI::Something' |
63 | 62 | },
|
64 | 63 | {
|
65 | 64 | 'code' => 403,
|
66 | 65 | 'message' => 'Refused to return something',
|
67 |
| - 'responseModel' => 'Error' |
| 66 | + 'responseModel' => 'MyAPI::Error' |
68 | 67 | }
|
69 | 68 | ]
|
70 | 69 | )
|
71 |
| - expect(subject['models'].keys).to include 'Error' |
72 |
| - expect(subject['models']['Error']).to eq( |
73 |
| - 'id' => 'Error', |
| 70 | + |
| 71 | + expect(subject['models'].keys).to include 'MyAPI::Error' |
| 72 | + expect(subject['models']['MyAPI::Error']).to eq( |
| 73 | + 'id' => 'MyAPI::Error', |
74 | 74 | 'properties' => {
|
75 | 75 | 'code' => { 'type' => 'string', 'description' => 'Error code' },
|
76 | 76 | 'message' => { 'type' => 'string', 'description' => 'Error message' }
|
77 | 77 | }
|
78 | 78 | )
|
| 79 | + |
| 80 | + expect(subject['models'].keys).to include 'MyAPI::Something' |
| 81 | + expect(subject['models']['MyAPI::Something']).to eq( |
| 82 | + 'id' => 'MyAPI::Something', |
| 83 | + 'properties' => { |
| 84 | + 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, |
| 85 | + 'kind' => { '$ref' => 'MyAPI::Kind', 'description' => 'The kind of this something.' } |
| 86 | + } |
| 87 | + ) |
| 88 | + |
| 89 | + expect(subject['models'].keys).to include 'MyAPI::Kind' |
| 90 | + expect(subject['models']['MyAPI::Kind']).to eq( |
| 91 | + 'id' => 'MyAPI::Kind', |
| 92 | + 'properties' => { |
| 93 | + 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' } |
| 94 | + } |
| 95 | + ) |
79 | 96 | end
|
80 | 97 | end
|
0 commit comments