Skip to content

Commit 0aafa47

Browse files
committed
Fix and Bump to 1.4.2
1 parent ec3e6f2 commit 0aafa47

File tree

11 files changed

+33
-40
lines changed

11 files changed

+33
-40
lines changed

Gemfile.lock

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
zero-rails_openapi (1.4.1)
4+
zero-rails_openapi (1.4.2)
55
activesupport (>= 3)
66
rails (>= 3)
77

@@ -58,10 +58,12 @@ GEM
5858
loofah (2.1.1)
5959
crass (~> 1.0.2)
6060
nokogiri (>= 1.5.9)
61-
mail (2.7.0)
62-
mini_mime (>= 0.1.1)
61+
mail (2.6.6)
62+
mime-types (>= 1.16, < 4)
6363
method_source (0.9.0)
64-
mini_mime (1.0.0)
64+
mime-types (3.1)
65+
mime-types-data (~> 3.2015)
66+
mime-types-data (3.2016.0521)
6567
mini_portile2 (2.3.0)
6668
minitest (5.10.3)
6769
nio4r (2.1.0)
@@ -120,7 +122,7 @@ GEM
120122
thread_safe (~> 0.1)
121123
websocket-driver (0.6.5)
122124
websocket-extensions (>= 0.1.0)
123-
websocket-extensions (0.1.3)
125+
websocket-extensions (0.1.2)
124126

