Skip to content

Conversation

@ePaul
Copy link
Contributor

@ePaul ePaul commented Mar 10, 2017

PR checklist

  • Read the contribution guildelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change.
    → bin/elixir-petstore.sh
  • Filed the PR against the correct branch: master for non-breaking changes

Description of the PR

This fixes (or hopes to fix) part of #4898 for the elixir generator.

The problem likely occurred when a query/form/header parameter name (as declared in the OpenAPI definition) is of a form which doesn't match the form used in Elixir, or is a reserved word there. In this case the parameter gets renamed for use in the code, and the algorithm for including the parameter in the request uses the sanitized name instead of the original one.

This commit changes the replacement to using {{baseName}} (which is the original name of the parameter definition as parsed from the API definition) instead of {{paramName}} (which is the sanitized version of the parameter name).

There are some places in the Petstore samples where this makes some difference, to me it looks like the new ones are more sensible.

I don't know anything about Elixir (don't even have a compiler on my computer), so this needs intensive review by Elixir experts. /cc @niku

@wing328
Copy link
Contributor

wing328 commented Mar 14, 2017

@niku I wonder if you can help us understanding the following

query_params = [{{^queryParams.isEmpty}}query: [{{#queryParams}}{{^-first}}, {{/-first}}{:"{{paramName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/queryParams}}]{{/queryParams.isEmpty}}]
header_params = [{{^headerParams.isEmpty}}header: [{{#headerParams}}{{^-first}}, {{/-first}}{:"{{paramName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/headerParams}}]{{/headerParams.isEmpty}}]

Is {{#underscored}}{{paramName}}{{/underscored}} the variable name in Elixir or the original variable name (e.g. modified-date, AccountName) defined in the spec? Thanks.

@niku
Copy link
Contributor

niku commented Mar 15, 2017

Hi, I'm sorry for the late reply.
I will check this PR later probably some time today or tomorrow.

@niku
Copy link
Contributor

niku commented Mar 16, 2017

Is {{#underscored}}{{paramName}}{{/underscored}} the variable name in Elixir or the original variable name (e.g. modified-date, AccountName) defined in the spec?

It should be a variable name in Elixir like account_name not like AccountName.

  def login_user(username, password) do
    method = [method: :get]
    url = [url: "/user/login"]
    query_params = [query: [{:"username", username}, {:"password", password}]]
    #                                    ^^^^^^^^^^                ^^^^^^^^^
    # Thease are the parts that generated by {{#underscored}}{{paramName}}{{/underscored}}.
    # They have to equal the argument of the function.

@wing328 wing328 merged commit d3f365f into swagger-api:master Mar 20, 2017
@wing328 wing328 changed the title Fix (partially) #4898 for elixir [Elixir] fix parameter name with {{baseName}} Mar 20, 2017
@ePaul ePaul deleted the fix-partially-4898-for-elixir branch March 20, 2017 09:22
spr3nk3ls pushed a commit to spr3nk3ls/swagger-codegen that referenced this pull request Mar 28, 2017
* fix (partially) swagger-api#4898 for Elixir

* Update petstore samples (after fix for elixir for swagger-api#4898)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants