Skip to content

Commit

Permalink
Merge pull request #63 from tuwilof/fix_request_json_schema
Browse files Browse the repository at this point in the history
Fix request json schema
  • Loading branch information
tuwilof authored Dec 2, 2024
2 parents df3565e + 5e8f28d commit b539701
Show file tree
Hide file tree
Showing 6 changed files with 1,011 additions and 781 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

### 3.2.5 - 2024-12-02

* bug fixes
* fix request json schema definitions for OpenAPI 3

### 3.2.4 - 2024-08-08

* bug fixes
Expand Down
1 change: 1 addition & 0 deletions lib/tomograph/openapi/openapi2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def to_tomogram
@tomogram ||= @documentation['paths'].each_with_object([]) do |action, result|
action[1].keys.each do |method|
next result if method == 'parameters'

result.push(Tomograph::Tomogram::Action.new(
path: "#{@prefix}#{action[0]}",
method: method.upcase,
Expand Down
32 changes: 31 additions & 1 deletion lib/tomograph/openapi/openapi3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,48 @@ def initialize(prefix, openapi3_yaml_path)
def to_tomogram
@tomogram ||= @documentation['paths'].each_with_object([]) do |(path, action_definition), result|
action_definition.keys.each do |method|
ajj = valuekey(action_definition[method]['requestBody'], 'content')
aj = valuekey(ajj, 'application/json')

result.push(Tomograph::Tomogram::Action.new(
path: "#{@prefix}#{path}",
method: method.upcase,
content_type: action_definition[method]['requestBody'] && action_definition[method]['requestBody']['content'].keys[0] == 'application/json' ? action_definition[method]['requestBody']['content'].keys[0] : '',
requests: [],
requests: [schema_new(valuekey(aj, 'schema'), @documentation['definitions'])].compact,
responses: responses(action_definition[method]['responses']),
resource: ''
))
end
end
end

def valuekey(value, key)
value.nil? ? nil : value[key]
end

def schema_new(sche, defi)
return sche unless sche
if sche.keys.include?('$ref')
res = sche.merge('definitions' => { sche['$ref'][14..-1] => defi[sche['$ref'][14..-1]] })
if defi[sche['$ref'][14..-1]].to_s.include?('$ref')
keys = defi[sche['$ref'][14..-1]].to_s.split('"').find_all { |word| word.include?('definitions') }
keys.each do |key|
res['definitions'].merge!({ key[14..-1] => defi[key[14..-1]] })
end
end
res
elsif sche.to_s.include?('$ref')
res = sche.merge('definitions' => {})
keys = sche.to_s.split('"').find_all { |word| word.include?('definitions') }
keys.each do |key|
res['definitions'].merge!({ key[14..-1] => defi[key[14..-1]] })
end
res
else
sche
end
end

def responses(responses_definitions)
result = []
responses_definitions.each do |(response_code, response)|
Expand Down
2 changes: 1 addition & 1 deletion lib/tomograph/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Tomograph
VERSION = '3.2.4'.freeze
VERSION = '3.2.5'.freeze
end
Loading

0 comments on commit b539701

Please sign in to comment.