diff --git a/src/doc_generator/swagger_doc_generator.e b/src/doc_generator/swagger_doc_generator.e
index d6caa38..6bdcfed 100644
--- a/src/doc_generator/swagger_doc_generator.e
+++ b/src/doc_generator/swagger_doc_generator.e
@@ -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
diff --git a/src/swagger_documentation_generation.ecf b/src/swagger_documentation_generation.ecf
index fc19d40..99ebe09 100644
--- a/src/swagger_documentation_generation.ecf
+++ b/src/swagger_documentation_generation.ecf
@@ -9,10 +9,10 @@
-
-
-
-
+
+
+
+
/EIFGENs$
diff --git a/test/integration/application.e b/test/integration/application.e
index 687491d..a21e210 100644
--- a/test/integration/application.e
+++ b/test/integration/application.e
@@ -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
diff --git a/test/integration/classes/test_class.e b/test/integration/classes/test_class.e
new file mode 100644
index 0000000..3df9171
--- /dev/null
+++ b/test/integration/classes/test_class.e
@@ -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
diff --git a/test/integration/classes/test_class2.e b/test/integration/classes/test_class2.e
new file mode 100644
index 0000000..5a2d3ce
--- /dev/null
+++ b/test/integration/classes/test_class2.e
@@ -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
diff --git a/test/integration/integration.ecf b/test/integration/integration.ecf
index 7286eaa..bee26b1 100644
--- a/test/integration/integration.ecf
+++ b/test/integration/integration.ecf
@@ -6,9 +6,8 @@
-
-
-
+
+
/EIFGENs$
diff --git a/test/unit_test/unit_test.ecf b/test/unit_test/unit_test.ecf
index 8bae536..9abe97d 100644
--- a/test/unit_test/unit_test.ecf
+++ b/test/unit_test/unit_test.ecf
@@ -6,8 +6,7 @@
-
-
+
/EIFGENs$