swagger-parser 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +23 -0
  6. data/.travis.yml +6 -0
  7. data/.yardopts +4 -0
  8. data/Gemfile +5 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +114 -0
  11. data/Rakefile +11 -0
  12. data/lib/swagger.rb +56 -0
  13. data/lib/swagger/api.rb +26 -0
  14. data/lib/swagger/attachable.rb +39 -0
  15. data/lib/swagger/boolean.rb +13 -0
  16. data/lib/swagger/builder.rb +109 -0
  17. data/lib/swagger/mime_type.rb +46 -0
  18. data/lib/swagger/notes.md +35 -0
  19. data/lib/swagger/parsers.rb +36 -0
  20. data/lib/swagger/schema.rb +63 -0
  21. data/lib/swagger/swagger_object.rb +49 -0
  22. data/lib/swagger/uri.rb +11 -0
  23. data/lib/swagger/uri_template.rb +11 -0
  24. data/lib/swagger/v2/api.rb +90 -0
  25. data/lib/swagger/v2/deterministic_json_schema.rb +130 -0
  26. data/lib/swagger/v2/example.rb +32 -0
  27. data/lib/swagger/v2/header.rb +22 -0
  28. data/lib/swagger/v2/info.rb +33 -0
  29. data/lib/swagger/v2/operation.rb +66 -0
  30. data/lib/swagger/v2/parameter.rb +35 -0
  31. data/lib/swagger/v2/path.rb +47 -0
  32. data/lib/swagger/v2/response.rb +26 -0
  33. data/lib/swagger/v2/security_requirement.rb +12 -0
  34. data/lib/swagger/v2/security_scheme.rb +25 -0
  35. data/lib/swagger/v2/tag.rb +11 -0
  36. data/lib/swagger/version.rb +3 -0
  37. data/resources/schemas/json_schema/draft-04.json +150 -0
  38. data/resources/schemas/swagger/v2.0/schema.json +1483 -0
  39. data/spec/fixtures/custom-properties.yaml +61 -0
  40. data/spec/fixtures/petstore-full.yaml +245 -0
  41. data/spec/fixtures/swagger.yaml +100 -0
  42. data/spec/spec_helper.rb +2 -0
  43. data/spec/swagger/api_spec.rb +87 -0
  44. data/spec/swagger/builder_spec.rb +52 -0
  45. data/spec/swagger/custom_properties_spec.rb +22 -0
  46. data/spec/swagger/info_spec.rb +76 -0
  47. data/spec/swagger/operation_spec.rb +99 -0
  48. data/spec/swagger/swagger_spec.rb +74 -0
  49. data/swagger-parser.gemspec +32 -0
  50. metadata +250 -0
