@@ -29,7 +29,8 @@ These screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) s
29
29
30
30
## Model Parsers
31
31
32
- Since 0.21.0, ` Grape::Entity ` is not a part of grape-swagger, you need to add ` grape-swagger-entity ` manually to your Gemfile:
32
+ Since 0.21.0, ` Grape::Entity ` is not a part of grape-swagger, you need to add ` grape-swagger-entity ` manually to your Gemfile.
33
+ Also added support for [ representable] ( https://github.com/apotonick/representable ) via ` grape-swagger-representable ` .
33
34
34
35
``` ruby
35
36
# For Grape::Entity ( https://github.com/ruby-grape/grape-entity )
@@ -38,6 +39,60 @@ gem 'grape-swagger-entity'
38
39
gem ' grape-swagger-representable'
39
40
```
40
41
42
+ ##### Custom model parser interface
43
+
44
+ You can create yuor own model parser, for example for [ roar] ( https://github.com/apotonick/roar )
45
+
46
+ ``` rb
47
+ module GrapeSwagger
48
+ module Roar
49
+ class Parser
50
+ attr_reader :model
51
+ attr_reader :endpoint
52
+
53
+ def initialize (model , endpoint )
54
+ @model = model
55
+ @endpoint = endpoint
56
+ end
57
+
58
+ def call
59
+ # Parse your model and return hash with model schema for swagger
60
+ end
61
+ end
62
+ end
63
+ end
64
+ ```
65
+
66
+ Then you should register your custom parser:
67
+
68
+ ``` rb
69
+ GrapeSwagger .model_parsers.register(GrapeSwagger ::Roar ::Parser , Roar ::Decorator )
70
+ ```
71
+
72
+ To controll model parsers sequence, you can insert your Parser before or after another parser
73
+
74
+ before:
75
+
76
+ ``` rb
77
+ if defined? (GrapeSwagger ::Representable ::Parser )
78
+ GrapeSwagger .model_parsers.insert_before(GrapeSwagger ::Representable ::Parser , GrapeSwagger ::Roar ::Parser , Roar ::Decorator )
79
+ else
80
+ GrapeSwagger .model_parsers.register(GrapeSwagger ::Roar ::Parser , Roar ::Decorator )
81
+ end
82
+ ```
83
+
84
+ after:
85
+
86
+ ``` rb
87
+ if defined? (GrapeSwagger ::Roar ::Parser )
88
+ GrapeSwagger .model_parsers.insert_after(GrapeSwagger ::Roar ::Parser , GrapeSwagger ::Representable ::Parser , Representable ::Decorator )
89
+ else
90
+ GrapeSwagger .model_parsers.register(GrapeSwagger ::Representable ::Parser , Representable ::Decorator )
91
+ end
92
+ ```
93
+
94
+ As we know, ` Roar::Decorator ` uses as superclass ` Representable::Decorator ` , this allow to avoid problem when Roar objects will be processed by ` GrapeSwagger::Representable::Parser ` , instead ` GrapeSwagger::Roar::Parser `
95
+
41
96
<a name =" related " />
42
97
## Related Projects
43
98
@@ -53,13 +108,13 @@ gem 'grape-swagger-representable'
53
108
54
109
The following versions of grape, grape-entity and grape-swagger can currently be used together.
55
110
56
- grape-swagger | swagger spec | grape | grape-entity
57
- --------------|--------------|-------------------------|-------------
58
- 0.10.5 | 1.2 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0
59
- 0.11.0 | 1.2 | >= 0.16.2 | < 0.5.0
60
- 0.20.1 | 2.0 | >= 0.12.0 ... <= 0.14.0 | <= 0.5.1
61
- 0.20.3 | 2.0 | >= 0.12.0 ... ~ > 0.16.2 | ~ > 0.5.1
62
- 0.21.0 (next) | 2.0 | >= 0.12.0 ... <= 0.16.2 | <= 0.5.1
111
+ grape-swagger | swagger spec | grape | grape-entity | rerpresentable |
112
+ --------------|--------------|-------------------------|--------------------------------
113
+ 0.10.5 | 1.2 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0 | Unsupported
114
+ 0.11.0 | 1.2 | >= 0.16.2 | < 0.5.0 | Unsupported
115
+ 0.20.1 | 2.0 | >= 0.12.0 ... <= 0.14.0 | <= 0.5.1 | Unsupported
116
+ 0.20.3 | 2.0 | >= 0.12.0 ... ~ > 0.16.2 | ~ > 0.5.1 | Unsupported
117
+ 0.21.0 (next) | 2.0 | >= 0.12.0 ... <= 0.16.2 | <= 0.5.1 | >= 2.4.1
63
118
64
119
<a name =" swagger-spec " />
65
120
## Swagger-Spec
0 commit comments