swagger-core 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.shared_examples 'swagger loading' do
4
- it { is_expected.to be_a_kind_of Swagger::APIDeclaration }
4
+ it { is_expected.to be_a_kind_of Swagger::API }
5
5
 
6
6
  it 'has a swagger spec version' do
7
7
  expect(subject.swagger).to eq(2.0)
@@ -9,6 +9,35 @@ RSpec.shared_examples 'swagger loading' do
9
9
  end
10
10
 
11
11
  describe Swagger do
12
+ describe '#build' do
13
+ let(:content) { File.read(swagger_file) }
14
+
15
+ context 'json' do
16
+ let(:swagger_file) { 'swagger_spec/examples/v2.0/json/petstore.json' }
17
+ let(:opts) do
18
+ { format: :json }
19
+ end
20
+ subject(:swagger) { Swagger.build(content, opts) }
21
+ include_examples 'swagger loading'
22
+ end
23
+
24
+ context 'yaml' do
25
+ let(:swagger_file) { 'swagger_spec/examples/v2.0/yaml/petstore.yaml' }
26
+ let(:opts) do
27
+ { format: :yaml }
28
+ end
29
+ subject(:swagger) { Swagger.build(content, opts) }
30
+ include_examples 'swagger loading'
31
+ end
32
+
33
+ context 'already parsed' do
34
+ let(:swagger_file) { 'swagger_spec/examples/v2.0/yaml/petstore.yaml' }
35
+ let(:content) { YAML.load(File.read(swagger_file)) }
36
+ subject(:swagger) { Swagger.build(content) }
37
+ include_examples 'swagger loading'
38
+ end
39
+ end
40
+
12
41
  describe '#load' do
13
42
  subject(:swagger) { Swagger.load swagger_file }
14
43
 
@@ -22,4 +51,24 @@ describe Swagger do
22
51
  include_examples 'swagger loading'
23
52
  end
24
53
  end
54
+
55
+ describe '#builder' do
56
+ context 'default version' do
57
+ subject(:builder) { described_class.builder }
58
+ it { is_expected.to be_a_kind_of(Swagger::Bash) }
59
+ it { is_expected.to be_a_kind_of(Swagger::V2::API) }
60
+ end
61
+
62
+ context 'version 2' do
63
+ subject(:builder) { described_class.builder(version: '2.0') }
64
+ it { is_expected.to be_a_kind_of(Swagger::Bash) }
65
+ it { is_expected.to be_a_kind_of(Swagger::V2::API) }
66
+ end
67
+
68
+ context 'version 1' do
69
+ subject(:builder) { described_class.builder(version: '1.2') }
70
+ pending { is_expected.to be_a_kind_of(Swagger::Bash) }
71
+ pending { is_expected.to be_a_kind_of(Swagger::V2::API) }
72
+ end
73
+ end
25
74
  end
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rake'
29
29
  spec.add_development_dependency 'rspec'
30
30
  spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'rake-notes'
32
+ spec.add_development_dependency 'inch'
31
33
  end
