Skip to content
Open
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
183 changes: 96 additions & 87 deletions src/doc_generator/swagger_doc_generator.e
Original file line number Diff line number Diff line change
Expand Up @@ -6,126 +6,135 @@ note

class
SWAGGER_DOC_GENERATOR

inherit

STRING_HANDLER

create
make

feature

parser: EIFFEL_PARSER
factory: AST_ROUNDTRIP_FACTORY

factory: AST_FACTORY

swagger_object_creator: SWAGGER_OBJECT_CREATOR

annotation_validator: ANNOTATION_VALIDATOR_VISITOR

json_creator: JSON_GENERATOR

feature

make
do
initialize
end
do
create annotation_validator
create swagger_object_creator.make
create json_creator.make
initialize
end

feature {NONE}

initialize
--initialize the documentation generator
do
create factory
create parser.make_with_factory (factory)
create annotation_validator
create swagger_object_creator.make
create json_creator.make
parser.set_il_parser
parser.set_syntax_version (parser.transitional_syntax)
end

read_file(path: PATH): STRING
-- reads a file into a string, returns the string
require
path_not_void: path /= void
local
file: KL_BINARY_INPUT_FILE_32
count, nb: INTEGER
do
result := ""
if
attached path as p and then
attached p.extension as ext and then
ext.is_case_insensitive_equal("e")
then
create file.make_with_path (p)
if file.exists then
count := file.count
file.open_read
if file.is_open_read then
if result.count < count then
result.resize (count)
--initialize the documentation generator
do
create factory
create parser.make_with_factory (factory)
-- create annotation_validator
-- create swagger_object_creator.make
-- create json_creator.make
parser.set_il_parser
parser.set_syntax_version (parser.transitional_syntax)
parser.set_has_syntax_warning (False)
end

read_file (path: PATH): STRING
-- reads a file into a string, returns the string
require
path_not_void: path /= void
local
file: KL_BINARY_INPUT_FILE_32
count, nb: INTEGER

do
result := ""
if attached path as p and then attached p.extension as ext and then ext.is_case_insensitive_equal ("e") then
create file.make_with_path (p)
if file.exists then
count := file.count
file.open_read
if file.is_open_read then
if result.count < count then
result.resize (count)
end
result.set_count (count)
nb := file.read_to_string (result, 1, count)
result.set_count (nb)
file.close
else
io.error.put_string ("Couldn't open: " + p.utf_8_name)
io.error.put_new_line
end
result.set_count (count)
nb := file.read_to_string (result, 1, count)
result.set_count (nb)
file.close
else
io.error.put_string ("Couldn't open: " + p.utf_8_name)
io.error.put_string ("Couldn't find: " + p.utf_8_name)
io.error.put_new_line
end
else
io.error.put_string ("Couldn't find: " + p.utf_8_name)
io.error.put_new_line
end
end
end

feature {NONE}

swagger_object: SWAGGER_OBJECT

feature

create_documentation(path_to_folder: STRING)
-- creates documentation from a *.e file
require
path_not_void: path_to_folder /= void
local
current_file: KL_BINARY_INPUT_FILE_32
directory: DIRECTORY
classes: LINKED_LIST[CLASS_AS]
do
create classes.make
create directory.make_with_path (create {PATH}.make_from_string (path_to_folder))

across directory.entries as files
loop
if attached files.item as f and then
attached files.item.extension as e and then
files.item.extension.same_string ("e")
then
create current_file.make_with_path (directory.path.extended_path (f))
current_file.open_read
io.putstring ("parsing file " + f.out + "%N")
if current_file.is_open_read then
parser.parse_class_from_file (current_file, Void, Void)
end
current_file.close
if parser.error_count = 0 then
classes.extend (parser.root_node)
else
io.putstring ("error while parsing " + f.out + ":%N")
io.putstring (parser.error_message + "%N")
create_documentation (path_to_folder: STRING)
-- creates documentation from a *.e file
require
path_not_void: path_to_folder /= void
local
current_file: KL_BINARY_INPUT_FILE_32
directory: DIRECTORY
classes: LINKED_LIST [CLASS_AS]
do
create classes.make
create directory.make_with_path (create {PATH}.make_from_string (path_to_folder))
across
directory.entries as files
loop
if attached files.item as f and then attached files.item.extension as e and then files.item.extension.same_string ("e") then
create current_file.make_with_path (directory.path.extended_path (f))
current_file.open_read
io.putstring ("parsing file " + f.out + "%N")
if current_file.is_open_read then
parser.parse (current_file)
end
current_file.close
if parser.error_count = 0 then
classes.extend (parser.root_node)
parser.reset
initialize
else
io.putstring ("error while parsing " + f.out + ":%N")
io.put_string (parser.error_code.out)
io.putstring (parser.error_message + "%N")
end
parser.wipe_out
end
parser.reset_nodes
parser.reset
end
io.putstring ("validating annotations%N")
annotation_validator.validate_classes (classes)
if annotation_validator.all_annotations_valid then
io.putstring ("starting to scan classes for swagger annotations%N")
swagger_object_creator.create_swagger_object (classes)
io.putstring ("creating JSON file%N")
json_creator.process_swagger_object (swagger_object_creator.swagger_object)
io.putstring ("done")
end
end
io.putstring ("validating annotations%N")
annotation_validator.validate_classes (classes)
if annotation_validator.all_annotations_valid then
io.putstring ("starting to scan classes for swagger annotations%N")
swagger_object_creator.create_swagger_object (classes)
io.putstring ("creating JSON file%N")
json_creator.process_swagger_object (swagger_object_creator.swagger_object)
io.putstring ("done")
end
end

