meta-api 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/lib/meta/application/execution.rb +19 -49
  4. data/lib/meta/application/metadata.rb +68 -15
  5. data/lib/meta/application/responses.rb +32 -0
  6. data/lib/meta/application/route.rb +4 -26
  7. data/lib/meta/config.rb +2 -3
  8. data/lib/meta/entity.rb +2 -3
  9. data/lib/meta/json_schema/builders/object_schema_builder.rb +45 -40
  10. data/lib/meta/json_schema/builders/schema_builder_tool.rb +2 -5
  11. data/lib/meta/json_schema/schemas/array_schema.rb +24 -14
  12. data/lib/meta/json_schema/schemas/base_schema.rb +107 -37
  13. data/lib/meta/json_schema/schemas/named_properties.rb +37 -0
  14. data/lib/meta/json_schema/schemas/object_schema.rb +58 -20
  15. data/lib/meta/json_schema/schemas/properties.rb +27 -76
  16. data/lib/meta/json_schema/schemas/ref_schema.rb +36 -9
  17. data/lib/meta/json_schema/schemas/scoping_schema.rb +38 -0
  18. data/lib/meta/json_schema/schemas/staging_schema.rb +59 -0
  19. data/lib/meta/json_schema/schemas/unsupported_schema.rb +22 -0
  20. data/lib/meta/json_schema/support/errors.rb +3 -0
  21. data/lib/meta/json_schema/support/json_object.rb +37 -0
  22. data/lib/meta/json_schema/support/schema_options.rb +0 -9
  23. data/lib/meta/json_schema/support/scope_matcher.rb +29 -0
  24. data/lib/meta/json_schema/support/type_converter.rb +3 -24
  25. data/lib/meta/route_dsl/meta_builder.rb +2 -2
  26. data/lib/meta/swagger_doc.rb +2 -25
  27. data/lib/meta/utils/kwargs/builder.rb +5 -3
  28. data/lib/meta/utils/route_dsl_builders.rb +2 -1
  29. data/meta-api.gemspec +6 -5
  30. metadata +75 -111
  31. data/.autoenv.zsh +0 -1
  32. data/.gitignore +0 -7
  33. data/.rubocop.yml +0 -28
  34. data/Gemfile +0 -19
  35. data/Gemfile.lock +0 -68
  36. data/README.md +0 -166
  37. data/Rakefile +0 -3
  38. data/docs/Rails.md +0 -61
  39. data/docs//345/220/215/347/247/260/347/224/261/346/235/245.md +0 -7
  40. data/docs//345/246/202/344/275/225/350/264/241/347/214/256.md +0 -10
  41. data/docs//346/225/231/347/250/213.md +0 -1708
  42. data/docs//347/264/242/345/274/225.md +0 -183
  43. data/examples/lobster.rb +0 -71
  44. data/examples/rack_app/README.md +0 -3
  45. data/examples/rack_app/config.ru +0 -6
  46. data/examples/rack_app/hello.rb +0 -6
  47. data/examples/rack_app/timing.rb +0 -15
  48. data/examples/rails_app/.gitattributes +0 -5
  49. data/examples/rails_app/.gitignore +0 -23
  50. data/examples/rails_app/.rspec +0 -1
  51. data/examples/rails_app/.ruby-version +0 -1
  52. data/examples/rails_app/Gemfile +0 -29
  53. data/examples/rails_app/Gemfile.lock +0 -190
  54. data/examples/rails_app/README.md +0 -11
  55. data/examples/rails_app/Rakefile +0 -6
  56. data/examples/rails_app/app/controllers/application_controller.rb +0 -7
  57. data/examples/rails_app/app/controllers/concerns/.keep +0 -0
  58. data/examples/rails_app/app/controllers/data_controller.rb +0 -63
  59. data/examples/rails_app/app/controllers/swagger_controller.rb +0 -13
  60. data/examples/rails_app/app/models/concerns/.keep +0 -0
  61. data/examples/rails_app/bin/rails +0 -4
  62. data/examples/rails_app/bin/rake +0 -4
  63. data/examples/rails_app/bin/setup +0 -25
  64. data/examples/rails_app/config/application.rb +0 -39
  65. data/examples/rails_app/config/boot.rb +0 -3
  66. data/examples/rails_app/config/credentials.yml.enc +0 -1
  67. data/examples/rails_app/config/environment.rb +0 -5
  68. data/examples/rails_app/config/environments/development.rb +0 -51
  69. data/examples/rails_app/config/environments/production.rb +0 -65
  70. data/examples/rails_app/config/environments/test.rb +0 -50
  71. data/examples/rails_app/config/initializers/cors.rb +0 -16
  72. data/examples/rails_app/config/initializers/filter_parameter_logging.rb +0 -8
  73. data/examples/rails_app/config/initializers/inflections.rb +0 -16
  74. data/examples/rails_app/config/initializers/meta_rails_plugin.rb +0 -3
  75. data/examples/rails_app/config/locales/en.yml +0 -33
  76. data/examples/rails_app/config/puma.rb +0 -43
  77. data/examples/rails_app/config/routes.rb +0 -13
  78. data/examples/rails_app/config.ru +0 -6
  79. data/examples/rails_app/lib/tasks/.keep +0 -0
  80. data/examples/rails_app/log/.keep +0 -0
  81. data/examples/rails_app/public/robots.txt +0 -1
  82. data/examples/rails_app/spec/data_controller_spec.rb +0 -60
  83. data/examples/rails_app/spec/rails_helper.rb +0 -55
  84. data/examples/rails_app/spec/spec_helper.rb +0 -94
  85. data/examples/rails_app/spec/swagger_controller_spec.rb +0 -13
  86. data/examples/rails_app/tmp/.keep +0 -0
  87. data/examples/rails_app/tmp/pids/.keep +0 -0
