oas_core 0.2.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 +4 -4
- data/lib/oas_core/builders/content_builder.rb +8 -1
- data/lib/oas_core/builders/request_body_builder.rb +1 -2
- data/lib/oas_core/json_schema_generator.rb +3 -0
- data/lib/oas_core/version.rb +1 -1
- data/lib/oas_core/yard/oas_core_factory.rb +7 -5
- data/lib/oas_core/yard/request_body_tag.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f30441b4a84ba035b6731c1051d0a4572e9e60a45d806ec55b80ccc1e288735e
|
4
|
+
data.tar.gz: 41e0abe3e0533a72b5713e0d243ac35d3cd8a0a1f0427f7157aceda38c19f1f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
46
|
+
@content_type => @media_type
|
40
47
|
}
|
41
48
|
end
|
42
49
|
end
|
@@ -19,8 +19,7 @@ module OasCore
|
|
19
19
|
|
20
20
|
def from_tags(tag:, examples_tags: [])
|
21
21
|
@request_body.description = tag.text
|
22
|
-
@request_body.content = ContentBuilder.new(@specification,
|
23
|
-
: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
|
24
23
|
@request_body.required = tag.required
|
25
24
|
|
26
25
|
self
|
@@ -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
|
data/lib/oas_core/version.rb
CHANGED
@@ -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
|
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
|