oas_rails 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/oas_rails/builders/content_builder.rb +1 -1
- data/lib/oas_rails/builders/esquema_builder.rb +39 -0
- data/lib/oas_rails/extractors/render_response_extractor.rb +1 -1
- data/lib/oas_rails/spec/parameter.rb +6 -3
- data/lib/oas_rails/spec/specable.rb +8 -5
- data/lib/oas_rails/utils.rb +1 -1
- data/lib/oas_rails/version.rb +1 -1
- data/lib/oas_rails.rb +1 -1
- metadata +10 -16
- data/lib/oas_rails/esquema_builder.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99f785633c605daf49dae444252b0bf2782a98621be1ead063bdd0d1ffb26014
|
4
|
+
data.tar.gz: d2b8f108c8fd8ceab1a286247cb5763663ecd1b6d87bb97677bdf09fe25917c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c30ec251db3f3397e3adc78974f80fd74fa4bfc4ad21385f9b9a120a12d8d8ac8655bd815be60e1b4769898f297cb5816f8851b23fd78eadb5ec0df14c21dd89
|
7
|
+
data.tar.gz: 2b4e29a8d2e47a4e7e9142b44a80d0a6504d93d3bca72cfe4b3a18fcbe111fdbd743876d678163099e64a04e192ec515197b5a831245c2487611f284e9ec6cec
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
![Gem Version](https://img.shields.io/gem/v/oas_rails)
|
2
|
-
![GitHub License](https://img.shields.io/github/license/a-chacon/oas_rails)
|
1
|
+
![Gem Version](https://img.shields.io/gem/v/oas_rails?color=E9573F)
|
2
|
+
![GitHub License](https://img.shields.io/github/license/a-chacon/oas_rails?color=blue)
|
3
3
|
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/a-chacon/oas_rails/.github%2Fworkflows%2Frubyonrails.yml)
|
4
|
+
![Gem Total Downloads](https://img.shields.io/gem/dt/oas_rails)
|
5
|
+
![Static Badge](https://img.shields.io/badge/Rails-%3E%3D7.0.0-%23E9573F)
|
6
|
+
![Static Badge](https://img.shields.io/badge/Ruby-%3E%3D3.1.0-%23E9573F)
|
4
7
|
|
5
8
|
# Open API Specification For Rails
|
6
9
|
|
@@ -35,7 +35,7 @@ module OasRails
|
|
35
35
|
def from_model_class(klass)
|
36
36
|
return self unless klass.ancestors.include? ActiveRecord::Base
|
37
37
|
|
38
|
-
model_schema = EsquemaBuilder.send("build_#{@context}_schema", klass:)
|
38
|
+
model_schema = Builders::EsquemaBuilder.send("build_#{@context}_schema", klass:)
|
39
39
|
model_schema["required"] = []
|
40
40
|
schema = { type: "object", properties: { klass.to_s.downcase => model_schema } }
|
41
41
|
examples = Spec::MediaType.search_for_examples_in_tests(klass, context: @context)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module OasRails
|
2
|
+
module Builders
|
3
|
+
module EsquemaBuilder
|
4
|
+
class << self
|
5
|
+
# Builds a schema for a class when it is used as incoming API data.
|
6
|
+
#
|
7
|
+
# @param klass [Class] The class for which the schema is built.
|
8
|
+
# @return [Hash] The schema as a JSON-compatible hash.
|
9
|
+
def build_incoming_schema(klass:, model_to_schema_class: Esquema)
|
10
|
+
configure_common_settings
|
11
|
+
model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_incoming
|
12
|
+
|
13
|
+
model_to_schema_class::Builder.new(klass).build_schema.as_json
|
14
|
+
end
|
15
|
+
|
16
|
+
# Builds a schema for a class when it is used as outgoing API data.
|
17
|
+
#
|
18
|
+
# @param klass [Class] The class for which the schema is built.
|
19
|
+
# @return [Hash] The schema as a JSON-compatible hash.
|
20
|
+
def build_outgoing_schema(klass:, model_to_schema_class: Esquema)
|
21
|
+
configure_common_settings
|
22
|
+
model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_outgoing
|
23
|
+
|
24
|
+
model_to_schema_class::Builder.new(klass).build_schema.as_json
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Configures common settings for schema building.
|
30
|
+
#
|
31
|
+
# Excludes associations and foreign keys from the schema.
|
32
|
+
def configure_common_settings
|
33
|
+
Esquema.configuration.exclude_associations = true
|
34
|
+
Esquema.configuration.exclude_foreign_keys = true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -61,7 +61,7 @@ module OasRails
|
|
61
61
|
klass = maybe_a_model.singularize.camelize(:upper).constantize
|
62
62
|
|
63
63
|
if klass.ancestors.include?(ActiveRecord::Base)
|
64
|
-
schema = EsquemaBuilder.build_outgoing_schema(klass:)
|
64
|
+
schema = Builders::EsquemaBuilder.build_outgoing_schema(klass:)
|
65
65
|
if test_singularity(maybe_a_model)
|
66
66
|
build_singular_model_schema_and_examples(maybe_a_model, errors, klass, schema)
|
67
67
|
else
|
@@ -6,7 +6,8 @@ module OasRails
|
|
6
6
|
|
7
7
|
STYLE_DEFAULTS = { query: 'form', path: 'simple', header: 'simple', cookie: 'form' }.freeze
|
8
8
|
|
9
|
-
attr_accessor :name, :
|
9
|
+
attr_accessor :name, :style, :description, :required, :schema
|
10
|
+
attr_reader :in
|
10
11
|
|
11
12
|
def initialize(specification)
|
12
13
|
@specification = specification
|
@@ -18,8 +19,10 @@ module OasRails
|
|
18
19
|
@schema = { type: 'string' }
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
22
|
+
def in=(value)
|
23
|
+
@in = value
|
24
|
+
@style = STYLE_DEFAULTS[@in.to_sym]
|
25
|
+
@required = true if value == "path"
|
23
26
|
end
|
24
27
|
|
25
28
|
def required?
|
@@ -18,8 +18,6 @@ module OasRails
|
|
18
18
|
elsif value.is_a?(Array) && value.all? { |elem| elem.respond_to?(:to_spec) }
|
19
19
|
value.map(&:to_spec)
|
20
20
|
# elsif value.is_a?(Hash)
|
21
|
-
# p "Here"
|
22
|
-
# p value
|
23
21
|
# hash = {}
|
24
22
|
# value.each do |key, object|
|
25
23
|
# hash[key] = object.to_spec
|
@@ -29,18 +27,23 @@ module OasRails
|
|
29
27
|
value
|
30
28
|
end
|
31
29
|
|
32
|
-
|
33
|
-
hash[camel_case_key] = processed_value unless processed_value.nil?
|
30
|
+
hash[camel_case_key] = processed_value unless valid_processed_value?(processed_value)
|
34
31
|
end
|
35
32
|
hash
|
36
33
|
end
|
37
34
|
|
38
|
-
|
35
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
36
|
+
def as_json(options = nil)
|
39
37
|
to_spec
|
40
38
|
end
|
39
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
41
40
|
|
42
41
|
private
|
43
42
|
|
43
|
+
def valid_processed_value?(processed_value)
|
44
|
+
((processed_value.is_a?(Hash) || processed_value.is_a?(Array)) && processed_value.empty?) || processed_value.nil?
|
45
|
+
end
|
46
|
+
|
44
47
|
def snake_to_camel(snake_str)
|
45
48
|
words = snake_str.to_s.split('_')
|
46
49
|
words[1..].map!(&:capitalize)
|
data/lib/oas_rails/utils.rb
CHANGED
@@ -80,7 +80,7 @@ module OasRails
|
|
80
80
|
if status.to_s =~ /^\d+$/
|
81
81
|
status.to_i
|
82
82
|
else
|
83
|
-
status = "unprocessable_content" if status == "unprocessable_entity"
|
83
|
+
# status = "unprocessable_content" if status == "unprocessable_entity"
|
84
84
|
Rack::Utils::SYMBOL_TO_STATUS_CODE[status.to_sym]
|
85
85
|
end
|
86
86
|
end
|
data/lib/oas_rails/version.rb
CHANGED
data/lib/oas_rails.rb
CHANGED
@@ -9,7 +9,6 @@ module OasRails
|
|
9
9
|
autoload :Configuration, "oas_rails/configuration"
|
10
10
|
autoload :OasRoute, "oas_rails/oas_route"
|
11
11
|
autoload :Utils, "oas_rails/utils"
|
12
|
-
autoload :EsquemaBuilder, "oas_rails/esquema_builder"
|
13
12
|
|
14
13
|
module Builders
|
15
14
|
autoload :OperationBuilder, "oas_rails/builders/operation_builder"
|
@@ -20,6 +19,7 @@ module OasRails
|
|
20
19
|
autoload :ParametersBuilder, "oas_rails/builders/parameters_builder"
|
21
20
|
autoload :ParameterBuilder, "oas_rails/builders/parameter_builder"
|
22
21
|
autoload :RequestBodyBuilder, "oas_rails/builders/request_body_builder"
|
22
|
+
autoload :EsquemaBuilder, "oas_rails/builders/esquema_builder"
|
23
23
|
end
|
24
24
|
|
25
25
|
# This module contains all the clases that represent a part of the OAS file.
|
metadata
CHANGED
@@ -1,51 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a-chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: method_source
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: model-to-schema
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.1.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '7.0'
|
48
|
-
- - ">="
|
49
46
|
- !ruby/object:Gem::Version
|
50
47
|
version: 7.0.0
|
51
48
|
type: :runtime
|
@@ -53,9 +50,6 @@ dependencies:
|
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - "~>"
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '7.0'
|
58
|
-
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: 7.0.0
|
61
55
|
- !ruby/object:Gem::Dependency
|
@@ -101,6 +95,7 @@ files:
|
|
101
95
|
- lib/generators/oas_rails/config/templates/oas_rails_initializer.rb
|
102
96
|
- lib/oas_rails.rb
|
103
97
|
- lib/oas_rails/builders/content_builder.rb
|
98
|
+
- lib/oas_rails/builders/esquema_builder.rb
|
104
99
|
- lib/oas_rails/builders/operation_builder.rb
|
105
100
|
- lib/oas_rails/builders/parameter_builder.rb
|
106
101
|
- lib/oas_rails/builders/parameters_builder.rb
|
@@ -110,7 +105,6 @@ files:
|
|
110
105
|
- lib/oas_rails/builders/responses_builder.rb
|
111
106
|
- lib/oas_rails/configuration.rb
|
112
107
|
- lib/oas_rails/engine.rb
|
113
|
-
- lib/oas_rails/esquema_builder.rb
|
114
108
|
- lib/oas_rails/extractors/oas_route_extractor.rb
|
115
109
|
- lib/oas_rails/extractors/render_response_extractor.rb
|
116
110
|
- lib/oas_rails/extractors/route_extractor.rb
|
@@ -156,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
150
|
- !ruby/object:Gem::Version
|
157
151
|
version: '0'
|
158
152
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.3.3
|
160
154
|
signing_key:
|
161
155
|
specification_version: 4
|
162
156
|
summary: OasRails is a Rails engine for generating automatic interactive documentation
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module EsquemaBuilder
|
3
|
-
class << self
|
4
|
-
# Builds a schema for a class when it is used as incoming API data.
|
5
|
-
#
|
6
|
-
# @param klass [Class] The class for which the schema is built.
|
7
|
-
# @return [Hash] The schema as a JSON-compatible hash.
|
8
|
-
def build_incoming_schema(klass:)
|
9
|
-
configure_common_settings
|
10
|
-
Esquema.configuration.excluded_columns = OasRails.config.excluded_columns_incoming
|
11
|
-
|
12
|
-
Esquema::Builder.new(klass).build_schema.as_json
|
13
|
-
end
|
14
|
-
|
15
|
-
# Builds a schema for a class when it is used as outgoing API data.
|
16
|
-
#
|
17
|
-
# @param klass [Class] The class for which the schema is built.
|
18
|
-
# @return [Hash] The schema as a JSON-compatible hash.
|
19
|
-
def build_outgoing_schema(klass:)
|
20
|
-
configure_common_settings
|
21
|
-
Esquema.configuration.excluded_columns = OasRails.config.excluded_columns_outgoing
|
22
|
-
|
23
|
-
Esquema::Builder.new(klass).build_schema.as_json
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# Configures common settings for schema building.
|
29
|
-
#
|
30
|
-
# Excludes associations and foreign keys from the schema.
|
31
|
-
def configure_common_settings
|
32
|
-
Esquema.configuration.exclude_associations = true
|
33
|
-
Esquema.configuration.exclude_foreign_keys = true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|