@@ -1,183 +0,0 @@
1
- # 索引
2
-
3
- ## 属性校验
4
-
5
- ### `validate`
6
-
7
- 通用的校验器,可传递一个自定义的块。注意,如果校验不通过,需要主动地抛出 `Meta::JsonSchema::ValidationError`. 例如:
8
-
9
- ```ruby
10
- property :mobile, validate: lambda do |value|
11
- raise Meta::JsonSchema::ValidationError, '手机号格式不正确' unless value =~ /\d+/
12
- end
13
- ```
14
-
15
- ### `required`
16
-
17
- 有关必须要传递的字段可通过 `required: true` 设置。
18
-
19
- ```ruby
20
- property :name, required: true # 必须
21
- property :age, required: false # 非必须
22
- ```
23
-
24
- 对于字符串属性,即使是空白字符串也无法通过 `required` 校验。这时可通过设置 `allow_empty: true` 来改变这一行为。
25
-
26
- ```ruby
27
- property :name, required: { allow_empty: true }
28
- ```
29
-
30
- 数组属性默认是允许空数组的。如果你不喜欢这种行为,需明确设置 `allow_empty` 为 `false`.
31
-
32
- ### `format`
33
-
34
- `format` 校验可传递一个正则表达式选项,参数需匹配正则表达式代表的模式。
35
-
36
- ```ruby
37
- property :date, format: /^\d{4}-\d{2}-\d{2}$/
38
- ```
39
-
40
- ### `allowable`
41
-
42
- 对于枚举值来说,通过 `allowable` 来定义可选项。
43
-
44
- ```ruby
45
- property :gender, allowable: ['male', 'female']
46
- ```
47
-
48
- 如果用户传递了不同于 `male` 或 `female` 的值,就会报错。
49
-
50
- ## 错误列表
51
-
52
- 框架中使用 `rescue_error` 捕获异常,框架能够抛出的异常包括:
53
-
54
- - `Meta::Errors::NoMatchingRoute`:路由不匹配时。
55
- - `Meta::Errors::ParameterInvalid`:参数存在异常时。
56
- - `Meta::Errors::RenderingInvalid`:响应值存在异常时。
57
- - `Meta::Errors::UnsupportedContentType`:框架只支持 `application/json` 的参数格式。当客户端的请求体不是这个格式时,会抛出这个错误。
58
-
59
- ## I18n
60
-
61
- 框架默认提供的语言是 `zh-CN`,可通过文件 `config/locales/zh-CN.yml` 查看可配置的内容。如果需要添加其他语言的支持,需要自行配置。
62
-
63
- ## `lock` 系列方法
64
-
65
- `locked` 方法返回一个新的实体,它将若干选项锁定。例如,锁定某个实体为 `scope: 'full'`:
66
-
67
- ```ruby
68
- # 如下定义一个 Entity
69
- class ArticleEntity < Meta::Entity
70
- property :title, type: 'string'
71
- property :content, type: 'string', scope: 'full'
72
- property :hidden, type: 'boolean', scope: 'o'
73
- end
74
-
75
- # 在 using 时锁定 scope
76
- params do
77
- property :article, using: ArticleEntity.locked(scope: 'full')
78
- end
79
- ```
80
-
81
- 如上,`article` 内容仅包含字段 `title`、`content`.
82
-
83
- 再例如,我们也可以去掉某些指定的字段,这时用到 `exclude: ...` 选项。下面的例子将达到与上面例子等效的结果:
84
-
85
- ```ruby
86
- # 在 using 时去掉某些字段
87
- params do
88
- property :article, using: ArticleEntity.locked(exclude: [:hidden])
89
- end
90
- ```
91
-
92
- 注意 `exclude` 的传递格式,它接受一个数组,并且字段应用符号而不是字符串。
93
-
94
- 最后一个示例是如何处理缺失字段的。在处理请求参数时,我们有时候需要包括缺失字段,有时候需要去掉缺失字段。默认情况下是按照前者处理的,如果需要按照后者的方式处理,需要锁定选项 `discard_missing: true`:
95
-
96
- ```ruby
97
- # 在 using 时不包括缺失字段
98
- params do
99
- property :article, using: ArticleEntity.locked(discard_missing: true)
100
- end
101
- ```
102
-
103
- 我们也可以综合这几个选项(由于综合 `scope` 和 `exclude` 往往没有意义,这里我们只综合 `scope` 和 `discard_missing`):
104
-
105
- ```ruby
106
- params do
107
- property :article, using: ArticleEntity.locked(scope: ['full'], discard_missing: true)
108
- end
109
- ```
110
-
111
- 如上,`scope` 选项也可以传递数组的。
112
-
113
- 除了 `locked` 方法,还包括几个便捷方法。例如 `lock` 方法,它与 `locked` 在某种程度上等价:
114
-
115
- ```ruby
116
- ArticleEntity.lock(:scope, 'full') # 它与 locked(scope: 'full') 等价
117
- ArticleEntity.lock(:discard_missing, true) # 它与 locked(discard_missing: true) 等价
118
- ```
119
-
120
- 还有 `lock_xxx` 便捷方法:
121
-
122
- ```ruby
123
- ArticleEntity.lock_scope('full') # 它与 locked(scope: 'full') 等价
124
- ```
125
-
126
- ## `parameters` 、`request_body` 和 Open API 规格定义
127
-
128
- 在 Open API 中,参数和请求体是分开定义的,它们不属于同一个语义。下面是一个 HTTP 请求的示例:
129
-
130
- ```http
131
- POST /request?foo=foo
132
- X-Bar: bar
133
-
134
- {
135
- "user": ...
136
- }
137
- ```
138
-
139
- 其中 `foo=foo` 和 `X-Bar: bar` 是参数,而 JSON 格式的 `{ "user": ... }` 才是请求体。
140
-
141
- 在 Meta 框架中,为了方便,可以用同一个宏命令(即 `params`)来定义参数和请求体:
142
-
143
- ```ruby
144
- params do
145
- param :foo, in: 'query'
146
- param 'X-Bar', in: 'header'
147
- param :user, type: 'object'
148
- end
149
- ```
150
-
151
- 而事实上,Meta 框架也给出了分开定义参数和请求体的的宏命令。也许有些混淆,`parameters` 宏专用于定义参数,`request_body` 宏用于定义请求体:
152
-
153
- ```ruby
154
- parameters do
155
- param :foo, in: 'query'
156
- param 'X-Bar', in: 'header'
157
- end
158
- request_body do
159
- property :user, type: 'object'
160
- end
161
- ```
162
-
163
- 而在应用中,也许有些混淆,`params`、`parameters`、`request_body` 能够获取到参数和请求体:
164
-
165
- ```ruby
166
- action do
167
- params # 合并获取参数和请求体
168
- parameters # 专用于获取参数
169
- request_body # 专用于获取请求体
170
- end
171
- ```
172
-
173
- 面对这两种使用方式,有何使用上的建议呢?我的建议是,你习惯用哪种就用哪种。
174
-
175
- ## `JsonSchema#filter` 方法的用户选项
176
-
177
- ### `discard_missing:`
178
-
179
- 规定是否忽略缺失的属性。所谓缺失的属性,是指在 `ObjectSchema` 实体宏中定义,但数据中不包含这个键值的属性。你可以将 `discard_missing: true` 视为 HTTP Patch 方法,`discard_missing: false` 视为 HTTP Put 方法。
180
-
181
- ### `extra_properties:`
182
-
183
- 规定多余的属性的处理办法。所谓多余的属性,是指未在 `ObjectSchema` 实体宏中定义,但数据中依然存在这个键值的属性。一般来讲我们允许前端传递一些多余的属性,但可能在内部测试时设定为更严格的条件。
data/examples/lobster.rb DELETED
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # 一个示例 Rack 应用,运行方式:`ruby -Ilib <this-file>`
4
-
5
- require 'zlib'
6
-
7
- # Paste has a Pony, Rack has a Lobster!
8
- class Lobster
9
- LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
10
- P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
11
- t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
12
- I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
13
-
14
- LambdaLobster = lambda { |env|
15
- if env[Rack::QUERY_STRING].include?("flip")
16
- lobster = LobsterString.split("\n").
17
- map { |line| line.ljust(42).reverse }.
18
- join("\n")
19
- href = "?"
20
- else
21
- lobster = LobsterString
22
- href = "?flip"
23
- end
24
-
25
- content = ["<title>Lobstericious!</title>",
26
- "<pre>", lobster, "</pre>",
27
- "<a href='#{href}'>flip!</a>"]
28
- length = content.inject(0) { |a, e| a + e.size }.to_s
29
- [200, { Rack::CONTENT_TYPE => "text/html", Rack::CONTENT_LENGTH => length }, content]
30
- }
31
-
32
- def call(env)
33
- req = Rack::Request.new(env)
34
- if req.GET["flip"] == "left"
35
- lobster = LobsterString.split("\n").map do |line|
36
- line.ljust(42).reverse.
37
- gsub('\\', 'TEMP').
38
- gsub('/', '\\').
39
- gsub('TEMP', '/').
40
- gsub('{', '}').
41
- gsub('(', ')')
42
- end.join("\n")
43
- href = "?flip=right"
44
- elsif req.GET["flip"] == "crash"
45
- raise "Lobster crashed"
46
- else
47
- lobster = LobsterString
48
- href = "?flip=left"
49
- end
50
-
51
- res = Rack::Response.new
52
- res.write "<title>Lobstericious!</title>"
53
- res.write "<pre>"
54
- res.write lobster
55
- res.write "</pre>"
56
- res.write "<p><a href='#{href}'>flip!</a></p>"
57
- res.write "<p><a href='?flip=crash'>crash!</a></p>"
58
- res.finish
59
- end
60
- end
61
-
62
- if $0 == __FILE__
63
- # :nocov:
64
- require 'rack'
65
-
66
- app = Lobster.new # or Lobster::LambdaLobster
67
- Rack::Server.start(
68
- app: Rack::ShowExceptions.new(Rack::Lint.new(app)), Port: 9292
69
- )
70
- # :nocov:
71
- end
@@ -1,3 +0,0 @@
1
- # Demo Rack Application
2
-
3
- 一个示例 Rack 应用,可以看到中间件的用法以及它们如何交互。
@@ -1,6 +0,0 @@
1
- require 'rack'
2
- require './hello.rb'
3
- require './timing.rb'
4
-
5
- use Timing
6
- run Hello
@@ -1,6 +0,0 @@
1
- class Hello
2
- def self.call(env)
3
- puts "Timing Start: #{env['Timing-Start']}"
4
- ['200', {'Content-Type' => 'text/html'}, ['Hello, Rack!']]
5
- end
6
- end
@@ -1,15 +0,0 @@
1
- class Timing
2
- def initialize(app)
3
- @app = app
4
- end
5
-
6
- def call(env)
7
- env['Timing-Start'] = Time.now.to_i
8
-
9
- ts = Time.now
10
- status, headers, body = @app.call(env)
11
- elapsed_time = Time.now - ts
12
- puts "Timing: #{env['REQUEST_METHOD']} #{env['REQUEST_URI']} #{elapsed_time.round(3)}"
13
- return [status, headers, body]
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
-
3
-
4
- # Mark any vendored files as having been vendored.
5
- vendor/* linguist-vendored
@@ -1,23 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile '~/.gitignore_global'
6
-
7
- # Ignore bundler config.
8
- /.bundle
9
-
10
- # Ignore all logfiles and tempfiles.
11
- /log/*
12
- /tmp/*
13
- !/log/.keep
14
- !/tmp/.keep
15
-
16
- # Ignore pidfiles, but keep the directory.
17
- /tmp/pids/*
18
- !/tmp/pids/
19
- !/tmp/pids/.keep
20
-
21
-
22
- # Ignore master key for decrypting credentials and more.
23
- /config/master.key
@@ -1 +0,0 @@
1
- --require spec_helper
@@ -1 +0,0 @@
1
- 3.1.2
@@ -1,29 +0,0 @@
1
- source "https://gems.ruby-china.com"
2
- git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
-
4
- ruby "3.1.2"
5
-
6
- # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7
- gem "rails", "~> 7.0.4"
8
- gem "meta-api", path: "../.."
9
-
10
- # Use the Puma web server [https://github.com/puma/puma]
11
- gem "puma", "~> 5.0"
12
-
13
- # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
14
- gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
15
-
16
- # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
17
- # gem "rack-cors"
18
-
19
- group :development, :test do
20
- # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
21
- gem "debug", platforms: %i[ mri mingw x64_mingw ]
22
- gem 'rspec-rails', '~> 6.0.0'
23
- end
24
-
25
- group :development do
26
- # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
27
- # gem "spring"
28
- end
29
-
@@ -1,190 +0,0 @@
1
- PATH
2
- remote: /home/run/workspace/personal/web-frame
3
- specs:
4
- meta-api (0.0.6)
5
-
6
- GEM
7
- remote: https://gems.ruby-china.com/
8
- specs:
9
- actioncable (7.0.4.3)
10
- actionpack (= 7.0.4.3)
11
- activesupport (= 7.0.4.3)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (7.0.4.3)
15
- actionpack (= 7.0.4.3)
16
- activejob (= 7.0.4.3)
17
- activerecord (= 7.0.4.3)
18
- activestorage (= 7.0.4.3)
19
- activesupport (= 7.0.4.3)
20
- mail (>= 2.7.1)
21
- net-imap
22
- net-pop
23
- net-smtp
24
- actionmailer (7.0.4.3)
25
- actionpack (= 7.0.4.3)
26
- actionview (= 7.0.4.3)
27
- activejob (= 7.0.4.3)
28
- activesupport (= 7.0.4.3)
29
- mail (~> 2.5, >= 2.5.4)
30
- net-imap
31
- net-pop
32
- net-smtp
33
- rails-dom-testing (~> 2.0)
34
- actionpack (7.0.4.3)
35
- actionview (= 7.0.4.3)
36
- activesupport (= 7.0.4.3)
37
- rack (~> 2.0, >= 2.2.0)
38
- rack-test (>= 0.6.3)
39
- rails-dom-testing (~> 2.0)
40
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
- actiontext (7.0.4.3)
42
- actionpack (= 7.0.4.3)
43
- activerecord (= 7.0.4.3)
44
- activestorage (= 7.0.4.3)
45
- activesupport (= 7.0.4.3)
46
- globalid (>= 0.6.0)
47
- nokogiri (>= 1.8.5)
48
- actionview (7.0.4.3)
49
- activesupport (= 7.0.4.3)
50
- builder (~> 3.1)
51
- erubi (~> 1.4)
52
- rails-dom-testing (~> 2.0)
53
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
54
- activejob (7.0.4.3)
55
- activesupport (= 7.0.4.3)
56
- globalid (>= 0.3.6)
57
- activemodel (7.0.4.3)
58
- activesupport (= 7.0.4.3)
59
- activerecord (7.0.4.3)
60
- activemodel (= 7.0.4.3)
61
- activesupport (= 7.0.4.3)
62
- activestorage (7.0.4.3)
63
- actionpack (= 7.0.4.3)
64
- activejob (= 7.0.4.3)
65
- activerecord (= 7.0.4.3)
66
- activesupport (= 7.0.4.3)
67
- marcel (~> 1.0)
68
- mini_mime (>= 1.1.0)
69
- activesupport (7.0.4.3)
70
- concurrent-ruby (~> 1.0, >= 1.0.2)
71
- i18n (>= 1.6, < 2)
72
- minitest (>= 5.1)
73
- tzinfo (~> 2.0)
74
- builder (3.2.4)
75
- concurrent-ruby (1.2.2)
76
- crass (1.0.6)
77
- date (3.3.3)
78
- debug (1.7.1)
79
- irb (>= 1.5.0)
80
- reline (>= 0.3.1)
81
- diff-lcs (1.5.0)
82
- erubi (1.12.0)
83
- globalid (1.1.0)
84
- activesupport (>= 5.0)
85
- i18n (1.12.0)
86
- concurrent-ruby (~> 1.0)
87
- io-console (0.6.0)
88
- irb (1.6.3)
89
- reline (>= 0.3.0)
90
- loofah (2.19.1)
91
- crass (~> 1.0.2)
92
- nokogiri (>= 1.5.9)
93
- mail (2.8.1)
94
- mini_mime (>= 0.1.1)
95
- net-imap
96
- net-pop
97
- net-smtp
98
- marcel (1.0.2)
99
- method_source (1.0.0)
100
- mini_mime (1.1.2)
101
- minitest (5.18.0)
102
- net-imap (0.3.4)
103
- date
104
- net-protocol
105
- net-pop (0.1.2)
106
- net-protocol
107
- net-protocol (0.2.1)
108
- timeout
109
- net-smtp (0.3.3)
110
- net-protocol
111
- nio4r (2.5.8)
112
- nokogiri (1.14.2-x86_64-linux)
113
- racc (~> 1.4)
114
- puma (5.6.5)
115
- nio4r (~> 2.0)
116
- racc (1.6.2)
117
- rack (2.2.6.4)
118
- rack-test (2.1.0)
119
- rack (>= 1.3)
120
- rails (7.0.4.3)
121
- actioncable (= 7.0.4.3)
122
- actionmailbox (= 7.0.4.3)
123
- actionmailer (= 7.0.4.3)
124
- actionpack (= 7.0.4.3)
125
- actiontext (= 7.0.4.3)
126
- actionview (= 7.0.4.3)
127
- activejob (= 7.0.4.3)
128
- activemodel (= 7.0.4.3)
129
- activerecord (= 7.0.4.3)
130
- activestorage (= 7.0.4.3)
131
- activesupport (= 7.0.4.3)
132
- bundler (>= 1.15.0)
133
- railties (= 7.0.4.3)
134
- rails-dom-testing (2.0.3)
135
- activesupport (>= 4.2.0)
136
- nokogiri (>= 1.6)
137
- rails-html-sanitizer (1.5.0)
138
- loofah (~> 2.19, >= 2.19.1)
139
- railties (7.0.4.3)
140
- actionpack (= 7.0.4.3)
141
- activesupport (= 7.0.4.3)
142
- method_source
143
- rake (>= 12.2)
144
- thor (~> 1.0)
145
- zeitwerk (~> 2.5)
146
- rake (13.0.6)
147
- reline (0.3.2)
148
- io-console (~> 0.5)
149
- rspec-core (3.12.1)
150
- rspec-support (~> 3.12.0)
151
- rspec-expectations (3.12.2)
152
- diff-lcs (>= 1.2.0, < 2.0)
153
- rspec-support (~> 3.12.0)
154
- rspec-mocks (3.12.4)
155
- diff-lcs (>= 1.2.0, < 2.0)
156
- rspec-support (~> 3.12.0)
157
- rspec-rails (6.0.1)
158
- actionpack (>= 6.1)
159
- activesupport (>= 6.1)
160
- railties (>= 6.1)
161
- rspec-core (~> 3.11)
162
- rspec-expectations (~> 3.11)
163
- rspec-mocks (~> 3.11)
164
- rspec-support (~> 3.11)
165
- rspec-support (3.12.0)
166
- thor (1.2.1)
167
- timeout (0.3.2)
168
- tzinfo (2.0.6)
169
- concurrent-ruby (~> 1.0)
170
- websocket-driver (0.7.5)
171
- websocket-extensions (>= 0.1.0)
172
- websocket-extensions (0.1.5)
173
- zeitwerk (2.6.7)
174
-
175
- PLATFORMS
176
- x86_64-linux
177
-
178
- DEPENDENCIES
179
- debug
180
- meta-api!
181
- puma (~> 5.0)
182
- rails (~> 7.0.4)
183
- rspec-rails (~> 6.0.0)
184
- tzinfo-data
185
-
186
- RUBY VERSION
187
- ruby 3.1.2p20
188
-
189
- BUNDLED WITH
190
- 2.3.17
@@ -1,11 +0,0 @@
1
- # 测试 Rails 插件
2
-
3
- 这个项目作为 meta-api 框架用作 Rails 插件的测试项目。请按照以下命令运行:
4
-
5
- ```bash
6
- # 安装 gems
7
- $ bundle install
8
-
9
- # 运行测试
10
- $ bin/rails test
11
- ```
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require_relative "config/application"
5
-
6
- Rails.application.load_tasks
@@ -1,7 +0,0 @@
1
- class ApplicationController < ActionController::API
2
- include Meta::Rails::Plugin
3
-
4
- rescue_from Meta::Errors::ParameterInvalid do |e|
5
- render json: e.errors, status: :bad_request
6
- end
7
- end
File without changes
@@ -1,63 +0,0 @@
1
- class DataController < ApplicationController
2
- route '/parse_params', :post do
3
- params do
4
- param :q, in: 'query'
5
- param :user, required: true do
6
- param :name, type: 'string', default: 'Jim'
7
- param :age, type: 'integer', default: 18
8
- param :foo, param: false
9
- end
10
- end
11
- end
12
- def parse_params
13
- render json: { params_on_schema: params_on_schema }
14
- end
15
-
16
- route '/render_hash', :post do
17
- status 200 do
18
- expose :user, required: true do
19
- expose :name, type: 'string', default: 'Jim'
20
- expose :age, type: 'integer', default: 18
21
- end
22
- end
23
- status 201 do
24
- expose :user, required: true do
25
- expose :name, type: 'string', default: 'Jack'
26
- expose :age, type: 'integer', default: 20
27
- end
28
- end
29
- end
30
- def render_hash
31
- render json_on_schema: { 'user' => params[:user].to_unsafe_h }, status: params[:status] || 200, scope: 'foo'
32
- end
33
-
34
- route '/render_object', :post do
35
- status 200 do
36
- expose :user, required: true do
37
- expose :name, type: 'string', default: 'Jim'
38
- expose :age, type: 'integer', default: 18
39
- end
40
- end
41
- end
42
- def render_object
43
- user = Object.new
44
- def user.name; 'Jim'; end
45
- def user.age; 18; end
46
- render json_on_schema: { 'user' => user }
47
- end
48
-
49
- route '/render_with_options', :post do
50
- status 200 do
51
- expose :user, required: true do
52
- expose :a, value: -> { @a }
53
- expose :b, scope: 'foo'
54
- expose :c, scope: 'bar'
55
- expose :d, default: 'd', render: false
56
- end
57
- end
58
- end
59
- def render_with_options
60
- @a = 'aa'
61
- render json_on_schema: { 'user' => params[:user].to_unsafe_hash }, scope: 'foo'
62
- end
63
- end
@@ -1,13 +0,0 @@
1
- class SwaggerController < ApplicationController
2
- def get_spec
3
- # 需要提前加载控制器常量,如以下两种方式:
4
- # - Rails.application.eager_load!
5
- # - Dir.glob(Rails.root.join('app', 'controllers', '**', '*.rb')).each { |f| require f }
6
- #
7
- # 这里仅仅仅仅使用了 require_relative
8
- require_relative 'data_controller'
9
-
10
- doc = Meta::Rails::Plugin.generate_swagger_doc(ApplicationController)
11
- render json: doc
12
- end
13
- end
File without changes
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path("../config/application", __dir__)
3
- require_relative "../config/boot"
4
- require "rails/commands"
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative "../config/boot"
3
- require "rake"
4
- Rake.application.run