sober_swag 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +1 -4
- data/.github/workflows/ruby.yml +1 -5
- data/CHANGELOG.md +4 -0
- data/README.md +14 -0
- data/example/app/controllers/people_controller.rb +4 -0
- data/example/app/controllers/posts_controller.rb +5 -0
- data/lib/sober_swag/compiler/path.rb +7 -0
- data/lib/sober_swag/controller/route.rb +9 -0
- data/lib/sober_swag/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a0e2ee1acc571a7f6a90db87f4c15b6d7d820f24b75abd3f37cb369d431f271
|
4
|
+
data.tar.gz: 6384f275b7b1bd21ef35f4972b519be59a19d1a5e24a5c2138e203748a9702bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1d8b82b62dc05656482b0e550bc5edb24cdf76dde9dc9bcd4729381c5439983df7e98704eb9a0d54964f70297c8097b8192a016736db5ffff3126849d5425e9
|
7
|
+
data.tar.gz: f55485cc2dd04c4dd414b7c2b5668be91d1c8ada7ad51cf20d04bad62925054d27f940caf83c6c83e1763928c3ea5295d9c592b7a83f85e133cdfbaca697652c
|
data/.github/workflows/lint.yml
CHANGED
@@ -24,10 +24,7 @@ jobs:
|
|
24
24
|
steps:
|
25
25
|
- uses: actions/checkout@v2
|
26
26
|
- name: Set up Ruby
|
27
|
-
|
28
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
-
# uses: ruby/setup-ruby@v1
|
30
|
-
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
27
|
+
uses: ruby/setup-ruby@v1
|
31
28
|
with:
|
32
29
|
ruby-version: ${{ matrix.ruby }}
|
33
30
|
- uses: actions/cache@v2
|
data/.github/workflows/ruby.yml
CHANGED
@@ -20,14 +20,10 @@ jobs:
|
|
20
20
|
strategy:
|
21
21
|
matrix:
|
22
22
|
ruby: [ '2.6', '2.7' ]
|
23
|
-
|
24
23
|
steps:
|
25
24
|
- uses: actions/checkout@v2
|
26
25
|
- name: Set up Ruby
|
27
|
-
|
28
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
-
# uses: ruby/setup-ruby@v1
|
30
|
-
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
26
|
+
uses: ruby/setup-ruby@v1
|
31
27
|
with:
|
32
28
|
ruby-version: ${{ matrix.ruby }}
|
33
29
|
- uses: actions/cache@v2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -268,6 +268,20 @@ QueryInput = SoberSwag.input_object do
|
|
268
268
|
end
|
269
269
|
```
|
270
270
|
|
271
|
+
## Tags
|
272
|
+
|
273
|
+
If you want to organize your API into sections, you can use `tags`.
|
274
|
+
It's quite simple:
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
define :patch, :update, '/people/{id}' do
|
278
|
+
# other cool config
|
279
|
+
tags 'people', 'mutations', 'incurs_cost'
|
280
|
+
end
|
281
|
+
```
|
282
|
+
|
283
|
+
This will map to OpenAPI's `tags` field (naturally), and the UI codegen will automatically organize your endpoints by their tags.
|
284
|
+
|
271
285
|
## Testing the validity of output objects
|
272
286
|
|
273
287
|
If you're using RSpec and want to test the validity of output objects, you can do so relatively easily.
|
@@ -35,6 +35,7 @@ class PeopleController < ApplicationController
|
|
35
35
|
request_body(PersonParams)
|
36
36
|
response(:ok, 'the person created', PersonOutputObject)
|
37
37
|
response(:unprocessable_entity, 'the validation errors', PersonErrorsOutputObject)
|
38
|
+
tags 'people', 'create'
|
38
39
|
end
|
39
40
|
def create
|
40
41
|
p = Person.new(parsed_body.person.to_h)
|
@@ -50,6 +51,7 @@ class PeopleController < ApplicationController
|
|
50
51
|
path_params { attribute :id, Types::Params::Integer }
|
51
52
|
response(:ok, 'the person updated', PersonOutputObject)
|
52
53
|
response(:unprocessable_entity, 'the validation errors', PersonErrorsOutputObject)
|
54
|
+
tags 'people', 'update'
|
53
55
|
end
|
54
56
|
def update
|
55
57
|
if @person.update(parsed_body.person.to_h)
|
@@ -68,6 +70,7 @@ class PeopleController < ApplicationController
|
|
68
70
|
attribute :view, Types::String.default('base'.freeze).enum('base', 'detail')
|
69
71
|
end
|
70
72
|
response(:ok, 'all the people', PersonOutputObject.array)
|
73
|
+
tags 'people', 'list'
|
71
74
|
end
|
72
75
|
def index
|
73
76
|
@people = Person.all
|
@@ -81,6 +84,7 @@ class PeopleController < ApplicationController
|
|
81
84
|
attribute :id, Types::Params::Integer
|
82
85
|
end
|
83
86
|
response(:ok, 'the person requested', PersonOutputObject)
|
87
|
+
tags 'people', 'show'
|
84
88
|
end
|
85
89
|
def show
|
86
90
|
respond!(:ok, @person)
|
@@ -47,6 +47,7 @@ class PostsController < ApplicationController
|
|
47
47
|
MARKDOWN
|
48
48
|
end
|
49
49
|
response(:ok, 'all the posts', PostOutputObject.array)
|
50
|
+
tags 'posts', 'list'
|
50
51
|
end
|
51
52
|
def index
|
52
53
|
@posts = Post.all
|
@@ -60,6 +61,7 @@ class PostsController < ApplicationController
|
|
60
61
|
path_params(ShowPath)
|
61
62
|
query_params { attribute? :view, ViewTypes }
|
62
63
|
response(:ok, 'the requested post', PostOutputObject)
|
64
|
+
tags 'posts', 'show'
|
63
65
|
end
|
64
66
|
def show
|
65
67
|
respond!(:ok, @post, serializer_opts: { view: parsed_query.view })
|
@@ -68,6 +70,7 @@ class PostsController < ApplicationController
|
|
68
70
|
define :post, :create, '/posts/' do
|
69
71
|
request_body(PostCreate)
|
70
72
|
response(:created, 'the created post', PostOutputObject)
|
73
|
+
tags 'posts', 'create'
|
71
74
|
end
|
72
75
|
def create
|
73
76
|
@post = Post.new(parsed_body.post.to_h)
|
@@ -83,6 +86,7 @@ class PostsController < ApplicationController
|
|
83
86
|
path_params(ShowPath)
|
84
87
|
request_body(PostUpdate)
|
85
88
|
response(:ok, 'the post updated', PostOutputObject.view(:base))
|
89
|
+
tags 'posts', 'update'
|
86
90
|
end
|
87
91
|
def update
|
88
92
|
if @post.update(parsed_body.post.to_h)
|
@@ -95,6 +99,7 @@ class PostsController < ApplicationController
|
|
95
99
|
define :delete, :destroy, '/posts/{id}' do
|
96
100
|
path_params(ShowPath)
|
97
101
|
response(:ok, 'the post deleted', PostOutputObject.view(:base))
|
102
|
+
tags 'posts', 'delete'
|
98
103
|
end
|
99
104
|
def destroy
|
100
105
|
@post.destroy
|
@@ -21,6 +21,7 @@ module SoberSwag
|
|
21
21
|
base[:parameters] = params if params.any?
|
22
22
|
base[:responses] = responses
|
23
23
|
base[:requestBody] = request_body if request_body
|
24
|
+
base[:tags] = tags if tags
|
24
25
|
base
|
25
26
|
end
|
26
27
|
|
@@ -72,6 +73,12 @@ module SoberSwag
|
|
72
73
|
}
|
73
74
|
}
|
74
75
|
end
|
76
|
+
|
77
|
+
def tags
|
78
|
+
return nil unless route.tags.any?
|
79
|
+
|
80
|
+
route.tags
|
81
|
+
end
|
75
82
|
end
|
76
83
|
end
|
77
84
|
end
|
@@ -9,6 +9,7 @@ module SoberSwag
|
|
9
9
|
@action_name = action_name
|
10
10
|
@response_serializers = {}
|
11
11
|
@response_descriptions = {}
|
12
|
+
@tags = []
|
12
13
|
end
|
13
14
|
|
14
15
|
attr_reader :response_serializers, :response_descriptions, :controller, :method, :path, :action_name
|
@@ -23,6 +24,14 @@ module SoberSwag
|
|
23
24
|
# What to parse the path params into.
|
24
25
|
attr_reader :path_params_class
|
25
26
|
|
27
|
+
##
|
28
|
+
# Standard swagger tags.
|
29
|
+
def tags(*args)
|
30
|
+
return @tags if args.empty?
|
31
|
+
|
32
|
+
@tags = args.flatten
|
33
|
+
end
|
34
|
+
|
26
35
|
##
|
27
36
|
# Define the request body, using SoberSwag's type-definition scheme.
|
28
37
|
# The block passed will be used to define the body of a new sublcass of `base` (defaulted to {SoberSwag::InputObject}.)
|
data/lib/sober_swag/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sober_swag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Super
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|