125127
PLATFORMS
126128
ruby

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
44
[![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
55
[![Maintainability](https://api.codeclimate.com/v1/badges/471fd60f6eb7b019ceed/maintainability)](https://codeclimate.com/github/zhandao/zero-rails_openapi/maintainability)
6+
[![Gitter Chat](https://badges.gitter.im/zero-rails_openapi/Lobby.svg)](https://gitter.im/zero-rails_openapi/Lobby)
67

78
Concise DSL for generating OpenAPI Specification 3 (**OAS3**, formerly Swagger3) JSON documentation for Rails application,
89
then you can use Swagger UI 3.2.0+ to show the documentation.

README_zh.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
44
[![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
55
[![Maintainability](https://api.codeclimate.com/v1/badges/471fd60f6eb7b019ceed/maintainability)](https://codeclimate.com/github/zhandao/zero-rails_openapi/maintainability)
6+
[![Gitter Chat](https://badges.gitter.im/zero-rails_openapi/Lobby.svg)](https://gitter.im/zero-rails_openapi/Lobby)
67

78
一套简洁的 DSL,用于为 Rails 应用生成 OpenAPI Specification 3 (**OAS3**, 旧称「Swagger3」) 标准的 JSON 文档。
89
(你还可以使用 Swagger-UI 3.2.0 以上版本来可视化所生成的文档。)

bin/console

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

3-
require "bundler/setup"
4-
require "open_api"
3+
require 'bundler/setup'
4+
require 'open_api'
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "open_api"
1010
# require "pry"
1111
# Pry.start
1212

13-
require "irb"
13+
require 'irb'
1414
IRB.start(__FILE__)

documentation/examples/auto_gen_doc.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,17 @@ def open_api_dry
5151
model = Object.const_get(action_path.split('#').first.split('/').last[0..-2].camelize) rescue nil
5252
type = action.in?(%w[ index show ]) ? Array[load_schema(model)] : String
5353
response '200', 'success', :json, type: {
54-
code: { type: Integer, dft: 200 },
55-
msg: { type: String, dft: 'success' },
56-
total: { type: Integer },
57-
timestamp: { type: Integer },
58-
language: { type: String, dft: 'Ruby' },
59-
data: { type: type }
54+
code: { type: Integer, dft: 200 },
55+
msg: { type: String, dft: 'success' },
56+
data: { type: type }
6057
}
6158

6259

6360
### Automatically generate responses based on the agreed error class.
6461
# The business error-class's implementation see:
65-
# https://github.com/zhandao/zero-rails/blob/master/lib/business_error/z_error.rb
62+
# https://github.com/zhandao/zero-rails/blob/master/lib/business_error/dsl.rb
6663
# It's usage see:
67-
# https://github.com/zhandao/zero-rails/blob/master/app/controllers/api/v1/base_controller.rb
64+
# https://github.com/zhandao/zero-rails/blob/master/app/_docs/api_error.rb
6865
# Then, the following code will auto generate error responses by
6966
# extracting the specified error classes info, for example,
7067
# in ExamplesError: `mattr_reader :name_not_found, 'can not find the name', 404`

lib/oas_objs/schema_obj.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class SchemaObj < Hash
1111
include SchemaObjHelpers
1212
include Helpers
1313

14-
attr_accessor :processed, :type
14+
attr_accessor :processed, :type, :preprocessed
1515

1616
def initialize(type, schema_hash)
17+
self.preprocessed = false
1718
self.processed = { }
1819
# [Note] Here is no limit to type, even if the input isn't up to OAS,
1920
# like: double, float, hash.
@@ -51,7 +52,7 @@ def process_for(param_name = nil, options = { desc_inside: false })
5152
def preprocess_with_desc desc, param_name = nil
5253
self.__desc = desc
5354
process_for param_name
54-
@preprocessed = true
55+
self.preprocessed = true
5556
__desc
5657
end
5758

lib/open_api/config.rb

+1-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Config
2323
end
2424

2525
cattr_accessor :active_record_base do
26-
'ApplicationRecord'
26+
nil
2727
end
2828

2929
# Everything about OAS3 is on https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md
@@ -55,18 +55,6 @@ module Config
5555
'binary'
5656
end
5757

58-
cattr_accessor :generate_jbuilder_file do
59-
false
60-
end
61-
62-
cattr_accessor :overwrite_jbuilder_file do
63-
false
64-
end
65-
66-
cattr_accessor :jbuilder_templates do
67-
{ }
68-
end
69-
7058
def self.docs
7159
open_api_docs
7260
end

lib/open_api/dsl/components.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ class Components < Hash
99
def schema component_key, type = nil, one_of: nil, all_of: nil, any_of: nil, not: nil, **schema_hash
1010
(schema_hash = type) and (type = type.delete(:type)) if type.is_a?(Hash) && type.key?(:type)
1111
type ||= schema_hash[:type]
12-
type ||= load_schema component_key if component_key.try(:superclass) == Config.active_record_base.to_s.constantize
12+
type ||= load_schema component_key if component_key.try(:superclass) == Config.active_record_base || ApplicationRecord
1313

14-
combined_schema = one_of || all_of || any_of || (_not = binding.local_variable_get(:not))
14+
combined_schema = (_not = binding.local_variable_get(:not)) || one_of || all_of || any_of
1515
combined_schema = CombinedSchema.new(one_of: one_of, all_of: all_of, any_of: any_of, _not: _not) if combined_schema
1616
(self[:schemas] ||= { })[component_key.to_s.to_sym] = combined_schema&.process || SchemaObj.new(type, schema_hash).process
1717
end
1818
arrow_enable :schema
1919

20-
def example summary, example_hash
21-
# TODO
20+
def example component_key, examples_hash
21+
(self[:examples] ||= { })[component_key] = ExampleObj.new(examples_hash).process
2222
end
23+
arrow_enable :example
2324

2425
def param component_key, param_type, name, type, required, schema_hash = { }
2526
(self[:parameters] ||= { })[component_key] = ParamObj.new(name, param_type, type, required, schema_hash).process
@@ -60,15 +61,18 @@ def security_scheme scheme_name, other_info# = { }
6061
def base_auth scheme_name, other_info = { }
6162
security_scheme scheme_name, { type: 'http', scheme: 'basic' }.merge(other_info)
6263
end
64+
arrow_enable :base_auth
6365

6466
def bearer_auth scheme_name, format = 'JWT', other_info = { }
6567
security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format }.merge(other_info)
6668
end
69+
arrow_enable :bearer_auth
6770

6871
def api_key scheme_name, field:, in:, **other_info
6972
_in = binding.local_variable_get(:in)
7073
security_scheme scheme_name, { type: 'apiKey', name: field, in: _in }.merge(other_info)
7174
end
75+
arrow_enable :api_key
7276

7377
def _process_objs
7478
self[:responses]&.each do |code, obj|

lib/open_api/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module OpenApi
2-
VERSION = '1.4.1'
2+
VERSION = '1.4.2'
33
end

spec/openapi/openapi_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
it "has a version number" do
33
expect(OpenApi::VERSION).not_to be nil
44
end
5-
65
end

spec/spec_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
require "bundler/setup"
2-
require "open_api"
1+
require 'bundler/setup'
2+
require 'open_api'
33

44
RSpec.configure do |config|
55
# Enable flags like --only-failures and --next-failure
6-
config.example_status_persistence_file_path = ".rspec_status"
6+
config.example_status_persistence_file_path = '.rspec_status'
77

88
# Disable RSpec exposing methods globally on `Module` and `main`
99
config.disable_monkey_patching!

0 commit comments

Comments
 (0)