oas_core 0.1.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f1ed49861556546b0712b0bf9db58ba28ac53f70e5de3d2276ef45d706b0e34
4
- data.tar.gz: dd3a8d125eb474036e48dc78722cf82ec3341760f903edf2ab4908eb011d6025
3
+ metadata.gz: f30441b4a84ba035b6731c1051d0a4572e9e60a45d806ec55b80ccc1e288735e
4
+ data.tar.gz: 41e0abe3e0533a72b5713e0d243ac35d3cd8a0a1f0427f7157aceda38c19f1f7
5
5
  SHA512:
6
- metadata.gz: ee76879d24af4ffe84279586567edbffd20328aa3d742fc36be9f25a79e218fd0496c87b497a939a534f555dd1c0b285ad7e21e8f8058cd49a8df6f20763dd1f
7
- data.tar.gz: ee8f32f1ab91af11aa5ccc56f60d63e32fa50d4e55a3211a7955ef3183df028533bc520038f23c889322742eb79d0de1db6ba7e5f3486d4802abd84a3a0d969b
6
+ metadata.gz: 8058d16bde405b7be785105bc065fe75e832639effb814109518351238adf1998cc28647017046cf9a41c6f01c95ec0f6e84f629e3e35035db6862559e202cff
7
+ data.tar.gz: 0740a659814ed9d2f6e2b0070e784924e0945c25316fad1ad9dea7f286dcebeb965e63ea20b5cbde5d94c3e49f8ced0c9f60662dd169ada03df562dabd335bc4
@@ -7,6 +7,7 @@ module OasCore
7
7
  @context = context || :incoming
8
8
  @specification = specification
9
9
  @media_type = Spec::MediaType.new(specification)
10
+ @content_type = 'application/json'
10
11
  end
11
12
 
12
13
  def with_schema(schema)
@@ -21,6 +22,12 @@ module OasCore
21
22
  self
22
23
  end
23
24
 
25
+ def with_content_type(content_type)
26
+ @content_type = content_type if content_type && !content_type.empty?
27
+
28
+ self
29
+ end
30
+
24
31
  def with_examples_from_tags(tags)
25
32
  @media_type.examples = @media_type.examples.merge(tags.each_with_object({}).with_index(1) do |(example, result), _index|
26
33
  key = example.text.downcase.gsub(' ', '_')
@@ -36,7 +43,7 @@ module OasCore
36
43
 
37
44
  def build
38
45
  {
39
- 'application/json': @media_type
46
+ @content_type => @media_type
40
47
  }
41
48
  end
42
49
  end
@@ -10,9 +10,6 @@ module OasCore
10
10
 
11
11
  def from_oas_route(oas_route)
12
12
  tag_request_body = oas_route.tags(:request_body).first
13
- # TODO: This is for frameowkr specific.
14
- # if tag_request_body.nil? && OasCore.config.autodiscover_request_body
15
- # detect_request_body(oas_route) if %w[create update].include? oas_route.method_name
16
13
  return self if tag_request_body.nil?
17
14
 
18
15
  from_tags(tag: tag_request_body, examples_tags: oas_route.tags(:request_body_example))
@@ -22,8 +19,7 @@ module OasCore
22
19
 
23
20
  def from_tags(tag:, examples_tags: [])
24
21
  @request_body.description = tag.text
25
- @request_body.content = ContentBuilder.new(@specification,
26
- :incoming).with_schema(tag.schema).with_examples_from_tags(examples_tags).build
22
+ @request_body.content = ContentBuilder.new(@specification, :incoming).with_schema(tag.schema).with_examples_from_tags(examples_tags).with_content_type(tag.content_type).build
27
23
  @request_body.required = tag.required
28
24
 
29
25
  self
@@ -27,18 +27,6 @@ module OasCore
27
27
  self
28
28
  end
29
29
 
30
- # def add_autodiscovered_responses(oas_route)
31
- # return self if !OasCore.config.autodiscover_responses || oas_route.tags(:response).any?
32
- #
33
- # new_responses = Extractors::RenderResponseExtractor.extract_responses_from_source(@specification, source: oas_route.source_string)
34
- #
35
- # new_responses.each do |new_response|
36
- # @responses.add_response(new_response) if @responses.responses[new_response.code].blank?
37
- # end
38
- #
39
- # self
40
- # end
41
-
42
30
  def add_default_responses(oas_route, security)
43
31
  return self unless OasCore.config.set_default_responses
44
32
 
@@ -3,33 +3,24 @@
3
3
  module OasCore
4
4
  class Configuration
5
5
  attr_accessor :info,
6
- :layout,
7
6
  :default_tags_from,
8
- :autodiscover_request_body,
9
- :autodiscover_responses,
10
7
  :api_path,
11
- :ignored_actions,
12
8
  :security_schemas,
13
9
  :authenticate_all_routes_by_default,
14
10
  :set_default_responses,
15
11
  :possible_default_responses,
16
12
  :http_verbs,
17
- :use_model_names,
18
- :rapidoc_theme
13
+ :use_model_names
19
14
 
20
- attr_reader :servers, :tags, :security_schema, :include_mode, :response_body_of_default
15
+ attr_reader :servers, :tags, :security_schema, :response_body_of_default
21
16
 
22
17
  def initialize
23
18
  @info = Spec::Info.new
24
- @layout = false
25
19
  @servers = default_servers
26
20
  @tags = []
27
21
  @swagger_version = '3.1.0'
28
22
  @default_tags_from = :namespace
29
- @autodiscover_request_body = true
30
- @autodiscover_responses = true
31
23
  @api_path = '/'
32
- @ignored_actions = []
33
24
  @authenticate_all_routes_by_default = true
34
25
  @security_schema = nil
35
26
  @security_schemas = {}
@@ -38,9 +29,8 @@ module OasCore
38
29
  unprocessable_entity]
