open_api 0.2.0 → 0.3.0

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: 9cb3780237e228de5aba05e77e13f1e7ad7699a0fa7e0f7650c6a959b533a248
4
- data.tar.gz: 1f85ba19940b862a3829e02e8db6c10a1fd31028b43771c417578d0fc869c765
3
+ metadata.gz: eb0adf2485d861c6548d554e3fb7b2f84b53416ff6f09c6af97ffb6b073a247e
4
+ data.tar.gz: 4df4e9890e7ead39fa4b24b60ec0b25fa05d8ffb3ac7f57ebd3341597e40ce5b
5
5
  SHA512:
6
- metadata.gz: 4acc8b5ab843a7aa5fa47ec5f528ba4d42851f7577ed02ac797c6940f77e06eb183a43cc2a885dad2451ce96f1631338bffa66b61bdda264c56f45672c79bdd8
7
- data.tar.gz: 2487a600e7d723351712d83b0307960a61c1caaad328c57333a52540ee658220418647d8acd9ca226b1c41d9fc0db1aacc0eefa327cd80a6ba5e28b2129e47f0
6
+ metadata.gz: b5a7df0a7d7e84129a3aeafdd14bb318731e8472185622f15f3aa318124b096026a56bb81b19dacd1ca80de72499c8680afa8265ee0b391dca865dee70f96545
7
+ data.tar.gz: 926ebda0ae134f4a7b9bf29dc8c287283d093d5e10f45cda05e52d3ab0d05bdbf0046ceca84a6380efe8d5a4fa8c7ab8089791377b1d4e4d8bb887edc821b826
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+ * Add `#serializable_hash` to Components
3
+ * Allow Paths and Responses to set like a hash
4
+ * Fallback to string when it has no serializable way
5
+
1
6
  ## 0.2.0
2
7
  * Allow Schema to behave like OpenStruct 5a698cf796f0467b726062bcd7c2cf2c20693950
3
8
  * Allow to serialize `schema.properties` fb6f2a0a5d58de7c0bfb113b3a6636a50df7de3d
data/README.md CHANGED
@@ -71,7 +71,7 @@ spec = OpenApi::Serializers::YamlSerializer.deserialize(yaml)
71
71
 
72
72
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
73
 
74
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, run `bundle exec rake bump:patch` to update the version, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
75
 
76
76
  ## Contributing
77
77
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "bump/tasks"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
@@ -16,6 +16,20 @@ module OpenApi
16
16
  self.callbacks = callbacks
17
17
  end
18
18
 
19
+ def serializable_hash
20
+ {
21
+ "schemas" => schemas&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
22
+ "responses" => responses&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
23
+ "parameters" => parameters&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
24
+ "examples" => examples&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
25
+ "requestBodies" => request_bodies&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
26
+ "headers" => headers&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
27
+ "securitySchemes" => security_schemes&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
28
+ "links" => links&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
29
+ "callbacks" => callbacks&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
30
+ }.compact
31
+ end
32
+
19
33
  def self.load(hash)
20
34
  return unless hash
21
35
 
@@ -0,0 +1,27 @@
1
+ module OpenApi
2
+ DataType = Struct.new(:name, :type, :format)
3
+
4
+ class DataTypes
5
+ @data = [
6
+ DataType.new(:integer, :integer, :int32),
7
+ DataType.new(:long, :integer, :int64),
8
+ DataType.new(:float, :number, :float),
9
+ DataType.new(:double, :number, :double),
10
+ DataType.new(:string, :string),
11
+ DataType.new(:byte, :string, :byte),
12
+ DataType.new(:binary, :string, :binary),
13
+ DataType.new(:boolean, :boolean),
14
+ DataType.new(:date, :string, :date),
15
+ DataType.new(:dateTime, :string, :"date-time"),
16
+ DataType.new(:password, :string, :password),
17
+ ]
18
+
19
+ def self.all
20
+ @data
21
+ end
22
+
23
+ def self.all_types
24
+ all.map(&:type).uniq
25
+ end
26
+ end
27
+ end
@@ -13,7 +13,7 @@ module OpenApi
13
13
  self.description = description
14
14
  self.servers = servers
15
15
  self.parameters = parameters
16
- self.operations = operations.with_indifferent_access
16
+ self.operations = operations.map { |k, v| [k.to_s.underscore.to_sym, v] }.to_h
17
17
  end
18
18
 
19
19
  def serializable_hash
@@ -23,7 +23,7 @@ module OpenApi
23
23
  "description" => description&.to_s,
24
24
  "servers" => servers&.map(&:serializable_hash),
25
25
  "parameters" => parameters&.map(&:serializable_hash),
26
- }.merge(operations.map { |k, v| [k.to_s, v.serializable_hash] }.to_h)
26
+ }.merge(operations.map { |k, v| [k.to_s.underscore, v.serializable_hash] }.to_h)
27
27
  .compact
28
28
  end
29
29
 
@@ -8,7 +8,7 @@ module OpenApi
8
8
  self.path_hash = path_hash.with_indifferent_access
9
9
  end
10
10
 
11
- def_delegator :path_hash, :[]
11
+ def_delegators :path_hash, :[], :[]=
12
12
 
13
13
  def self.load(hash)
14
14
  hash = hash.map { |k, v| [k.to_sym, PathItem.load(v)] }.to_h
@@ -10,7 +10,7 @@ module OpenApi
10
10
  self.responses_hash = responses_hash.with_indifferent_access
11
11
  end
12
12
 
13
- def_delegator :responses_hash, :[]
13
+ def_delegators :responses_hash, :[], :[]=
14
14
 
15
15
  def serializable_hash
16
16
  {
@@ -13,7 +13,7 @@ module OpenApi
13
13
  self.external_docs = external_docs
14
14
  self.example = example
15
15
  self.deprecated = deprecated
16
- self.other_fields_hash = other_fields_hash.symbolize_keys
16
+ self.other_fields_hash = other_fields_hash
17
17
 
18
18
  other_fields_hash.keys.each { |name| new_field(name) }
19
19
  end
@@ -54,7 +54,7 @@ module OpenApi
54
54
  when :items then v.serializable_hash
55
55
  when :properties then v.map { |k, v| [k.to_s, v.serializable_hash] }.to_h
56
56
  else
57
- v
57
+ v.to_s
58
58
  end
59
59
  [k.to_s, value]
60
60
  }.to_h
@@ -1,3 +1,3 @@
1
1
  module OpenApi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/open_api.rb CHANGED
@@ -7,6 +7,7 @@ require "active_support/core_ext/object/inclusion"
7
7
  # open_api/*
8
8
  require "open_api/equatable_as_content"
9
9
  require "open_api/version"
10
+ require "open_api/data_types"
10
11
 
11
12
  # Models
12
13
  require "open_api/specification"
data/open_api.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
28
  spec.add_development_dependency "pry"
29
29
  spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "bump"
30
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent Nagata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-09 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bump
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: It provides PORO of OpenAPI specification. It only support OpenAPI v3.
98
112
  email:
99
113
  - ngtknt@me.com
@@ -117,6 +131,7 @@ files:
117
131
  - lib/open_api/callback.rb
118
132
  - lib/open_api/components.rb
119
133
  - lib/open_api/contact.rb
134
+ - lib/open_api/data_types.rb
120
135
  - lib/open_api/discriminator.rb
121
136
  - lib/open_api/encoding.rb
122
137
  - lib/open_api/equatable_as_content.rb