Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples generation #77

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/oas_objs/example_obj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ def process

examples_hash.map do |(name, value)|
value =
if keys_of_value.present? && value.is_a?(Array)
{ value: Hash[keys_of_value.zip(value)] }
elsif value.is_a?(Symbol) && value['$']
RefObj.new(value.to_s.delete('$'), :example).process
else
{ value: value }
end
if keys_of_value.present? && value.is_a?(Array)
{ value: Hash[keys_of_value.zip(value)] }
elsif value.is_a?(Symbol) && value['$']
RefObj.new(value.to_s.delete('$'), :example).process
elsif value.is_a?(Hash) && value.key?(:value)
value
else
{ value: value }
end

{ name => value }
end
[ name, value ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.

end.to_h
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions lib/oas_objs/param_obj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ParamObj < Hash

attr_accessor :processed, :schema

EXTRACTABLE_KEYS = %i[
description examples style explode uniqueItems
].freeze

def initialize(name, param_type, type, required, schema)
self.processed = {
name: name.to_s.delete('!').to_sym,
Expand All @@ -21,19 +25,21 @@ def initialize(name, param_type, type, required, schema)

def process
processed[:schema] = schema.process
desc = schema.processed[:description]
processed[:description] = desc if desc
EXTRACTABLE_KEYS.each { |key| extract_from_schema(key) }
processed
end

def name
processed[:name]
end

def extract_from_schema(key)
processed[key] = processed[:schema].delete(key) if processed[:schema].key?(key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [87/80]

end
end
end
end


__END__

Parameter Object Examples
Expand Down
2 changes: 1 addition & 1 deletion spec/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def clear

desc :example, subject: :examples do
mk -> { example :ExampleA, { }; example :ExampleZ, { } }, doc_will_has_keys: { examples: %i[ ExampleA ExampleZ ] }; clear
mk -> { example :ExampleA, { name: 'BeiGou' } }, get: { ExampleA: [{ name: { value: 'BeiGou' } }] }
mk -> { example :ExampleA, { name: 'BeiGou' } }, get: { ExampleA: { name: { value: 'BeiGou' } } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
Metrics/LineLength: Line is too long. [101/80]

end


Expand Down