metadata CHANGED
@@ -1,225 +1,236 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Max Lincoln
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: addressable
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.3'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: hashie
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '3.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '3.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json-schema
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '2.2'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '2.2'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: mime-types
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '2.0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '2.0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: '1.6'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: '1.6'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rake
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rubocop
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - ">="
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - ">="
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
- description: ! " The Swagger gem parses and provides an simple API for\n [Swagger](http://swagger.io/)
143
- documents that define RESTful APIs.\n"
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake-notes
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: inch
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: |2
154
+ The Swagger gem parses and provides an simple API for
155
+ [Swagger](http://swagger.io/) documents that define RESTful APIs.
144
156
  email:
145
157
  - max@devopsy.com
146
158
  executables: []
147
159
  extensions: []
148
160
  extra_rdoc_files: []
149
161
  files:
150
- - .gitignore
151
- - .gitmodules
152
- - .rubocop.yml
153
- - .travis.yml
162
+ - ".gitignore"
163
+ - ".gitmodules"
164
+ - ".rspec"
165
+ - ".rubocop.yml"
166
+ - ".travis.yml"
167
+ - ".yardopts"
154
168
  - Gemfile
155
169
  - LICENSE.txt
156
170
  - README.md
157
171
  - Rakefile
158
172
  - lib/swagger.rb
159
- - lib/swagger/api_declaration.rb
173
+ - lib/swagger/api.rb
160
174
  - lib/swagger/attachable.rb
161
175
  - lib/swagger/builder.rb
162
- - lib/swagger/definition_section.rb
163
- - lib/swagger/loaders.rb
164
176
  - lib/swagger/mime_type.rb
165
177
  - lib/swagger/notes.md
178
+ - lib/swagger/parsers.rb
166
179
  - lib/swagger/schema.rb
180
+ - lib/swagger/swagger_object.rb
167
181
  - lib/swagger/uri.rb
168
182
  - lib/swagger/uri_template.rb
169
- - lib/swagger/v2/api_declaration.rb
170
- - lib/swagger/v2/api_operation.rb
183
+ - lib/swagger/v2/api.rb
171
184
  - lib/swagger/v2/example.rb
172
185
  - lib/swagger/v2/info.rb
186
+ - lib/swagger/v2/operation.rb
173
187
  - lib/swagger/v2/parameter.rb
174
188
  - lib/swagger/v2/path.rb
175
189
  - lib/swagger/v2/response.rb
190
+ - lib/swagger/v2/tag.rb
176
191
  - lib/swagger/version.rb
177
192
  - resources/schemas/json_schema/draft-04.json
178
193
  - resources/schemas/swagger/v2.0/schema.json
179
194
  - spec/fixtures/petstore-full.yaml
180
195
  - spec/fixtures/swagger.yaml
181
196
  - spec/spec_helper.rb
182
- - spec/swagger/api_declaration_spec.rb
183
- - spec/swagger/api_operation_spec.rb
197
+ - spec/swagger/api_spec.rb
198
+ - spec/swagger/builder_spec.rb
184
199
  - spec/swagger/info_spec.rb
200
+ - spec/swagger/operation_spec.rb
185
201
  - spec/swagger/swagger_spec.rb
186
202
  - swagger-core.gemspec
187
203
  homepage: https://github.com/maxlinc/swagger-rb
188
204
  licenses:
189
205
  - Apache-2.0
206
+ metadata: {}
190
207
  post_install_message:
191
208
  rdoc_options: []
192
209
  require_paths:
193
210
  - lib
194
211
  required_ruby_version: !ruby/object:Gem::Requirement
195
- none: false
196
212
  requirements:
197
- - - ! '>='
213
+ - - ">="
198
214
  - !ruby/object:Gem::Version
199
215
  version: '0'
200
- segments:
201
- - 0
202
- hash: -4489768355737568917
203
216
  required_rubygems_version: !ruby/object:Gem::Requirement
204
- none: false
205
217
  requirements:
206
- - - ! '>='
218
+ - - ">="
207
219
  - !ruby/object:Gem::Version
208
220
  version: '0'
209
- segments:
210
- - 0
211
- hash: -4489768355737568917
212
221
  requirements: []
213
222
  rubyforge_project:
214
- rubygems_version: 1.8.23.2
223
+ rubygems_version: 2.2.0
215
224
  signing_key:
216
- specification_version: 3
225
+ specification_version: 4
217
226
  summary: Swagger parser for Ruby
218
227
  test_files:
219
228
  - spec/fixtures/petstore-full.yaml
220
229
  - spec/fixtures/swagger.yaml
221
230
  - spec/spec_helper.rb
222
- - spec/swagger/api_declaration_spec.rb
223
- - spec/swagger/api_operation_spec.rb
231
+ - spec/swagger/api_spec.rb
232
+ - spec/swagger/builder_spec.rb
224
233
  - spec/swagger/info_spec.rb
234
+ - spec/swagger/operation_spec.rb
225
235
  - spec/swagger/swagger_spec.rb
236
+ has_rdoc:
@@ -1,34 +0,0 @@
1
- module Swagger
2
- class DefinitionSection < Hashie::Dash
3
- include Hashie::Extensions::Coercion
4
- include Hashie::Extensions::IndifferentAccess
5
- include Swagger::Attachable
6
-
7
- attr_accessor :parent
8
-
9
- def initialize(hash)
10
- super
11
- attach_to_children
12
- end
13
-
14
- # @api private
15
- # @!macro [new] section
16
- # @!attribute [rw] $1
17
- # $3
18
- # @return [$2]
19
- def self.section(name, type)
20
- property name
21
- coerce_key name, type
22
- end
23
-
24
- # @api private
25
- # @!macro [new] section
26
- # @!attribute [rw] $1
27
- # **Required**. $3
28
- # @return [$2]
29
- def self.required_section(name, type)
30
- property name, required: true
31
- coerce_key name, type
32
- end
33
- end
34
- end
@@ -1,29 +0,0 @@
1
- autoload :YAML, 'yaml'
2
- autoload :JSON, 'json'
3
-
4
- module Swagger
5
- module Loaders
6
- def self.loader_for(ext)
7
- case ext
8
- when '.yaml', '.yml'
9
- YAMLLoader
10
- when '.json', '.js'
11
- JSONLoader
12
- else
13
- fail ArgumentError, "No registered Loader for #{ext}"
14
- end
15
- end
16
-
17
- class YAMLLoader
18
- def self.load(content)
19
- APIDeclaration.build(YAML.load(content))
20
- end
21
- end
22
-
23
- class JSONLoader
24
- def self.load(content)
25
- APIDeclaration.build(JSON.parse(content))
26
- end
27
- end
28
- end
29
- end
@@ -1,81 +0,0 @@
1
- require 'json-schema'
2
- require 'swagger/v2/info'
3
- require 'swagger/v2/path'
4
-
5
- module Swagger
6
- module V2
7
- SWAGGER_SCHEMA = File.expand_path 'schemas/swagger/v2.0/schema.json', Swagger::RESOURCES_DIR
8
- JSON_SCHEMA = File.expand_path 'schemas/json_schema/draft-04.json', Swagger::RESOURCES_DIR
9
-
10
- class APIDeclaration < Swagger::APIDeclaration
11
- required_section :swagger, Float
12
- required_section :info, Info
13
- required_section :paths, Hash[String => Path]
14
- section :host, Swagger::URITemplate
15
- section :basePath, Swagger::URITemplate
16
- section :schemes, Array[String]
17
- section :consumes, Array[String]
18
- section :produces, Array[String]
19
- section :schemas, Hash
20
- section :definitions, Hash
21
- section :security, Array
22
- # FIXME: Doesn't :parameter exist at this level as well?
23
-
24
- attr_reader :apis
25
-
26
- alias_method :base_path, :basePath
27
-
28
- # def initialize(hash)
29
- # super
30
- # attach_to_apis
31
- # end
32
-
33
- def apis
34
- # Perhaps not the best way...
35
- paths.values.map do | path |
36
- path.operations.values
37
- end.flatten
38
- end
39
-
40
- def uri_template
41
- # TODO: Can calculated values be safely memoized?
42
- # TODO: Actual URI Template objects or just strings?
43
- "#{host}#{basePath}"
44
- end
45
-
46
- def fully_validate
47
- # FIXME: fully_validate is ideal, but very slow with the current schema/validator
48
- errors = JSON::Validator.fully_validate(swagger_schema, to_json)
49
- fail Swagger::InvalidDefinition, errors unless errors.empty?
50
- true
51
- end
52
-
53
- def validate
54
- JSON::Validator.validate!(swagger_schema, to_json)
55
- rescue JSON::Schema::ValidationError => e
56
- raise Swagger::InvalidDefinition, e.message
57
- end
58
-
59
- private
60
-
61
- def swagger_schema
62
- @swagger_schema ||= JSON.parse(File.read(SWAGGER_SCHEMA))
63
-
64
- # Offline workaround
65
- # @swagger_schema = JSON.parse(File.read(SWAGGER_SCHEMA)
66
- # .gsub('http://json-schema.org/draft-04/schema', "file://#{SWAGGER_SCHEMA}"))
67
- # @swagger_schema['$schema'] = 'http://json-schema.org/draft-04/schema#'
68
- # @swagger_schema
69
- end
70
-
71
- # def attach_to_apis
72
- # @apis ||= Set.new
73
- # paths.each do |path, api|
74
- # api.path = path
75
- # api.parent = self
76
- # @apis << api
77
- # end
78
- # end
79
- end
80
- end
81
- end