Skip to content

Commit

Permalink
Fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisnyman committed Sep 6, 2018
1 parent a93c41f commit 89aa8a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Naming/HeredocDelimiterNaming:

Lint/NestedMethodDefinition:
Enabled: false

Performance/HashEachMethods:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def api(text)
output = @render.path(text)
# Render any schemas referenced in the above path
output += @render.schemas_from_path(text)
output
else
@render.schema(text)
end
Expand All @@ -92,7 +93,6 @@ def api_info
def api_server
@document.servers[0]
end

end
end
end
Expand Down
32 changes: 12 additions & 20 deletions lib/govuk_tech_docs/api_reference/api_reference_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ def schema(text)
schemas = ''
schemas_data = @document.components.schemas
schemas_data.each do |schema_data|

allOf = schema_data[1]["allOf"]
all_of = schema_data[1]["allOf"]
properties = []
if !allOf.blank?
schema_data[1]["allOf"].each do |schema_nested|
if !all_of.blank?
all_of.each do |schema_nested|
schema_nested.properties.each do |property|
properties.push property
end
Expand All @@ -74,9 +73,9 @@ def schemas_from_path(text)
operations = get_operations(path)
# Get all referenced schemas
schemas = []
operations.compact.each do |key, operation|
operations.compact.each_value do |operation|
responses = operation.responses
responses.each do |key,response|
responses.each do |_rkey, response|
if response.content['application/json']
schema = response.content['application/json'].schema
schema_name = get_schema_name(schema.node_context.source_location.to_s)
Expand Down Expand Up @@ -107,9 +106,9 @@ def schemas_from_schema(schema)
if schema.type == 'array'
properties.push schema.items
end
allOf = schema["allOf"]
if !allOf.blank?
allOf.each do |schema_nested|
all_of = schema["allOf"]
if !all_of.blank?
all_of.each do |schema_nested|
schema_nested.properties.each do |property|
properties.push property[1]
end
Expand All @@ -118,7 +117,8 @@ def schemas_from_schema(schema)
properties.each do |property|
# Must be a schema be referenced by another schema
# And not a property of a schema
if property.node_context.referenced_by.to_s.include? '#/components/schemas' and !property.node_context.source_location.to_s.include? '/properties/'
if property.node_context.referenced_by.to_s.include?('#/components/schemas') &&
!property.node_context.source_location.to_s.include?('/properties/')
schema_name = get_schema_name(property.node_context.source_location.to_s)
end
if !schema_name.nil?
Expand All @@ -130,7 +130,6 @@ def schemas_from_schema(schema)
schemas
end


def operations(path, path_id)
output = ''
operations = get_operations(path)
Expand Down Expand Up @@ -198,13 +197,7 @@ def schema_properties(schema_data)
properties_hash[pkey].push schema_properties(items)
end
else
if !property.example.nil?
value = property.example
else
value = property.type
end
properties_hash[pkey] = value
# if $ref return referenced
properties_hash[pkey] = !property.example.nil? ? property.example : property.type
end
end

Expand All @@ -214,7 +207,7 @@ def schema_properties(schema_data)
private

def get_all_of_array(schema)
properties = Array.new
properties = Array.new
if schema.is_a?(Array)
schema = schema[1]
end
Expand Down Expand Up @@ -284,4 +277,3 @@ def get_schema_link(schema)
end
end
end

0 comments on commit 89aa8a1

Please sign in to comment.