graphiti-openapi 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e72f28f72e39813ba6776fa40544279bbf842fed200b5be56678aa40495981d
4
- data.tar.gz: ebe5f2fd5206ad29590fec6b6336003e34b3433092a813f47d6caf7cd2c87b4a
3
+ metadata.gz: 2070008985f65464531c93f438aaa275db413c0d1daf0b933f6b86296063384a
4
+ data.tar.gz: 115f94a0a40844d56d46737be9e63880c81fe40e4273ec7df0aaeeceb0bbe4c4
5
5
  SHA512:
6
- metadata.gz: 706bbdd8b08e6983b576d806e0af2dd23058ba1cc0a90a56be5a4591cf6d341e86ebbd06e137e001aa1525e358b4770f78e3c96abf3e212f411127330f5815dc
7
- data.tar.gz: 4ba0e5eb35b63240bc917f1cd0984787d20218e47afcf65a5c449943bc40a17dec1aa486969926caf6a1b57515c36f9ea8cfe3c081e97876f916d64a2881948b
6
+ metadata.gz: 58105cea097503a9ae1ba7669771a21f414c32bebbb0870bd17f824092349c5f88f19018cf0c9d305d8e2e303f2fe9f617e3a81044b59b731e26557b08cf007c
7
+ data.tar.gz: 0cf2572e4a4ba8e6600beac1271650fcca1897439e1a2e60d2a15161ca27941201c334bb5ecbd0b3a002fe38f73d267e7b596cf59a1a2c7496b564d0e4100399
@@ -17,10 +17,6 @@ module Graphiti::OpenAPI
17
17
  attribute :schema, Types::Any
18
18
  attribute :path, Types::Coercible::String
19
19
 