39
30
  @http_verbs = %i[get post put patch delete]
40
31
  @response_body_of_default = 'Hash{ status: !Integer, error: String }'
32
+ # TODO: What does this config??
41
33
  @use_model_names = false
42
- @rapidoc_theme = :rails
43
- @include_mode = :all
44
34
 
45
35
  @possible_default_responses.each do |response|
46
36
  method_name = "response_body_of_#{response}="
@@ -85,13 +75,6 @@ module OasCore
85
75
  []
86
76
  end
87
77
 
88
- def include_mode=(value)
89
- valid_modes = %i[all with_tags explicit]
90
- raise ArgumentError, "include_mode must be one of #{valid_modes}" unless valid_modes.include?(value)
91
-
92
- @include_mode = value
93
- end
94
-
95
78
  def response_body_of_default=(value)
96
79
  raise ArgumentError, 'response_body_of_default must be a String With a valid object' unless value.is_a?(String)
97
80
 
@@ -116,6 +116,7 @@ module OasCore
116
116
  #
117
117
  # @param type [Symbol, String] The Ruby data type.
118
118
  # @return [Hash, String] The JSON schema type or a hash with additional format information.
119
+ # rubocop:disable Metrics/CyclomaticComplexity
119
120
  def self.ruby_type_to_json_schema_type(type)
120
121
  case type.to_s.downcase
121
122
  when 'string' then { type: 'string' }
@@ -127,8 +128,10 @@ module OasCore
127
128
  when 'nil' then { type: 'null' }
128
129
  when 'date' then { type: 'string', format: 'date' }
129
130
  when 'datetime' then { type: 'string', format: 'date-time' }
131
+ when 'file' then { type: 'string', format: 'binary' }
130
132
  else type.to_s.downcase
131
133
  end
132
134
  end
135
+ # rubocop:enable Metrics/CyclomaticComplexity
133
136
  end
134
137
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OasCore
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -8,8 +8,8 @@ module OasCore
8
8
  # @param text [String] The tag text to parse.
9
9
  # @return [RequestBodyTag] The parsed request body tag object.
10
10
  def parse_tag_with_request_body(tag_name, text)
11
- description, klass, schema, required = extract_description_and_schema(text.squish)
12
- RequestBodyTag.new(tag_name, description, klass, schema:, required:)
11
+ description, klass, schema, required, content_type = extract_description_and_schema(text.squish)
12
+ RequestBodyTag.new(tag_name, description, klass, schema:, required:, content_type:)
13
13
  end
14
14
 
15
15
  # Parses a tag that represents a request body example.
@@ -69,11 +69,13 @@ module OasCore
69
69
 
70
70
  # Specific method to extract description and schema for request body tags.
71
71
  # @param text [String] The text to parse.
72
- # @return [Array] An array containing the description, class, schema, and required flag.
72
+ # @return [Array] An array containing the description, class, schema, required flag and content type.
73
73
  def extract_description_and_schema(text)
74
74
  description, type, = extract_description_type_and_content(text)
75
+ description, content_type = extract_text_and_parentheses_content(description)
76
+
75
77
  klass, schema, required = type_text_to_schema(type)
76
- [description, klass, schema, required]
78
+ [description, klass, schema, required, content_type]
77
79
  end
78
80
 
79
81
  # Specific method to extract name, location, and schema for parameters.
@@ -122,7 +124,7 @@ module OasCore
122
124
  # @param input [String] The input text to parse.
123
125
  # @return [Array] An array containing the name and location.
124
126
  def extract_text_and_parentheses_content(input)
125
- return unless input =~ /^(.+?)\(([^)]+)\)/
127
+ return input unless input =~ /^(.+?)\(([^)]+)\)/
126
128
 
127
129
  text = ::Regexp.last_match(1).strip
128
130
  parenthesis_content = ::Regexp.last_match(2).strip
@@ -3,14 +3,15 @@
3
3
  module OasCore
4
4
  module YARD
5
5
  class RequestBodyTag < ::YARD::Tags::Tag
6
- attr_accessor :klass, :schema, :required
6
+ attr_accessor :klass, :schema, :required, :content_type
7
7
 
8
- def initialize(tag_name, text, klass, schema: {}, required: false)
8
+ def initialize(tag_name, text, klass, schema: {}, required: false, content_type: 'application/json')
9
9
  # initialize(tag_name, text, types = nil, name = nil)
10
10
  super(tag_name, text, nil, nil)
11
11
  @klass = klass
12
12
  @schema = schema
13
13
  @required = required
14
+ @content_type = content_type
14
15
  end
15
16
  end
16
17
  end
data/lib/oas_core.rb CHANGED
@@ -57,9 +57,10 @@ module OasCore
57
57
  end
58
58
 
59
59
  class << self
60
- def configure
61
- OasCore.configure_yard!
62
- yield config
60
+ def config=(config)
61
+ raise 'Configuration must be an OasCore::Configuration or its subclass' unless config.is_a?(OasCore::Configuration)
62
+
63
+ @config = config
63
64
  end
64
65
 
65
66
  def config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon