jsonapi-swagger 0.8.1 → 0.9.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/lib/generators/jsonapi/swagger/swagger_generator.rb +4 -4
- data/lib/generators/jsonapi/swagger/templates/swagger.json.erb +21 -21
- data/lib/generators/jsonapi/swagger/templates/swagger.rb.erb +20 -20
- data/lib/jsonapi/swagger/resource.rb +19 -16
- data/lib/jsonapi/swagger/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca788a5cb82d20869ddb1d61bc35f7f70a96a087d5f5063710b5c9e7d903aff7
|
|
4
|
+
data.tar.gz: e02238b6ed49ce8b7402853bfb234571580e35a2f5a46eef351272cbe403a618
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7a7e2e7ac26bf503e9b9a9119f4739585b5a8a4475f8ee3638e7d94c1177991c4ba0836e6d8f02a825ad9ae7f53cf60691e19cd2feaa525dee3c65e72084b84
|
|
7
|
+
data.tar.gz: 1d887fc8de0108a6e6b6bcaff773bb16219bdfabc9a51c7a4aade3324b8982468ee796bd6972acdad3d0b9c10f06c005140627314663b37cb1970f910e9ee947
|
|
@@ -61,12 +61,12 @@ module Jsonapi
|
|
|
61
61
|
file_name.downcase.singularize
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def
|
|
64
|
+
def resources_name
|
|
65
65
|
model_class_name.pluralize
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
def
|
|
69
|
-
|
|
68
|
+
def route_resources
|
|
69
|
+
resources_name.tableize
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def model_class_name
|
|
@@ -82,7 +82,7 @@ module Jsonapi
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def model_klass
|
|
85
|
-
|
|
85
|
+
model_class_name.safe_constantize
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def resource_klass
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
filters.each do |filter_attr, filter_config|
|
|
17
17
|
parameters << { name: :"filter[#{filter_attr}]", in: :query, type: :string, description: tt(:filter_field), required: false}
|
|
18
18
|
end
|
|
19
|
-
parameters << { name: :"fields[#{
|
|
19
|
+
parameters << { name: :"fields[#{route_resources}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
|
20
20
|
relationships.each_value do |relation|
|
|
21
21
|
parameters << { name: :"fields[#{relation_table_name(relation)}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
|
22
22
|
end
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
if relationships.present?
|
|
30
30
|
parameters << { name: :include, in: :query, type: :string, description: tt(:include_related_data), required: false }
|
|
31
31
|
end
|
|
32
|
-
parameters << { name: :"fields[#{
|
|
32
|
+
parameters << { name: :"fields[#{route_resources}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
|
33
33
|
relationships.each_value do |relation|
|
|
34
34
|
parameters << { name: :"fields[#{relation_table_name(relation)}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
|
35
35
|
end
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
data: {
|
|
46
46
|
type: :object,
|
|
47
47
|
properties: {
|
|
48
|
-
type: { type: :string, default:
|
|
48
|
+
type: { type: :string, default: route_resources },
|
|
49
49
|
attributes: {
|
|
50
50
|
type: :object,
|
|
51
51
|
properties: properties(attrs: creatable_fields)
|
|
@@ -257,20 +257,20 @@
|
|
|
257
257
|
}
|
|
258
258
|
end
|
|
259
259
|
|
|
260
|
-
doc['paths']["/#{
|
|
260
|
+
doc['paths']["/#{route_resources}"] = {
|
|
261
261
|
get: {
|
|
262
|
-
summary: "#{
|
|
263
|
-
tags: [
|
|
262
|
+
summary: "#{route_resources} #{tt(:list)}",
|
|
263
|
+
tags: [route_resources],
|
|
264
264
|
produces: ['application/vnd.api+json'],
|
|
265
265
|
parameters: list_resource_parameters,
|
|
266
266
|
responses: list_resource_responses
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
doc['paths']["/#{
|
|
270
|
+
doc['paths']["/#{route_resources}/{id}"] = {
|
|
271
271
|
get: {
|
|
272
|
-
summary: "#{
|
|
273
|
-
tags: [
|
|
272
|
+
summary: "#{route_resources} #{tt(:detail)}",
|
|
273
|
+
tags: [route_resources],
|
|
274
274
|
produces: ['application/vnd.api+json'],
|
|
275
275
|
parameters: show_resource_parameters,
|
|
276
276
|
responses: show_resource_responses
|
|
@@ -278,10 +278,10 @@
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
if mutable?
|
|
281
|
-
doc['paths']["/#{
|
|
281
|
+
doc['paths']["/#{route_resources}"].merge!({
|
|
282
282
|
post: {
|
|
283
|
-
summary: "#{
|
|
284
|
-
tags: [
|
|
283
|
+
summary: "#{route_resources} #{tt(:create)}",
|
|
284
|
+
tags: [route_resources],
|
|
285
285
|
consumes: ['application/vnd.api+json'],
|
|
286
286
|
produces: ['application/vnd.api+json'],
|
|
287
287
|
parameters: [create_resource_parameters],
|
|
@@ -289,10 +289,10 @@ if mutable?
|
|
|
289
289
|
}
|
|
290
290
|
})
|
|
291
291
|
|
|
292
|
-
doc['paths']["/#{
|
|
292
|
+
doc['paths']["/#{route_resources}/{id}"].merge!({
|
|
293
293
|
patch: {
|
|
294
|
-
summary: "#{
|
|
295
|
-
tags: [
|
|
294
|
+
summary: "#{route_resources} #{tt(:patch)}",
|
|
295
|
+
tags: [route_resources],
|
|
296
296
|
consumes: ['application/vnd.api+json'],
|
|
297
297
|
produces: ['application/vnd.api+json'],
|
|
298
298
|
parameters: patch_resource_parameters,
|
|
@@ -300,19 +300,19 @@ if mutable?
|
|
|
300
300
|
}
|
|
301
301
|
})
|
|
302
302
|
|
|
303
|
-
doc['paths']["/#{
|
|
303
|
+
doc['paths']["/#{route_resources}/{id}"].merge!({
|
|
304
304
|
delete: {
|
|
305
|
-
summary: "#{
|
|
306
|
-
tags: [
|
|
305
|
+
summary: "#{route_resources} #{tt(:delete)}",
|
|
306
|
+
tags: [route_resources],
|
|
307
307
|
produces: ['application/vnd.api+json'],
|
|
308
308
|
parameters: delete_resource_parameters,
|
|
309
309
|
responses: delete_resource_responses
|
|
310
310
|
}
|
|
311
311
|
})
|
|
312
312
|
else
|
|
313
|
-
doc['paths']["/#{
|
|
314
|
-
doc['paths']["/#{
|
|
315
|
-
doc['paths']["/#{
|
|
313
|
+
doc['paths']["/#{route_resources}"].delete(:post)
|
|
314
|
+
doc['paths']["/#{route_resources}/{id}"].delete(:patch)
|
|
315
|
+
doc['paths']["/#{route_resources}/{id}"].delete(:delete)
|
|
316
316
|
end
|
|
317
317
|
-%>
|
|
318
318
|
"paths": <%= JSON.pretty_generate(doc['paths'] ) %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'swagger_helper'
|
|
2
|
-
RSpec.describe '<%=
|
|
2
|
+
RSpec.describe '<%= resources_name %>', type: :request do
|
|
3
3
|
let(:include) {''} #see https://github.com/domaindrivendev/rswag/issues/188
|
|
4
4
|
|
|
5
5
|
before(:each) do
|
|
@@ -10,9 +10,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
10
10
|
<% end -%>
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
path '/<%=
|
|
14
|
-
get '<%=
|
|
15
|
-
tags '<%=
|
|
13
|
+
path '/<%= route_resources %>' do
|
|
14
|
+
get '<%= route_resources %> <%= t(:list) %>' do
|
|
15
|
+
tags '<%= route_resources %>'
|
|
16
16
|
produces 'application/vnd.api+json'
|
|
17
17
|
parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false
|
|
18
18
|
<% if sortable_fields.present? -%>
|
|
@@ -24,7 +24,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
24
24
|
<% filters.each do |filter_attr, filter_config| -%>
|
|
25
25
|
parameter name: :'filter[<%= filter_attr %>]', in: :query, type: :string, description: '<%= t(:filter_field) %>', <% if filter_config[:default] -%>default: '<%= safe_encode(filter_config[:default]) %>',<% end %>required: false
|
|
26
26
|
<% end -%>
|
|
27
|
-
parameter name: :'fields[<%=
|
|
27
|
+
parameter name: :'fields[<%= route_resources %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
|
28
28
|
<% relationships.each_value do |relation| -%>
|
|
29
29
|
parameter name: :'fields[<%= relation_table_name(relation) %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
|
30
30
|
<% end -%>
|
|
@@ -103,15 +103,15 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
path '/<%=
|
|
107
|
-
get '<%=
|
|
108
|
-
tags '<%=
|
|
106
|
+
path '/<%= route_resources %>/{id}' do
|
|
107
|
+
get '<%= route_resources %> <%= t(:detail) %>' do
|
|
108
|
+
tags '<%= route_resources %>'
|
|
109
109
|
produces 'application/vnd.api+json'
|
|
110
110
|
parameter name: :id, in: :path, type: :integer, description: 'ID', required: true
|
|
111
111
|
<% if relationships.present? -%>
|
|
112
112
|
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
|
|
113
113
|
<% end -%>
|
|
114
|
-
parameter name: :'fields[<%=
|
|
114
|
+
parameter name: :'fields[<%= route_resources %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
|
115
115
|
<% relationships.each_value do |relation| -%>
|
|
116
116
|
parameter name: :'fields[<%= relation_table_name(relation) %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
|
117
117
|
<% end -%>
|
|
@@ -174,9 +174,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
<% if mutable? -%>
|
|
177
|
-
path '/<%=
|
|
178
|
-
post '<%=
|
|
179
|
-
tags '<%=
|
|
177
|
+
path '/<%= route_resources %>' do
|
|
178
|
+
post '<%= route_resources %> <%= t(:create) %>' do
|
|
179
|
+
tags '<%= route_resources %>'
|
|
180
180
|
consumes 'application/vnd.api+json'
|
|
181
181
|
produces 'application/vnd.api+json'
|
|
182
182
|
parameter name: :data,
|
|
@@ -186,7 +186,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
186
186
|
data: {
|
|
187
187
|
type: :object,
|
|
188
188
|
properties: {
|
|
189
|
-
type: { type: :string, default: '<%=
|
|
189
|
+
type: { type: :string, default: '<%= route_resources %>' },
|
|
190
190
|
attributes: {
|
|
191
191
|
type: :object,
|
|
192
192
|
properties: {
|
|
@@ -295,9 +295,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
|
295
295
|
end
|
|
296
296
|
end
|
|
297
297
|
|
|
298
|
-
path '/<%=
|
|
299
|
-
patch '<%=
|
|
300
|
-
tags '<%=
|
|
298
|
+
path '/<%= route_resources %>/{id}' do
|
|
299
|
+
patch '<%= route_resources %> <%= t(:patch) %>' do
|
|
300
|
+
tags '<%= route_resources %>'
|
|
301
301
|
consumes 'application/vnd.api+json'
|
|
302
302
|
produces 'application/vnd.api+json'
|
|
303
303
|
parameter name: :id, in: :path, type: :integer, description: 'ID', required: true
|
|
@@ -308,7 +308,7 @@ path '/<%= route_resouces %>/{id}' do
|
|
|
308
308
|
data: {
|
|
309
309
|
type: :object,
|
|
310
310
|
properties: {
|
|
311
|
-
type: { type: :string, default: '<%=
|
|
311
|
+
type: { type: :string, default: '<%= route_resources %>' },
|
|
312
312
|
id: { type: :string },
|
|
313
313
|
attributes: {
|
|
314
314
|
type: :object,
|
|
@@ -419,9 +419,9 @@ path '/<%= route_resouces %>/{id}' do
|
|
|
419
419
|
end
|
|
420
420
|
end
|
|
421
421
|
|
|
422
|
-
path '/<%=
|
|
423
|
-
delete '<%=
|
|
424
|
-
tags '<%=
|
|
422
|
+
path '/<%= route_resources %>/{id}' do
|
|
423
|
+
delete '<%= route_resources %> <%= t(:delete) %>' do
|
|
424
|
+
tags '<%= route_resources %>'
|
|
425
425
|
produces 'application/vnd.api+json'
|
|
426
426
|
parameter name: :id, in: :path, type: :integer, description: 'ID', required: true
|
|
427
427
|
|
|
@@ -3,31 +3,34 @@ module Jsonapi
|
|
|
3
3
|
module Swagger
|
|
4
4
|
class Resource
|
|
5
5
|
def self.with(model_class_name)
|
|
6
|
-
if
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Resource!"
|
|
6
|
+
if (resource_class = "#{model_class_name}Resource".safe_constantize)
|
|
7
|
+
unless resource_class < JSONAPI::Resource
|
|
8
|
+
raise Jsonapi::Swagger::Error, "#{resource_class} is not Subclass of JSONAPI::Resource!"
|
|
10
9
|
end
|
|
11
10
|
require 'jsonapi/swagger/resources/jsonapi_resource'
|
|
12
|
-
return Jsonapi::Swagger::JsonapiResource.new(
|
|
13
|
-
elsif
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Serializable::Resource!"
|
|
11
|
+
return Jsonapi::Swagger::JsonapiResource.new(resource_class)
|
|
12
|
+
elsif (resource_class = serializable_class_name(model_class_name).safe_constantize)
|
|
13
|
+
unless resource_class < JSONAPI::Serializable::Resource
|
|
14
|
+
raise Jsonapi::Swagger::Error, "#{resource_class} is not Subclass of JSONAPI::Serializable::Resource!"
|
|
17
15
|
end
|
|
18
16
|
require 'jsonapi/swagger/resources/serializable_resource'
|
|
19
|
-
return Jsonapi::Swagger::SerializableResource.new(
|
|
20
|
-
elsif
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of FastJsonapi::ObjectSerializer!"
|
|
17
|
+
return Jsonapi::Swagger::SerializableResource.new(resource_class)
|
|
18
|
+
elsif (resource_class = "#{model_class_name}Serializer".safe_constantize)
|
|
19
|
+
unless resource_class < FastJsonapi::ObjectSerializer
|
|
20
|
+
raise Jsonapi::Swagger::Error, "#{resource_class} is not Subclass of FastJsonapi::ObjectSerializer!"
|
|
24
21
|
end
|
|
25
22
|
require 'jsonapi/swagger/resources/fast_jsonapi_resource'
|
|
26
|
-
return Jsonapi::Swagger::FastJsonapiResource.new(
|
|
23
|
+
return Jsonapi::Swagger::FastJsonapiResource.new(resource_class)
|
|
27
24
|
else
|
|
28
25
|
raise Jsonapi::Swagger::Error, "#{model_class_name} not support!"
|
|
29
26
|
end
|
|
30
27
|
end
|
|
28
|
+
|
|
29
|
+
def self.serializable_class_name(model_class_name)
|
|
30
|
+
parts = model_class_name.split('::')
|
|
31
|
+
parts[-1] = "Serializable#{parts[-1]}"
|
|
32
|
+
parts.join('::')
|
|
33
|
+
end
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
|
-
end
|
|
36
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonapi-swagger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- YingRui Lu
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -66,7 +65,6 @@ dependencies:
|
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '2.0'
|
|
69
|
-
description:
|
|
70
68
|
email:
|
|
71
69
|
- yingruilu518@gmail.com
|
|
72
70
|
executables: []
|
|
@@ -92,7 +90,6 @@ homepage: https://github.com/superiorlu/jsonapi-swagger
|
|
|
92
90
|
licenses:
|
|
93
91
|
- MIT
|
|
94
92
|
metadata: {}
|
|
95
|
-
post_install_message:
|
|
96
93
|
rdoc_options: []
|
|
97
94
|
require_paths:
|
|
98
95
|
- lib
|
|
@@ -107,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
104
|
- !ruby/object:Gem::Version
|
|
108
105
|
version: '0'
|
|
109
106
|
requirements: []
|
|
110
|
-
rubygems_version: 3.
|
|
111
|
-
signing_key:
|
|
107
|
+
rubygems_version: 3.6.9
|
|
112
108
|
specification_version: 4
|
|
113
109
|
summary: JSON API Swagger Doc Generator
|
|
114
110
|
test_files: []
|