20
- def path
21
- __attributes__[:path].gsub(/^#{Regexp.escape(ApplicationResource.endpoint_namespace)}/, '')
22
- end
23
-
24
20
  def resource_path
25
21
  File.join(path.to_s, "{id}")
26
22
  end
@@ -63,7 +59,7 @@ module Graphiti::OpenAPI
63
59
  actions.select(&:collection?)
64
60
  end
65
61
 
66
- memoize :path, :resource_path, :paths, :parameters, :resource, :resource_actions, :collection_actions
62
+ memoize :resource_path, :paths, :parameters, :resource, :resource_actions, :collection_actions
67
63
  end
68
64
 
69
65
  class Endpoints < Hash
@@ -77,7 +77,7 @@ module Graphiti::OpenAPI
77
77
  private
78
78
 
79
79
  def servers
80
- [{url: "#{root_url}#{ApplicationResource.endpoint_namespace}", description: "#{Rails.env} server"}]
80
+ [{url: root_url, description: "#{Rails.env} server"}]
81
81
  end
82
82
 
83
83
  def root_url
@@ -160,6 +160,7 @@ module Graphiti::OpenAPI
160
160
 
161
161
  # Use real resources in examples
162
162
  defs[:resource] = {
163
+ type: :object,
163
164
  oneOf: resources.values.map { |resource| {'$ref': "#/components/schemas/#{resource.type}_resource"} },
164
165
  }
165
166
 
@@ -174,30 +174,50 @@ module Graphiti::OpenAPI
174
174
  {
175
175
  "#{type}_single" => {
176
176
  type: :object,
177
- allOf: [
178
- {'$ref': "#/components/schemas/jsonapi_success"},
179
- {
180
- type: :object,
181
- properties: {
182
- data: {'$ref': "#/components/schemas/#{type}_resource"},
183
- },
177
+ properties: {
178
+ data: {'$ref': "#/components/schemas/#{type}_resource"},
179
+ included: {
180
+ description: "To reduce the number of HTTP requests, servers **MAY** allow responses that include related resources along with the requested primary resources. Such responses are called \"compound documents\".",
181
+ type: "array",
182
+ items: {'$ref': "#/components/schemas/jsonapi_resource"},
183
+ uniqueItems: true
184
184
  },
185
- ],
185
+ meta: {'$ref': "#/components/schemas/jsonapi_meta"},
186
+ links: {
187
+ description: "Link members related to the primary data.",
188
+ allOf: [
189
+ {"$ref": "#/components/schemas/jsonapi_links"},
190
+ {"$ref": "#/components/schemas/jsonapi_pagination"},
191
+ ]
192
+ },
193
+ "jsonapi": {"$ref": "#/components/schemas/jsonapi_jsonapi"},
194
+ },
195
+ additionalProperties: false
186
196
  },
187
197
  "#{type}_collection" => {
188
198
  type: :object,
189
- allOf: [
190
- {'$ref': "#/components/schemas/jsonapi_success"},
191
- {
192
- type: :object,
193
- properties: {
194
- data: {
195
- type: :array,
196
- items: {"$ref" => "#/components/schemas/#{type}_resource"},
197
- },
198
- },
199
+ properties: {
200
+ data: {
201
+ type: "array",
202
+ items: {'$ref': "#/components/schemas/#{type}_resource"},
203
+ },
204
+ included: {
205
+ description: "To reduce the number of HTTP requests, servers **MAY** allow responses that include related resources along with the requested primary resources. Such responses are called \"compound documents\".",
206
+ type: "array",
207
+ items: {'$ref': "#/components/schemas/jsonapi_resource"},
208
+ uniqueItems: true
199
209
  },
200
- ],
210
+ meta: {'$ref': "#/components/schemas/jsonapi_meta"},
211
+ links: {
212
+ description: "Link members related to the primary data.",
213
+ allOf: [
214
+ {"$ref": "#/components/schemas/jsonapi_links"},
215
+ {"$ref": "#/components/schemas/jsonapi_pagination"},
216
+ ]
217
+ },
218
+ "jsonapi": {"$ref": "#/components/schemas/jsonapi_jsonapi"},
219
+ },
220
+ additionalProperties: false
201
221
  },
202
222
  }
203
223
  end
@@ -209,7 +229,7 @@ module Graphiti::OpenAPI
209
229
  properties: {
210
230
  data: {'$ref': "#/components/schemas/#{type}_resource"},
211
231
  },
212
- # xml: {name: :data},
232
+ # xml: {name: :data},
213
233
  },
214
234
  }
215
235
  end
@@ -252,7 +272,7 @@ module Graphiti::OpenAPI
252
272
  description: "OK: #{human} resource",
253
273
  content: {
254
274
  "application/vnd.api+json" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
255
- # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
275
+ # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
256
276
  },
257
277
  links: link_refs,
258
278
  },
@@ -260,14 +280,14 @@ module Graphiti::OpenAPI
260
280
  description: "OK: #{plural_human} collection",
261
281
  content: {
262
282
  "application/vnd.api+json" => {schema: {"$ref": "#/components/schemas/#{type}_collection"}},
263
- # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_collection"}},
283
+ # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_collection"}},
264
284
  },
265
285
  },
266
286
  "#{type}_201" => {
267
287
  description: "Created",
268
288
  content: {
269
289
  "application/vnd.api+json" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
270
- # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
290
+ # "application/xml" => {schema: {"$ref": "#/components/schemas/#{type}_single"}},
271
291
  },
272
292
  links: link_refs,
273
293
  },
@@ -9,13 +9,42 @@ info:
9
9
  name: Developer Example
10
10
  # url: 'https://developer.example.test/'
11
11
  security:
12
- - bearerAuth: []
12
+ - Basic: []
13
+ - BearerJWT: []
14
+ - OAuth2:
15
+ - manage
16
+ - read
17
+ write
18
+ - read
19
+ create
20
+ update
21
+ delete
13
22
  components:
14
23
  securitySchemes:
15
- bearerAuth:
24
+ Basic:
25
+ type: http
26
+ scheme: basic
27
+ BearerJWT:
16
28
  type: http
17
29
  scheme: bearer
18
30
  bearerFormat: JWT
