weak_swagger_parameters 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +16 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/lib/weak_swagger_parameters/controller.rb +65 -0
- data/lib/weak_swagger_parameters/definitions/api.rb +94 -0
- data/lib/weak_swagger_parameters/definitions/body.rb +40 -0
- data/lib/weak_swagger_parameters/definitions/body_param.rb +55 -0
- data/lib/weak_swagger_parameters/definitions/param_container.rb +19 -0
- data/lib/weak_swagger_parameters/definitions/params.rb +23 -0
- data/lib/weak_swagger_parameters/definitions/path.rb +14 -0
- data/lib/weak_swagger_parameters/definitions/path_params/integer.rb +30 -0
- data/lib/weak_swagger_parameters/definitions/path_params/string.rb +30 -0
- data/lib/weak_swagger_parameters/definitions/query.rb +10 -0
- data/lib/weak_swagger_parameters/definitions/query_params/string.rb +30 -0
- data/lib/weak_swagger_parameters/definitions/response.rb +20 -0
- data/lib/weak_swagger_parameters/definitions.rb +12 -0
- data/lib/weak_swagger_parameters/version.rb +4 -0
- data/lib/weak_swagger_parameters.rb +13 -0
- data/weak_swagger_parameters.gemspec +33 -0
- metadata +216 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1115da4842c8121b7889c7dda59162abd282be23
|
4
|
+
data.tar.gz: fce57b9824de4ae255acb77253ff26c6e452755d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d64a8a87628021d0a533dc54d1cce12b38e26eb1137fbee56e4cb56b66bad71641a878ec83afcc789e5274b20ce4d7bfd28b672989c1d4ab653cb195df35ba8
|
7
|
+
data.tar.gz: e60a312ce9abcf379e0f4246906f3c5e68f16f745972d0126ed33af65925b86b8e2e1ea486282eca97a0d3dbc5bef758c2a96e51c59df0d04cca1561a41d059c
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at pirvu.doru@ymail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Pirvu Doru
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Agilefreaks/weak_swagger_parameters.svg?branch=master)](https://travis-ci.org/Agilefreaks/weak_swagger_parameters)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/Agilefreaks/weak_swagger_parameters/badges/gpa.svg)](https://codeclimate.com/github/Agilefreaks/weak_swagger_parameters)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/Agilefreaks/weak_swagger_parameters/badges/coverage.svg)](https://codeclimate.com/github/Agilefreaks/weak_swagger_parameters/coverage)
|
4
|
+
|
5
|
+
# WeakSwaggerParameters
|
6
|
+
|
7
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/weak_swagger_parameters`. To experiment with that code, run `bin/console` for an interactive prompt.
|
8
|
+
|
9
|
+
TODO: Delete this and the text above, and describe your gem
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'weak_swagger_parameters'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install weak_swagger_parameters
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
TODO: Write usage instructions here
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
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).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weak_swagger_parameters. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
40
|
+
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Controller
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def add_to_doc_section(doc_section)
|
8
|
+
@doc_sections ||= []
|
9
|
+
@doc_sections << doc_section
|
10
|
+
end
|
11
|
+
|
12
|
+
def in_doc_section?(doc_section)
|
13
|
+
(@doc_sections || []).include?(doc_section)
|
14
|
+
end
|
15
|
+
|
16
|
+
def api(method, path, description, &block)
|
17
|
+
api_docs = WeakSwaggerParameters::Definitions::Api.new(method, path, description, &block)
|
18
|
+
api_docs.apply_validations(self)
|
19
|
+
api_docs.apply_docs(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
included do
|
24
|
+
extend WeakParameters::Controller
|
25
|
+
include Swagger::Blocks
|
26
|
+
|
27
|
+
rescue_from WeakParameters::ValidationError, with: :handle_param_validation_error
|
28
|
+
|
29
|
+
def render_docs(docs_section)
|
30
|
+
ensure_loaded
|
31
|
+
controllers = controllers_in_docs_section(docs_section)
|
32
|
+
|
33
|
+
render json: Swagger::Blocks.build_root_json(controllers)
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_param_validation_error(e)
|
37
|
+
render json: { message: e.message }, status: 400
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def controllers_in_docs_section(docs_section)
|
43
|
+
controllers = []
|
44
|
+
ObjectSpace.each_object(Class) do |klass|
|
45
|
+
if controller?(klass) && in_docs_section?(klass, docs_section)
|
46
|
+
controllers << klass
|
47
|
+
end
|
48
|
+
end
|
49
|
+
controllers
|
50
|
+
end
|
51
|
+
|
52
|
+
def ensure_loaded
|
53
|
+
Rails.application.eager_load! if !Rails.configuration.eager_load || !Rails.configuration.cache_classes
|
54
|
+
end
|
55
|
+
|
56
|
+
def controller?(klass)
|
57
|
+
klass.ancestors.include?(AbstractController::Base)
|
58
|
+
end
|
59
|
+
|
60
|
+
def in_docs_section?(klass, docs_section)
|
61
|
+
klass.respond_to?(:in_doc_section?) && klass.in_doc_section?(docs_section)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Api
|
5
|
+
attr_writer :description
|
6
|
+
|
7
|
+
def initialize(method, path, summary, &block)
|
8
|
+
@method = method
|
9
|
+
@path = path
|
10
|
+
@summary = summary
|
11
|
+
@param_definition = nil
|
12
|
+
@response_definitions = []
|
13
|
+
@description = nil
|
14
|
+
|
15
|
+
instance_eval(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def params(&block)
|
19
|
+
@param_definition = WeakSwaggerParameters::Definitions::Params.new(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def response(status_code, description)
|
23
|
+
@response_definitions << WeakSwaggerParameters::Definitions::Response.new(status_code, description)
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_validations(controller_class)
|
27
|
+
child_definitions = validation_definitions
|
28
|
+
method = @method
|
29
|
+
|
30
|
+
controller_class.instance_eval do
|
31
|
+
validates method do
|
32
|
+
child_definitions.each { |definition| definition.apply_validations(self) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply_docs(controller_class)
|
38
|
+
child_definitions = doc_definitions
|
39
|
+
path = @path
|
40
|
+
method = http_method
|
41
|
+
operation_params = operation_params(method, controller_class)
|
42
|
+
|
43
|
+
controller_class.instance_eval do
|
44
|
+
swagger_path path do
|
45
|
+
operation method, operation_params do
|
46
|
+
child_definitions.each { |definition| definition.apply_docs(self) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def doc_definitions
|
55
|
+
validation_definitions + @response_definitions
|
56
|
+
end
|
57
|
+
|
58
|
+
def validation_definitions
|
59
|
+
[@param_definition]
|
60
|
+
end
|
61
|
+
|
62
|
+
def http_method
|
63
|
+
known_methods = {
|
64
|
+
create: :post,
|
65
|
+
index: :get,
|
66
|
+
show: :get,
|
67
|
+
destroy: :delete,
|
68
|
+
update: :put
|
69
|
+
}
|
70
|
+
|
71
|
+
known_methods[@method]
|
72
|
+
end
|
73
|
+
|
74
|
+
def operation_params(method, controller_class)
|
75
|
+
name = resource_name(controller_class)
|
76
|
+
{
|
77
|
+
summary: @summary,
|
78
|
+
operationId: operation_id(method, name),
|
79
|
+
tags: [name]
|
80
|
+
}.tap do |h|
|
81
|
+
h[:description] = @description unless @description.blank?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def resource_name(controller_class)
|
86
|
+
controller_class.controller_name.humanize
|
87
|
+
end
|
88
|
+
|
89
|
+
def operation_id(method, name)
|
90
|
+
"#{method}#{name}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Body < ParamContainer
|
5
|
+
def initialize(&block)
|
6
|
+
@required_fields = []
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def string(name, description, options = {})
|
11
|
+
@required_fields << name if options.try(:[], :required)
|
12
|
+
@child_definitions << WeakSwaggerParameters::Definitions::BodyParam.new(:string, name, description, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def boolean(name, description, options = {})
|
16
|
+
@required_fields << name if options.try(:[], :required)
|
17
|
+
@child_definitions << WeakSwaggerParameters::Definitions::BodyParam.new(:boolean, name, description, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def integer(name, description, options = {})
|
21
|
+
@required_fields << name if options.try(:[], :required)
|
22
|
+
@child_definitions << WeakSwaggerParameters::Definitions::BodyParam.new(:integer, name, description, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def apply_docs(parent_node)
|
26
|
+
param_definitions = @child_definitions
|
27
|
+
required_fields = @required_fields
|
28
|
+
|
29
|
+
parent_node.instance_eval do
|
30
|
+
parameter name: :body, in: :body, required: true do
|
31
|
+
schema required: required_fields do
|
32
|
+
schema_node = self
|
33
|
+
param_definitions.each { |definition| definition.apply_docs(schema_node) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class BodyParam
|
5
|
+
def initialize(type, name, description, options = {})
|
6
|
+
@type = type
|
7
|
+
@name = name
|
8
|
+
@description = description
|
9
|
+
@options = options || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply_validations(parent_node)
|
13
|
+
type = @type
|
14
|
+
name = @name
|
15
|
+
validation_options = {}
|
16
|
+
validation_options[:strong] = true
|
17
|
+
validation_options[:required] = @options.key?(:required)
|
18
|
+
validation_options[:only] = @options[:enum] if @options.key?(:enum)
|
19
|
+
|
20
|
+
parent_node.instance_eval { send type, name, validation_options }
|
21
|
+
end
|
22
|
+
|
23
|
+
def apply_docs(parent_node)
|
24
|
+
name = @name
|
25
|
+
property_options = { description: @description }
|
26
|
+
property_options[:default] = @options[:default] if @options.key?(:default)
|
27
|
+
property_options[:enum] = @options[:enum] if @options.key?(:enum)
|
28
|
+
property_options.merge!(swagger_type_options)
|
29
|
+
|
30
|
+
parent_node.instance_eval { property name, property_options }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# rubocop:disable MethodLength
|
36
|
+
def swagger_type_options
|
37
|
+
known_types = {
|
38
|
+
integer: { type: :integer, format: :int32 },
|
39
|
+
long: { type: :integer, format: :int64 },
|
40
|
+
float: { type: :number, format: :float },
|
41
|
+
double: { type: :number, format: :double },
|
42
|
+
string: { type: :string },
|
43
|
+
byte: { type: :string, format: :byte },
|
44
|
+
binary: { type: :string, format: :binary },
|
45
|
+
boolean: { type: :boolean },
|
46
|
+
date: { type: :string, format: :date },
|
47
|
+
dateTime: { type: :string, format: :'date-time' },
|
48
|
+
password: { type: :string, format: :password }
|
49
|
+
}
|
50
|
+
|
51
|
+
known_types[@type]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class ParamContainer
|
5
|
+
def initialize(&block)
|
6
|
+
@child_definitions = []
|
7
|
+
instance_eval(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def apply_validations(parent_node)
|
11
|
+
@child_definitions.each { |definition| definition.apply_validations(parent_node) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def apply_docs(parent_node)
|
15
|
+
@child_definitions.each { |definition| definition.apply_docs(parent_node) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Params < ParamContainer
|
5
|
+
def initialize(&block)
|
6
|
+
@child_definitions = []
|
7
|
+
instance_eval(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def body(&block)
|
11
|
+
@child_definitions << WeakSwaggerParameters::Definitions::Body.new(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def query(&block)
|
15
|
+
@child_definitions << WeakSwaggerParameters::Definitions::Query.new(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def path(&block)
|
19
|
+
@child_definitions << WeakSwaggerParameters::Definitions::Path.new(&block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Path < ParamContainer
|
5
|
+
def string(name, description)
|
6
|
+
@child_definitions << WeakSwaggerParameters::Definitions::PathParams::String.new(name, description)
|
7
|
+
end
|
8
|
+
|
9
|
+
def integer(name, description)
|
10
|
+
@child_definitions << WeakSwaggerParameters::Definitions::PathParams::Integer.new(name, description)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
module PathParams
|
5
|
+
class Integer
|
6
|
+
def initialize(name, description)
|
7
|
+
@name = name
|
8
|
+
@description = description
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply_validations(parent_node)
|
12
|
+
name = @name
|
13
|
+
|
14
|
+
parent_node.instance_eval do
|
15
|
+
integer name, strong: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_docs(parent_node)
|
20
|
+
name = @name
|
21
|
+
description = @description
|
22
|
+
|
23
|
+
parent_node.instance_eval do
|
24
|
+
parameter name: name, type: :integer, format: :int32, in: :path, description: description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
module PathParams
|
5
|
+
class String
|
6
|
+
def initialize(name, description)
|
7
|
+
@name = name
|
8
|
+
@description = description
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply_validations(parent_node)
|
12
|
+
name = @name
|
13
|
+
|
14
|
+
parent_node.instance_eval do
|
15
|
+
string name, strong: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_docs(parent_node)
|
20
|
+
name = @name
|
21
|
+
description = @description
|
22
|
+
|
23
|
+
parent_node.instance_eval do
|
24
|
+
parameter name: name, type: :string, in: :path, description: description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Query < ParamContainer
|
5
|
+
def string(name, description)
|
6
|
+
@child_definitions << WeakSwaggerParameters::Definitions::QueryParams::String.new(name, description)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
module QueryParams
|
5
|
+
class String
|
6
|
+
def initialize(name, description)
|
7
|
+
@name = name
|
8
|
+
@description = description
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply_validations(parent_node)
|
12
|
+
name = @name
|
13
|
+
|
14
|
+
parent_node.instance_eval do
|
15
|
+
string name, strong: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_docs(parent_node)
|
20
|
+
name = @name
|
21
|
+
description = @description
|
22
|
+
|
23
|
+
parent_node.instance_eval do
|
24
|
+
parameter name: name, type: :string, in: :query, description: description
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module WeakSwaggerParameters
|
3
|
+
module Definitions
|
4
|
+
class Response
|
5
|
+
def initialize(status_code, description)
|
6
|
+
@status_code = status_code
|
7
|
+
@description = description
|
8
|
+
end
|
9
|
+
|
10
|
+
def apply_docs(parent_node)
|
11
|
+
status_code = @status_code
|
12
|
+
response_options = { description: @description }
|
13
|
+
|
14
|
+
parent_node.instance_eval do
|
15
|
+
response status_code, response_options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'weak_swagger_parameters/definitions/body_param'
|
3
|
+
require 'weak_swagger_parameters/definitions/path_params/integer'
|
4
|
+
require 'weak_swagger_parameters/definitions/path_params/string'
|
5
|
+
require 'weak_swagger_parameters/definitions/query_params/string'
|
6
|
+
require 'weak_swagger_parameters/definitions/param_container'
|
7
|
+
require 'weak_swagger_parameters/definitions/body'
|
8
|
+
require 'weak_swagger_parameters/definitions/path'
|
9
|
+
require 'weak_swagger_parameters/definitions/query'
|
10
|
+
require 'weak_swagger_parameters/definitions/params'
|
11
|
+
require 'weak_swagger_parameters/definitions/response'
|
12
|
+
require 'weak_swagger_parameters/definitions/api'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails'
|
3
|
+
require 'active_support'
|
4
|
+
require 'weak_parameters'
|
5
|
+
require 'swagger/blocks'
|
6
|
+
|
7
|
+
require 'weak_swagger_parameters/version'
|
8
|
+
require 'weak_swagger_parameters/definitions'
|
9
|
+
require 'weak_swagger_parameters/controller'
|
10
|
+
|
11
|
+
module WeakSwaggerParameters
|
12
|
+
# Your code goes here...
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'weak_swagger_parameters'
|
8
|
+
spec.version = '0.0.1'
|
9
|
+
spec.authors = ['AgileFreaks']
|
10
|
+
spec.email = ['office@agilefreaks.com']
|
11
|
+
|
12
|
+
spec.summary = 'Generate docs and Validate request parameters'
|
13
|
+
spec.description = 'Basic integration between swagger-blocks and weak_parameters'
|
14
|
+
spec.homepage = 'https://github.com/Agilefreaks/weak_swagger_parameters'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'rails', '>= 4', '< 5'
|
23
|
+
spec.add_dependency 'weak_parameters', '~> 0.4'
|
24
|
+
spec.add_dependency 'swagger-blocks', '~> 1.3'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
30
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.4'
|
31
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.42'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weak_swagger_parameters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AgileFreaks
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: weak_parameters
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.4'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.4'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: swagger-blocks
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.12'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.12'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: sqlite3
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.3'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rspec-rails
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '3.4'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '3.4'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec-its
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.2'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.2'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rubocop
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.42'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0.42'
|
159
|
+
description: Basic integration between swagger-blocks and weak_parameters
|
160
|
+
email:
|
161
|
+
- office@agilefreaks.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- ".codeclimate.yml"
|
167
|
+
- ".gitignore"
|
168
|
+
- ".rspec"
|
169
|
+
- ".rubocop.yml"
|
170
|
+
- ".travis.yml"
|
171
|
+
- CODE_OF_CONDUCT.md
|
172
|
+
- Gemfile
|
173
|
+
- LICENSE.txt
|
174
|
+
- README.md
|
175
|
+
- Rakefile
|
176
|
+
- lib/weak_swagger_parameters.rb
|
177
|
+
- lib/weak_swagger_parameters/controller.rb
|
178
|
+
- lib/weak_swagger_parameters/definitions.rb
|
179
|
+
- lib/weak_swagger_parameters/definitions/api.rb
|
180
|
+
- lib/weak_swagger_parameters/definitions/body.rb
|
181
|
+
- lib/weak_swagger_parameters/definitions/body_param.rb
|
182
|
+
- lib/weak_swagger_parameters/definitions/param_container.rb
|
183
|
+
- lib/weak_swagger_parameters/definitions/params.rb
|
184
|
+
- lib/weak_swagger_parameters/definitions/path.rb
|
185
|
+
- lib/weak_swagger_parameters/definitions/path_params/integer.rb
|
186
|
+
- lib/weak_swagger_parameters/definitions/path_params/string.rb
|
187
|
+
- lib/weak_swagger_parameters/definitions/query.rb
|
188
|
+
- lib/weak_swagger_parameters/definitions/query_params/string.rb
|
189
|
+
- lib/weak_swagger_parameters/definitions/response.rb
|
190
|
+
- lib/weak_swagger_parameters/version.rb
|
191
|
+
- weak_swagger_parameters.gemspec
|
192
|
+
homepage: https://github.com/Agilefreaks/weak_swagger_parameters
|
193
|
+
licenses:
|
194
|
+
- MIT
|
195
|
+
metadata: {}
|
196
|
+
post_install_message:
|
197
|
+
rdoc_options: []
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
requirements: []
|
211
|
+
rubyforge_project:
|
212
|
+
rubygems_version: 2.5.1
|
213
|
+
signing_key:
|
214
|
+
specification_version: 4
|
215
|
+
summary: Generate docs and Validate request parameters
|
216
|
+
test_files: []
|