@@ -0,0 +1,61 @@
1
+ swagger: 2.0
2
+ info:
3
+ version: 1.0.0
4
+ title: Swagger Petstore
5
+ license:
6
+ name: MIT
7
+ host: petstore.swagger.wordnik.com
8
+ basePath: /v1
9
+ schemes:
10
+ - http
11
+ consumes:
12
+ - application/json
13
+ produces:
14
+ - application/json
15
+ paths:
16
+ /pets:
17
+ get:
18
+ summary: List all pets
19
+ x-my-custom-param: whatever the hell I want!
20
+ operationId: listPets
21
+ responses:
22
+ 200:
23
+ description: An paged array of pets
24
+ headers:
25
+ x-next:
26
+ type: string
27
+ description: A link to the next page of responses
28
+ schema:
29
+ $ref: Pets
30
+ default:
31
+ description: unexpected error
32
+ schema:
33
+ $ref: Error
34
+
35
+ definitions:
36
+ Pet:
37
+ required:
38
+ - id
39
+ - name
40
+ properties:
41
+ id:
42
+ type: integer
43
+ format: int64
44
+ name:
45
+ type: string
46
+ tag:
47
+ type: string
48
+ Pets:
49
+ type: array
50
+ items:
51
+ $ref: Pet
52
+ Error:
53
+ required:
54
+ - code
55
+ - message
56
+ properties:
57
+ code:
58
+ type: integer
59
+ format: int32
60
+ message:
61
+ type: string
@@ -0,0 +1,245 @@
1
+ swagger: 2.0
2
+ info:
3
+ version: 1.0.0
4
+ title: Swagger Petstore
5
+ description: |
6
+ A sample API that uses a petstore as an example to demonstrate
7
+ features in the swagger-2.0 specification
8
+ termsOfService: http://helloreverb.com/terms/ # Note: require TOS to be URL again?
9
+ contact:
10
+ name: Wordnik API Team
11
+ url: http://madskristensen.net
12
+ email: foo@example.com
13
+ license:
14
+ name: MIT
15
+ url: http://choosealicense.com/licenses/mit/
16
+ host: petstore.swagger.wordnik.com
17
+ basePath: /api
18
+ schemes:
19
+ - http
20
+ - https
21
+ - ws
22
+ - wss
23
+ consumes:
24
+ - application/json
25
+ - application/xml
26
+ produces:
27
+ - application/vnd.max+json
28
+ - application/xml
29
+ paths:
30
+ /pets:
31
+ parameters:
32
+ - name: foo
33
+ in: query
34
+ description: foos to bar by
35
+ required: false
36
+ type: array
37
+ collectionFormat: csv
38
+ items:
39
+ type: string
40
+ get:
41
+ tags:
42
+ - Things
43
+ - That
44
+ - Do
45
+ - Stuff
46
+ summary: Gets pets
47
+ description: |-
48
+ Returns all pets from the system that the user has access to
49
+ Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.
50
+
51
+ Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.
52
+ operationId: Get Pets
53
+ security:
54
+ - githubAuth:
55
+ - "user:read"
56
+ - "user:write"
57
+ - internalApiKey: []
58
+ produces:
59
+ - application/json
60
+ parameters:
61
+ - name: tags
62
+ in: query
63
+ description: tags to filter by
64
+ required: false
65
+ type: array
66
+ collectionFormat: csv
67
+ items:
68
+ type: string
69
+ - name: limit
70
+ in: query
71
+ description: maximum number of results to return
72
+ required: false
73
+ type: integer
74
+ format: int32
75
+ responses:
76
+ 200:
77
+ description: pet response
78
+ schema:
79
+ type: array
80
+ items:
81
+ Pet:
82
+ $ref: '#/models/Pet'
83
+ headers:
84
+ is-dog:
85
+ type: boolean
86
+ is-cat:
87
+ type: boolean
88
+ examples:
89
+ application/json:
90
+ id: 9
91
+ category:
92
+ name: domestic
93
+ name: monster
94
+ tags:
95
+ - name: for sale
96
+ status: alive
97
+ default:
98
+ description: pet response (default)
99
+ schema:
100
+ type: array
101
+ items:
102
+ Pet:
103
+ $ref: '#/models/Pet'
104
+ headers:
105
+ is-dog:
106
+ type: boolean
107
+ is-cat:
108
+ type: boolean
109
+ examples:
110
+ application/json:
111
+ id: 9
112
+ category:
113
+ name: domestic
114
+ name: monster
115
+ tags:
116
+ - name: for sale
117
+ status: alive
118
+ schemes:
119
+ - http
120
+ - https
121
+ definitions:
122
+ Pet:
123
+ required:
124
+ - id
125
+ - name
126
+ properties:
127
+ id:
128
+ type: integer
129
+ format: int64
130
+ name:
131
+ type: string
132
+ tag:
133
+ type: string
134
+ securityDefinitions:
135
+ githubAccessCode:
136
+ type: "oauth2"
137
+ scopes:
138
+ user: |-
139
+ Grants read/write access to profile info only. Note that this scope
140
+ includes user:email and user:follow.
141
+ user:email: |-
142
+ Grants read access to a user’s email addresses.
143
+ user:follow: |-
144
+ Grants access to follow or unfollow other users.
145
+ public_repo: |-
146
+ Grants read/write access to code, commit statuses, and deployment
147
+ statuses for public repositories and organizations.
148
+ repo: |-
149
+ Grants read/write access to code, commit statuses, and deployment
150
+ statuses for public and private repositories and organizations.
151
+ repo_deployment: |-
152
+ Grants access to deployment statuses for public and private
153
+ repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.
154
+ repo:status: |-
155
+ Grants read/write access to public and private repository commit
156
+ statuses. This scope is only necessary to grant other users or services
157
+ access to private repository commit statuses without granting access to the code.
158
+ delete_repo: |-
159
+ Grants access to delete adminable repositories.
160
+ notifications: |-
161
+ Grants read access to a user’s notifications. repo also provides
162
+ this access.
163
+ gist: |-
164
+ Grants write access to gists.
165
+ read:repo_hook: |-
166
+ Grants read and ping access to hooks in public or private repositories.
167
+ write:repo_hook: |-
168
+ Grants read, write, and ping access to hooks in public or private repositories.
169
+ admin:repo_hook: |-
170
+ Grants read, write, ping, and delete access to hooks in public or private
171
+ repositories.
172
+ read:org: |-
173
+ Read-only access to organization, teams, and membership.
174
+ write:org: |-
175
+ Publicize and unpublicize organization membership.
176
+ admin:org: |-
177
+ Fully manage organization, teams, and memberships.
178
+ read:public_key: |-
179
+ List and view details for public keys.
180
+ write:public_key: |-
181
+ Create, list, and view details for public keys.
182
+ admin:public_key: |-
183
+ Fully manage public keys.
184
+ flow: "accessCode"
185
+ authorizationUrl: "https://github.com/login/oauth/authorize"
186
+ tokenUrl: "https://github.com/login/oauth/access_token"
187
+ petstoreImplicit:
188
+ type: "oauth2"
189
+ scopes:
190
+ user: |-
191
+ Grants read/write access to profile info only. Note that this scope
192
+ includes user:email and user:follow.
193
+ user:email: |-
194
+ Grants read access to a user’s email addresses.
195
+ user:follow: |-
196
+ Grants access to follow or unfollow other users.
197
+ public_repo: |-
198
+ Grants read/write access to code, commit statuses, and deployment statuses
199
+ for public repositories and organizations.
200
+ repo: |-
201
+ Grants read/write access to code, commit statuses, and deployment statuses
202
+ for public and private repositories and organizations.
203
+ repo_deployment: |-
204
+ Grants access to deployment statuses for public and private repositories. This
205
+ scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.
206
+ repo:status: |-
207
+ Grants read/write access to public and private repository commit statuses. This
208
+ scope is only necessary to grant other users or services access to private repository
209
+ commit statuses without granting access to the code.
210
+ delete_repo: |-
211
+ Grants access to delete adminable repositories.
212
+ notifications: |-
213
+ Grants read access to a user’s notifications. repo also provides this access.
214
+ gist: |-
215
+ Grants write access to gists.
216
+ read:repo_hook: |-
217
+ Grants read and ping access to hooks in public or private repositories.
218
+ write:repo_hook: |-
219
+ Grants read, write, and ping access to hooks in public or private repositories.
220
+ admin:repo_hook: |-
221
+ Grants read, write, ping, and delete access to hooks in public or private
222
+ repositories.
223
+ read:org: |-
224
+ Read-only access to organization, teams, and membership.
225
+ write:org: |-
226
+ Publicize and unpublicize organization membership.
227
+ admin:org: |-
228
+ Fully manage organization, teams, and memberships.
229
+ read:public_key: |-
230
+ List and view details for public keys.
231
+ write:public_key: |-
232
+ Create, list, and view details for public keys.
233
+ admin:public_key: |-
234
+ Fully manage public keys.
235
+ flow: "implicit"
236
+ authorizationUrl: "http://petstore.swagger.wordnik.com/oauth/dialog"
237
+ internalApiKey:
238
+ type: "apiKey"
239
+ in: "header"
240
+ name: "api_key"
241
+ security:
242
+ - githubAccessCode:
243
+ - "user"
244
+ - "gist"
245
+ - internalApiKey: []
@@ -0,0 +1,100 @@
1
+ swagger: 2.0
2
+ info:
3
+ version: 1.0.0
4
+ title: Swagger Petstore
5
+ license:
6
+ name: MIT
7
+ host: petstore.swagger.wordnik.com
8
+ basePath: /v1
9
+ schemes:
10
+ - http
11
+ consumes:
12
+ - application/json
13
+ produces:
14
+ - application/json
15
+ paths:
16
+ /pets:
17
+ get:
18
+ summary: List all pets
19
+ operationId: listPets
20
+ tags:
21
+ - pets
22
+ parameters:
23
+ - name: limit
24
+ in: query
25
+ description: How many items to return at one time (max 100)
26
+ required: false
27
+ type: integer
28
+ format: int32
29
+ responses:
30
+ 200:
31
+ description: An paged array of pets
32
+ headers:
33
+ x-next:
34
+ type: string
35
+ description: A link to the next page of responses
36
+ schema:
37
+ $ref: Pets
38
+ default:
39
+ description: unexpected error
40
+ schema:
41
+ $ref: Error
42
+ post:
43
+ summary: Create a pet
44
+ operationId: createPets
45
+ tags:
46
+ - pets
47
+ responses:
48
+ 201:
49
+ description: Null response
50
+ default:
51
+ description: unexpected error
52
+ schema:
53
+ $ref: Error
54
+ /pets/{petId}:
55
+ get:
56
+ summary: Info for a specific pet
57
+ operationId: showPetById
58
+ tags:
59
+ - pets
60
+ parameters:
61
+ - name: petId
62
+ in: path
63
+ description: The id of the pet to retrieve
64
+ type: string
65
+ responses:
66
+ 200:
67
+ description: Expected response to a valid request
68
+ schema:
69
+ $ref: Pets
70
+ default:
71
+ description: unexpected error
72
+ schema:
73
+ $ref: Error
74
+ definitions:
75
+ Pet:
76
+ required:
77
+ - id
78
+ - name
79
+ properties:
80
+ id:
81
+ type: integer
82
+ format: int64
83
+ name:
84
+ type: string
85
+ tag:
86
+ type: string
87
+ Pets:
88
+ type: array
89
+ items:
90
+ $ref: Pet
91
+ Error:
92
+ required:
93
+ - code
94
+ - message
95
+ properties:
96
+ code:
97
+ type: integer
98
+ format: int32
99
+ message:
100
+ type: string
@@ -0,0 +1,2 @@
1
+ # require 'webmock' # This will disable HTTP connections
2
+ require 'swagger'
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ module Swagger
4
+ module V2
5
+ describe API do
6
+ let(:swagger_file) { 'spec/fixtures/petstore-full.yaml' }
7
+ let(:swagger) { Swagger.load swagger_file }
8
+ let(:expected_host) { 'petstore.swagger.wordnik.com' }
9
+ let(:expected_basePath) { '/api' }
10
+
11
+ context 'extras' do
12
+ # These are utility methods, not part of the Swagger specification
13
+ describe '#validate' do
14
+ it 'returns true if the Swagger definition complies with the Swagger schema' do
15
+ expect(swagger.validate).to eq(true)
16
+ end
17
+
18
+ it 'raises an exception if the Swagger definition does not comply with the Swagger schema' do
19
+ swagger.swagger = 2.1
20
+ expect { swagger.validate }.to raise_error(Swagger::InvalidDefinition)
21
+ end
22
+ end
23
+
24
+ describe '#fully_validate' do
25
+ it 'returns true if the Swagger definition complies with the Swagger schema' do
26
+ expect(swagger.fully_validate).to eq(true)
27
+ end
28
+
29
+ it 'raises an exception if the Swagger definition does not comply with the Swagger schema' do
30
+ swagger.swagger = 2.1
31
+ expect { swagger.fully_validate }.to raise_error(Swagger::InvalidDefinition)
32
+ end
33
+ end
34
+
35
+ describe '#uri_template', extension: true do
36
+ it 'is combines the host and basePath into a single template' do
37
+ expect(swagger.uri_template).to eq("#{expected_host}#{expected_basePath}")
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'Sample petstore API' do
43
+ describe '#swagger' do
44
+ subject { swagger.swagger }
45
+ it { is_expected.to eq('2.0') }
46
+ end
47
+
48
+ describe '#info' do
49
+ subject { swagger.info }
50
+ it { is_expected.to be_a_kind_of Swagger::V2::Info }
51
+ # See info_spec for more
52
+ end
53
+
54
+ describe '#host' do
55
+ subject { swagger.host }
56
+ pending { is_expected.to be_a_kind_of Addressable::Template }
57
+ it { is_expected.to eq(expected_host) }
58
+ end
59
+
60
+ describe '#basePath' do
61
+ subject { swagger.basePath }
62
+ pending { is_expected.to be_a_kind_of Addressable::Template }
63
+ it { is_expected.to eq(expected_basePath) }
64
+ end
65
+
66
+ describe '#schemes' do
67
+ subject { swagger.schemes }
68
+ it { is_expected.to eq(%w(http https ws wss)) }
69
+ end
70
+
71
+ describe '#consumes' do
72
+ subject { swagger.consumes }
73
+ it { is_expected.to eq(%w(application/json application/xml)) }
74
+ end
75
+
76
+ describe '#produces' do
77
+ subject { swagger.produces }
78
+ it { is_expected.to eq(%w(application/vnd.max+json application/xml)) }
79
+ end
80
+
81
+ skip '#paths'
82
+ skip '#definitions'
83
+ skip '#security'
84
+ end
85
+ end
86
+ end
87
+ end