31
+ OAuth2:
32
+ type: oauth2
33
+ description: |
34
+ [OAuth 2.0 protocol](http://oauth.net/2/)
35
+ See /oauth/requests
36
+ flows:
37
+ password:
38
+ tokenUrl: /oauth/token
39
+ scopes:
40
+ public: Grant read-only access to all public data
41
+ read: Grant read-only access to all your data
42
+ write: Grant write-only access to all your data except for the account and user info
43
+ create: Grant write-only access to create anything
44
+ update: Grant write-only access to update all your data
45
+ delete: Grant write-only access to delete any of your data
46
+ manage: Grant read and write access to all your data
47
+ profile: Grant read-only access to the account and user info only
19
48
  responses:
20
49
  '200':
21
50
  description: OK
@@ -63,4 +92,169 @@ components:
63
92
  application/vnd.api+json:
64
93
  schema:
65
94
  $ref: '#/components/schemas/jsonapi_failure'
95
+ schemas:
96
+ OAuth2Scope:
97
+ type: string
98
+ enum: [public, read, write, create, update, delete, manage]
99
+ default: public
100
+ OAuth2Scopes:
101
+ type: array
102
+ items:
103
+ $ref: "#/components/schemas/OAuth2Scope"
104
+ default: [public]
105
+ OAuth2GrantType:
106
+ type: string
107
+ enum: [password, authorization_code]
108
+ OAuth2TokenRequest:
109
+ type: object
110
+ required:
111
+ - grant_type
112
+ properties:
113
+ grant_type:
114
+ $ref: "#/components/schemas/OAuth2GrantType"
115
+ scope:
116
+ $ref: "#/components/schemas/OAuth2Scopes"
117
+ username:
118
+ description: (when `grant_type="password"`)
119
+ type: string
120
+ format: email
121
+ password:
122
+ description: (when `grant_type="password"`)
123
+ type: string
124
+ format: password
125
+ client_id:
126
+ description: (when `grant_type="authorization_code"`)
127
+ type: string
128
+ client_secret:
129
+ description: (when `grant_type="authorization_code"`)
130
+ type: string
131
+ code:
132
+ description: (when `grant_type="authorization_code"`)
133
+ type: string
134
+ redirect_uri:
135
+ description: (when `grant_type="authorization_code"`)
136
+ type: string
137
+ format: uri
138
+ default: "urn:ietf:wg:oauth:2.0:oob"
139
+ additionalProperties: false
140
+ OAuth2Response:
141
+ type: object
142
+ properties:
143
+ access_token:
144
+ type: string
145
+ example: "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOjEsImlhdCI6MTU0ODU1OTMwNiwianRpIjoiZTc4MWZlYjUtNWYxNi00YzRlLWFjOWMtOTBlYTA2YWMwZWVjIiwiaW5mIjp7ImVtYWlsIjoiYWxleEBjZXJlYmVsby5zcGFjZSJ9fQ."
146
+ created_at:
147
+ type: integer
148
+ example: 1548559306
149
+ expires_in:
150
+ type: integer
151
+ example: 7200
152
+ scope:
153
+ type: string
154
+ example: "manage"
155
+ token_type:
156
+ type: string
157
+ enum: [Bearer]
158
+
159
+ examples:
160
+ OAuth2AuthorizationCodeRequest:
161
+ summary: Authorization Code Flow Request Body
162
+ value:
163
+ grant_type: authorization_code
164
+ code: "eyJhbGciOiJIUzUxMiJ9"
165
+ client_id: "123"
166
+ client_secret: "very-secret"
167
+ redirect_uri: "https://example.test/oauth/redirect"
168
+ OAuth2PasswordRequest:
169
+ summary: Resource Owner Password Credentials Flow Request Body
170
+ value:
171
+ grant_type: password
172
+ username: user@example.test
173
+ password: password
174
+ invalid_request:
175
+ summary: Missing required parameter
176
+ value:
177
+ error: invalid_request
178
+ error_description: The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.
179
+ authentication:
180
+ summary: Invalid credentials
181
+ value:
182
+ error: Invalid Email or password.
183
+
184
+ requestBodies:
185
+ OAuth2Request:
186
+ required: true
187
+ content:
188
+ application/x-www-form-urlencoded:
189
+ schema:
190
+ $ref: "#/components/schemas/OAuth2TokenRequest"
191
+ encoding:
192
+ scope:
193
+ style: spaceDelimited
194
+ explode: false
195
+ examples:
196
+ OAuth2AuthorizationCodeRequest:
197
+ $ref: "#/components/examples/OAuth2AuthorizationCodeRequest"
198
+ OAuth2PasswordRequest:
199
+ $ref: "#/components/examples/OAuth2PasswordRequest"
200
+
66
201
  paths:
202
+ /oauth/token:
203
+ post:
204
+ operationId: getOAuth2Token
205
+ tags:
206
+ - OAuth2.0
207
+ description: REtrieve OAuth 2.0 AccessToken
208
+ requestBody:
209
+ $ref: "#/components/requestBodies/OAuth2Request"
210
+ responses:
211
+ '200':
212
+ description: OAuth 2.0 Access Token
213
+ content:
214
+ application/json:
215
+ schema:
216
+ $ref: "#/components/schemas/OAuth2Response"
217
+ '401':
218
+ description: Unauthorized
219
+ content:
220
+ application/json:
221
+ schema:
222
+ type: object
223
+ required:
224
+ - error
225
+ properties:
226
+ error:
227
+ type: string
228
+ error_description:
229
+ type: string
230
+ examples:
231
+ invalid_request:
232
+ $ref: "#/components/examples/invalid_request"
233
+ authentication:
234
+ $ref: "#/components/examples/authentication"
235
+ # /oauth/revoke:
236
+ # post:
237
+ # tags:
238
+ # - OAuth2.0
239
+ # description: |
240
+ # [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
241
+ # responses:
242
+ # /oauth/introspect:
243
+ # post:
244
+ # tags:
245
+ # - OAuth2.0
246
+ # description: |
247
+ # [OAuth 2.0 Token Introspection](http://tools.ietf.org/html/rfc7662)
248
+ # parameters:
249
+ # - name: token
250
+ # in: body
251
+ # required: true
252
+ # schema:
253
+ # type: string
254
+ # - name: token_type_hint
255
+ # in: body
256
+ # responses:
257
+ tags:
258
+ - name: OAuth2.0
259
+ description: |
260
+ [OAuth 2.0 protocol](http://oauth.net/2/)
@@ -1,6 +1,6 @@
1
1
  Graphiti::OpenAPI::Engine.routes.draw do
2
2
  resources :specifications, only: :index, defaults: {format: :html}
3
3
 
4
- get "openapi.:format" => "specifications#index", defaults: {format: :json}
4
+ get "openapi.:format" => "specifications#index", defaults: {format: :json}, as: :openapi
5
5
  root to: "specifications#index", defaults: {format: :html}
6
6
  end
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency "activemodel"
30
30
  spec.add_runtime_dependency "responders"
31
31
  spec.add_runtime_dependency "kaminari"
32
- spec.add_runtime_dependency "graphiti", "~> 1.0.beta.8"
32
+ spec.add_runtime_dependency "graphiti", "~> 1.0.rc.7"
33
33
  spec.add_runtime_dependency "dry-struct", "~> 0.6.0"
34
34
  spec.add_runtime_dependency "transproc"
35
35
  spec.add_runtime_dependency "webpacker"
@@ -1,5 +1,5 @@
1
1
  module Graphiti
2
2
  module OpenAPI
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ namespace :graphiti do
14
14
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{installer_template}"
15
15
  end
16
16
 
17
+ desc "Generate OpenAPI files in public/"
17
18
  task generate: %W[environment #{jsonapi_schema}] do
18
19
  generator = Graphiti::OpenAPI::Generator.new
19
20
  api = Rails.root.join("public#{ApplicationResource.endpoint_namespace}")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti-openapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Semyonov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
11
+ date: 2019-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.0.beta.8
75
+ version: 1.0.rc.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.0.beta.8
82
+ version: 1.0.rc.7
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: dry-struct
85
85
  requirement: !ruby/object:Gem::Requirement