-
Notifications
You must be signed in to change notification settings - Fork 463
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
Added Swagger generation #569
Conversation
lib/apipie/swagger_generator.rb
Outdated
@@ -0,0 +1,583 @@ | |||
module Apipie | |||
module Validator | |||
class EnumValidator < BaseValidator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not putting it directly to the validator definition?
lib/apipie/swagger_generator.rb
Outdated
end | ||
|
||
|
||
def save_and_compare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not being called from any place? Should it be exposed from the rake?
lib/apipie/swagger_generator.rb
Outdated
# note that at the moment, this only takes operation ids into account, and ignores parameter | ||
# definitions, so it's only partially useful. | ||
def include_op_id_in_master_identifier(op_id) | ||
@master_id = Zlib::crc32("#{@master_id} #{op_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably require zlib
somewhere: it's probably loaded by rails somewhere, but just to be on safe side
lib/apipie/swagger_generator.rb
Outdated
# print "??? RESEARCH: [#{ruby_name_for_method(@current_method)}] -- #{msg}\n" | ||
end | ||
|
||
def dump_param_desc(param_desc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method?
There are some unused methods and commented code, that should be cleaned first. I have not tested this yet, but my view on this is we could get this in pretty soon, as it has not influence on other features, and can be pretty useful for many folks. |
I wonder if we could have a test on checking that the swagger output valid, in the tests. |
Another question: would it make sense to expose this via an |
Thanks @iNecas - good points. I'll push a cleaned-up version early next week. Re exposing via Re testing the validity of the swagger output: would be great to add. A possible approach might be to validate against the Swagger schema (perhaps by using the json-shema gem?) on the output. What do you think? |
Agreed with all you said :) |
* moved EnumValidator#values to validator.rb * replaced 'save_and_compare' method with new rake task ("apipie:did_swagger_change") and optional 'x-computed-id' info field in output swagger * added "require 'zlib'" (if configured to generate x-computed-id field) * removed leftover routines (SwaggerGenerator#investigate, SwaggerGenerator#dump_param_desc) * added warning_inferring_boolean (when inferring that a [true,false] enum param is really a boolean) * documented the 'host' configuration param in the README, and made it possible not to include this field in the output
Pushed a cleaned-up version addressing the code issues you highlighted. Will keep you posted on progress re the |
Hi @iNecas - it turns out that rendering at runtime from If you feel comfortable with what I've posted so far as a first version, it might be best to merge that into the master branch and not wait for the additional functionality. This will reduce the risk of incompatibilities creeping into the code. |
I'm ok with waiting for the |
…enAPI-2.0 JSON schema
The schema validation was surprisingly easy to add. Pushed a version that includes it. |
…neration to play nice with swagger-codegen
ping |
Hi @iNecas - runtime swagger generation is now supported (with some limitations - see the README). |
|
||
@language = get_language | ||
|
||
Apipie.load_documentation if Apipie.configuration.reload_controllers? || (Rails.version.to_i >= 4.0 && !Rails.application.config.eager_load) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is quite a lot of code duplicated from the index
method. Could you look into how to DRY this a bit?
Otherwise, the implementation looks good and I think we are close to merging this
@swagger_content_type_input = :form_data # this can be :json or :form_data | ||
@swagger_json_input_uses_refs = false | ||
@swagger_include_warning_tags = false | ||
@swagger_suppress_warnings = false #[105,100,102] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does #[105,100,102]
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nm: I looked at the readme and here we go :)
Thanks @elasti-ron, I don't see any other reason why holding this in a PR any longer. Thanks for hard work and this one. I'm sure it will be useful for others as well |
Thanks for moving apipie forward. I would have few comments to the proposal: would you mind opening the proposal as a PR, with the markdown document in it. The would for the PR would not be to merge that, but to have a meaningful discussion over the diff itself. In general, I like the idea of combining the concepts we already have in the apipie. Although, I would suggest introducing additional keyword (something like I will have more comments, but I would like to leave that for a new PR to continue with the discussion. |
Also, make sure to advertise this in #273, as there are other folks interested into this functionality, that could have a valuable input to the progress of this. |
Done. #588. |
Hi,
I've added the capability to auto-generate static Swagger definition files from the Apipie DSL.
The resulting Swagger (OpenAPI 2.0) compliant JSON file can then be used to auto-generate REST clients, imported into tools like Postman, and so forth.
Swagger generation is implemented by crawling through Apipie's resource_descriptions construct.
The DSL is slightly enhanced to allow indication of default values of optional parameters.
There are a few configuration options that can be used to change the overall structure of the generated swagger file, in order to support both in:formData and in:body REST request styles.
Looking forward to hear your thoughts.