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

Parameter serialization format #64

Open
erictuvesson opened this issue Nov 18, 2019 · 2 comments
Open

Parameter serialization format #64

erictuvesson opened this issue Nov 18, 2019 · 2 comments

Comments

@erictuvesson
Copy link

Hey,

I currently came across an issue where we annotate the code with uppercase "Integer", but Swagger only supports lowercase integer.
https://swagger.io/docs/specification/data-models/data-types/

Is there a way to force it to be lowercase or have a way to convert types to a different name?

It could be nice to have a hash where you can map to custom types.

Something like this maybe

{
  "Integer" => "integer"
}
@nicksieger
Copy link
Collaborator

nicksieger commented Nov 18, 2019

This block of code is where identifiers are handled by the parser.

https://github.com/livingsocial/swagger_yard/blob/master/lib/swagger_yard/type_parser.rb#L70-L75

Looks like you could monkeypatch the SwaggerYard::Model.mangle method and add your custom behaviors:

class SwaggerYard::Model
  def self.mangle(name)
    case name
    when /Integer/
      name.downcase
    else
      name.gsub(/[^[:alnum:]_]+/, '_')
    end
  end
end

If you want to submit a patch to add some more formalized custom type mapping, feel free to submit a PR.

@erictuvesson
Copy link
Author

Thanks for the quick reply.

I would love to do a PR, just I don't have the time for it 😞

I ended up adding this monkeypatch, maybe I will add more types later. I only found an issue with String and Integer types now.

  module SwaggerYard
    class Model
      def self.mangle(name)
        case name
        when /string/i then name.downcase
        when /integer/i then name.downcase
        else
          name.gsub(/[^[:alnum:]_]+/, '_')
        end
      end
    end
  end

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

No branches or pull requests

2 participants