invariant
parser_not_void: parser /= void
Expand Down
8 changes: 4 additions & 4 deletions src/swagger_documentation_generation.ecf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="environment" location="\home\tobias\i_ti_eytsch\eiffel\svn\15.01_dev\framework\environment\environment.ecf"/>
<library name="file_utilities" location="\home\tobias\i_ti_eytsch\eiffel\svn\15.01_dev\framework\file_utilities\file_utilities.ecf"/>
<library name="parser" location="\home\tobias\i_ti_eytsch\eiffel\svn\15.01_dev\framework\parser\parser.ecf"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="environment" location="$ISE_LIBRARY\framework\environment\environment.ecf"/>
<library name="file_utilities" location="$ISE_LIBRARY\framework\file_utilities\file_utilities.ecf"/>
<library name="parser" location="$ISE_LIBRARY\framework\parser\parser.ecf"/>
<cluster name="swagger_documentation_generation" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/application.e
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ feature {NONE} -- Initialization
-- Run application.
do
create doc_generator.make
doc_generator.create_documentation (".")
doc_generator.create_documentation (".\classes")
end

feature
Expand Down
46 changes: 46 additions & 0 deletions test/integration/classes/test_class.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
note
description: "Summary description for {TEST_CLASS}."
author: ""
date: "$Date$"
revision: "$Revision$"
SA_SPEC: "swagger=2.0", "host=www.domain.com", "base_path=/basePath"
sa_spec_schemes: "http"
sa_consumes: "text"
sa_produces: "text"
SA_INFO: "version=1.0.0", "title=TEST_CLASS"
SA_CONTACT: "name=API Support", "url=http://www.swagger.io/support", "email=support@swagger.io"
SA_LICENSE: "name=Apache 2.0", "url=http://www.apache.org/licenses/LICENSE-2.0.html"
--sa_security_scheme: "type=blubb", "description=this is a description", "name=this is a name", "in=query", "flow=implicit", "authorization_url=http://www.foo.com", "token_url=http://www.bar.com"

sa_path: "/test_base_path"
class
TEST_CLASS

feature

foo: INTEGER
note
sa_operation: "operation=get", "summary=this is a summary", "description=description", "operation_id=my first operation", "deprecated=false", "path=/blubb"
sa_operation_tags: "tag1", "tag2"
sa_operation_consumes: "text/xml", "text/json"
sa_operation_produces: "image"
sa_operation_schemes: "http", "ws"
sa_schema: "name=schema1", "ref=#/definitions/Pet"
sa_response: "status_code=400", "description=blubb", "schema=schema1" --, "header=header1"
--sa_parameter: "in=body", "name=body", "description=first parameter", "required=false", "schema=schema1"
do
end

bar (i: INTEGER): STRING
note
sa_operation: "operation=put", "summary=this is a summary", "description=description", "operation_id=my first operation", "deprecated=false", "path=/blubb"
sa_operation_tags: "tag1", "tag2"
sa_operation_consumes: "text/xml", "text/json"
sa_operation_produces: "image"
sa_operation_schemes: "http", "ws"
sa_schema: "name=schema1", "ref=#/definitions/Pet"
sa_response: "status_code=400", "description=blubb", "schema=schema1" --, "header=header1"
do
result := i.out
end
end
44 changes: 44 additions & 0 deletions test/integration/classes/test_class2.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
note
description: "Summary description for {TEST_CLASS}."
author: ""
date: "$Date$"
revision: "$Revision$"
SA_SPEC: "2.0"
SA_INFO: "version=1.0.0", "title=TEST_CLASS2"
SA_CONTACT: "name=API Support", "url=http://www.swagger.io/support", "email=support@swagger.io"
SA_LICENSE: "name=Apache 2.0", "url=http://www.apache.org/licenses/LICENSE-2.0.html"
sa_path: "/test_base_path"

class

TEST_CLASS2

feature

foo: INTEGER
note
sa_operation: "operation=get", "summary=this is a summary", "description=description", "operation_id=my first operation", "deprecated=false", "path=/blubb"
sa_operation_tags: "tag1", "tag2"
sa_operation_consumes: "text/xml", "text/json"
sa_operation_produces: "image"
sa_operation_schemes: "http", "ws"
sa_schema: "name=schema1", "ref=#/definitions/Pet"
sa_response: "status_code=400", "description=blubb", "schema=schema1" --, "header=header1"
--sa_parameter: "in=body", "name=body", "description=first parameter", "required=false", "schema=schema1"
do
end

bar (i: INTEGER): STRING
note
sa_operation: "operation=put", "summary=this is a summary", "description=description", "operation_id=my first operation", "deprecated=false", "path=/blubb"
sa_operation_tags: "tag1", "tag2"
sa_operation_consumes: "text/xml", "text/json"
sa_operation_produces: "image"
sa_operation_schemes: "http", "ws"
sa_schema: "name=schema1", "ref=#/definitions/Pet"
sa_response: "status_code=400", "description=blubb", "schema=schema1" --, "header=header1"
do
result := i.out
end

end
5 changes: 2 additions & 3 deletions test/integration/integration.ecf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<precompile name="base_pre" location="$ISE_PRECOMP\base-safe.ecf"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="swagger_documentation_generation" location="\home\tobias\i_ti_eytsch\eiffel_proj\swagger_documentation_generation\src\swagger_documentation_generation.ecf"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="swagger_documentation_generation" location="..\..\src\swagger_documentation_generation.ecf" readonly="False"/>
<cluster name="integration" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
Expand Down
3 changes: 1 addition & 2 deletions test/unit_test/unit_test.ecf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<precompile name="base_pre" location="$ISE_PRECOMP/base-safe.ecf"/>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<cluster name="unit_test" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
Expand Down