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

GTD-2: API reference improvements #48

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d6358f3
Moved rendering into a separate class
lewisnyman Aug 23, 2018
ae6b562
Move operations rendering into a seperate file
lewisnyman Aug 23, 2018
0a59bd0
Moved paramters rendering into a seperate file
lewisnyman Aug 23, 2018
4e27939
Moved responses rendering into a seperate file
lewisnyman Aug 23, 2018
b054506
Add support for enum type in parameters
mikebell Aug 28, 2018
e21bec7
Fix inserting schema objects with api_schema>
mikebell Aug 28, 2018
dabc682
Render schemas below an individual path
lewisnyman Aug 28, 2018
fdbdbc8
Add paragraph tags to enum parameters
lewisnyman Aug 29, 2018
d134307
Add schema link support to nested schema objects. Move functionality …
lewisnyman Aug 29, 2018
8156fa8
Also print schema links to reference within schema array properties
lewisnyman Aug 29, 2018
38b3af1
Add start of json response output
mikebell Aug 29, 2018
35b2386
Simplified the json output generation for the response body
lewisnyman Aug 29, 2018
0d7599f
Lovely pretty JSON
lewisnyman Aug 29, 2018
b601b4e
Display referenced data structures in response bodies
lewisnyman Aug 30, 2018
b315d2d
Remove extra table row and space
mikebell Aug 30, 2018
0b229ec
Support array type in responses
mikebell Aug 30, 2018
61f9b97
Prevented response bodies from breaking page layout
lewisnyman Aug 30, 2018
fd28f5f
Printed nested references to schemas, currently one level deep
lewisnyman Aug 30, 2018
b6cc92f
Recursively render schemas referenced by other schemas referenced by …
lewisnyman Aug 30, 2018
369ae2b
Start of allOf support
mikebell Aug 30, 2018
4a2804c
Merge branch 'json-response-output' of github.com:ConvivioTeam/tech-d…
mikebell Aug 30, 2018
66cb0e6
Render AllOf properties
lewisnyman Aug 30, 2018
8ccf86e
Do not print schema links of properties of referenced schema objects
lewisnyman Aug 30, 2018
31c02fd
Print schema objects referenced in arrays for single paths
lewisnyman Aug 30, 2018
aaef8d5
Add AllOf support to schemas referenced by a single printed path
lewisnyman Aug 30, 2018
b51feec
Support example responses inline
mikebell Sep 6, 2018
f593b79
Pretty print example response
mikebell Sep 6, 2018
aa920b3
Add support for markdown in response descriptions
mikebell Sep 6, 2018
ff44e27
Correctly render nested array and items, with allOf support, in respo…
lewisnyman Sep 6, 2018
5a08292
Merge branch 'json-response-output' into GTD-2-api-reference-improvem…
mikebell Sep 6, 2018
a93c41f
Fixed the rendering of schemas on a single path, the template expects…
lewisnyman Sep 6, 2018
89aa8a1
Fixed linting errors
lewisnyman Sep 6, 2018
b2ce26b
Update tests
lewisnyman Sep 7, 2018
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
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:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most objects constructed by openapi3_parser support .each but not .each_value but Rubocop treats it as a hash.

Copy link
Contributor

@MatMoore MatMoore Sep 7, 2018

Choose a reason for hiding this comment

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

Fair enough. Makes me wonder if we should add #each_value to the parser at some point though (cc @kevindew)

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