Skip to content

Commit 78f395f

Browse files
committed
Documentation update [ci-skip]
1 parent fa6a62a commit 78f395f

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ These screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) s
2929

3030
## Model Parsers
3131

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`.
3334

3435
```ruby
3536
# For Grape::Entity ( https://github.com/ruby-grape/grape-entity )
@@ -38,6 +39,60 @@ gem 'grape-swagger-entity'
3839
gem 'grape-swagger-representable'
3940
```
4041

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+
4196
<a name="related" />
4297
## Related Projects
4398

@@ -53,13 +108,13 @@ gem 'grape-swagger-representable'
53108

54109
The following versions of grape, grape-entity and grape-swagger can currently be used together.
55110

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 | representable |
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 |
63118

64119
<a name="swagger-spec" />
65120
## Swagger-Spec

0 commit comments

Comments
 (0)