oas_rails 0.4.1 → 0.4.3
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: e565b7ee73dcf69c0b137f85039ef4de0e3a8d8b2fe3a4a8871df7141aecc30d
|
4
|
+
data.tar.gz: 56065fc1840d7a4a3ec59083e023ac4aaee4010ac3e34565cae763987dbcb53b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64185e13eb921be737e9536ece390e82632476632fd1a8ad67c5b5e4d75243c597f3d17e5be91b2e1d56bff5b7418955505082c06c7f823daba9a5a1dfcb877f
|
7
|
+
data.tar.gz: 47aa8d96c6dd12afd9c3047e3477f7ac164066f7a2f583a5f6fca8ca288934634b5d9c6911b6a7f08494f7055b6a1c7074004f918f3e65352e5b9043ee4e4af0
|
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,43 +1,43 @@
|
|
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.3
|
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-19 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
|
@@ -45,9 +45,6 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '7.0'
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 7.0.0
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -55,9 +52,6 @@ dependencies:
|
|
55
52
|
- - "~>"
|
56
53
|
- !ruby/object:Gem::Version
|
57
54
|
version: '7.0'
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 7.0.0
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: yard
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.5.
|
153
|
+
rubygems_version: 3.5.11
|
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
|