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

Move Swagger types and warnings under /generator namespace #803

Merged
merged 4 commits into from
Jan 2, 2023

Conversation

PanosCodes
Copy link
Contributor

@PanosCodes PanosCodes commented Dec 27, 2022

Why

I'm woking on PR to make generators pluggable and allow external generators to be used by apipie.
This PR is a first step to start moving the Swagger 2.0 generator under /generator namespace.

How

It introduces

  • Apipie::Generator::Swagger::TypeExtractor that is responsible to convert an Apipie::Validator to a Swagger type
  • Apipie::Generator::Swagger::Warning & Apipie::Generator::Swagger::WarningWriter to handle conditional logic on when a warning should be logged or not.

It's just a refactor and does not add any new functionality for the end user and it should not introduce any breaking changes.

@PanosCodes PanosCodes changed the title Swagger type extractor Move Swagger types and warnings under /generator namespace Dec 27, 2022
@PanosCodes PanosCodes marked this pull request as ready for review December 27, 2022 17:46
`Apipie::Generator::Swagger::TypeExtractor` is responsible to identify
the Swagger type from a given validator or default to `string` if no
validator is given.
private

def extract
expected_type = if string?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer preventing wide indent by adding a return after the assignation.
can you update to

expected_type = 
  if string?
    :string
  elsif boolean?
    :boolean
  elsif enum?
    :enum
  else
    @validator.expected_type.to_sym
  end

Copy link
Contributor Author

@PanosCodes PanosCodes Dec 28, 2022

Choose a reason for hiding this comment

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

That's fine with me. 036e748

Should we add it as a Rubocop cop ?

Copy link
Collaborator

@mathieujobin mathieujobin left a comment

Choose a reason for hiding this comment

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

This is a really cool refactor, I need more time to review, but I intend to merge...

elsif enum?
:enum
else
@validator.expected_type.to_sym
Copy link
Collaborator

Choose a reason for hiding this comment

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

now that I am reading this properly.. maybe this was the original code... but I wonder why the if/elsif/elsif/else when @validator.expected_type.to_sym probably already return the right value for string, boolean, and enum ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What was confusing to me as well.
There are a couple of issues we handle here

ParamDescription's validator can be

  • nil
  • Apipie::Validator::BaseValidator
  • ResponseDescriptionAdapter::PropDesc::Validator

Updated Yard comment dc88775


In case of nil we want to default to string


Apipie::Validator::EnumValidator#expected_type returns string


ResponseDescriptionAdapter::PropDesc::Validator#expected_type can we whatever by if we give it values that are [true, false] we need to result into boolean.

@mathieujobin mathieujobin merged commit 5eced26 into Apipie:master Jan 2, 2023
@PanosCodes PanosCodes deleted the swagger-type-extractor branch January 2, 2023 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants