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

[Elm] Fix not sanitizing param name #20171

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

Qluxzz
Copy link
Contributor

@Qluxzz Qluxzz commented Nov 24, 2024

From the example I added, when a schema has a property with a space in it like the following example:

schema:
  type: object
  properties:
    "name with spaces":
      type: string

The resulting function is:

paramSanitizeTestPost : Maybe String -> Api.Request ()
paramSanitizeTestPost name with spaces =
    Api.request
        "POST"
        "/param-sanitize-test"
        []
        []
        []
        (Just <| Http.multipartBody <| List.filterMap identity [ Maybe.map (Http.stringPart "name with spaces") name with spaces ])
        (Json.Decode.succeed ())

Which doesn't compile since the annotation says it should take one argument, but now it takes three (name, with, and spaces). And the same issue when we try to map it to the argument here:

(Just 
    <| Http.multipartBody 
    <| List.filterMap identity [ Maybe.map (Http.stringPart "name with spaces") name with spaces ]
                                                                                  ^----^----^
)

This PR fixes so we sanitize/normalize the param name. And also fix so we use the paramName partial when mapping multi part body arguments, which previously just used {{paramName}} to add it.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@eriktim

Copy link
Contributor

@eriktim eriktim left a comment

Choose a reason for hiding this comment

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

LGTM

@wing328
Copy link
Member

wing328 commented Nov 25, 2024

@Qluxzz thanks for the PR

I've filed #20173 instead as we usually override toParamName to handle other edge cases such as reserved word, better support for parameter name mapping, etc.

can you please give it a try to see if this approach works for you as well?

@wing328
Copy link
Member

wing328 commented Nov 25, 2024

@Qluxzz when you've time, can you please PM me via Slack?

https://join.slack.com/t/openapi-generator/shared_invite/zt-2uoef5v0g-XGwo8~2oJ3EoziDSO1CmdQ

@Qluxzz
Copy link
Contributor Author

Qluxzz commented Nov 25, 2024

I've reworked the solution so we now override toParamName instead of using the camelcase lambda, this required some changes in the templates where we should use baseName instead of the sanitized paramName.

I also expanded the endpoint I added for testing, so it tests the different parameter types.

@wing328 wing328 added this to the 7.11.0 milestone Nov 26, 2024
@wing328
Copy link
Member

wing328 commented Nov 26, 2024

lgtm. thanks for the PR

@wing328 wing328 merged commit ed21105 into OpenAPITools:master Nov 26, 2024
18 checks passed
@Qluxzz Qluxzz deleted the fix-not-sanitizing-param-name branch November 26, 2024 09:33
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