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

codegen: applying kotlin naming rules to operationId param #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pedro-cze
Copy link

@pedro-cze pedro-cze commented Oct 9, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring
  • Other... Please describe:

What is the current behavior?

Currently if operationId contains whitespaces the resulting function name is wrongly createad as foo bar(). This hould be prevented.

Fixes #30

What is the new behavior?

From now on the operationId will follow naming rules specified for kotlin functions. That means that the first character is removed in case it is a digit. After this check the Functions.toCamelCase() function is applied.

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

  • none

Copy link
Contributor

@niraj8 niraj8 left a comment

Choose a reason for hiding this comment

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

Thanks for the great first contribution! Please see my comment below.

codegen/src/main/kotlin/apifi/parser/PathsParser.kt Outdated Show resolved Hide resolved
- 'operation' prepend if operationId starts with a digit
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@pedro-cze pedro-cze requested a review from niraj8 October 13, 2020 07:55
@pedro-cze
Copy link
Author

hi, @niraj8, can I ask you for a check and response if provided fix is sufficient and the PR can be merged pls.? Thanks.

@niraj8
Copy link
Contributor

niraj8 commented Oct 23, 2020

Hey @pedro-cze!
Been a bit occupied lately.

I went over the issue once again and I think we should take a different approach here.

Instead of converting operationId to conform to function names, we should fail while parsing and ask for valid operationId, with a helpful error message that mentions what is considered valid.

I can't think of any reason for an operationId to start with any non-alphabetic characters.

The operationId would then be mapped directly to the generated controller function for that operation, which was my intention when I suggested we prefix the function name with operation to maintain the original operationId in some way.

We should fail while parsing the spec yml if the operationId doesn't conform to the kotlin function as is.
Later we could allow an option, which bypasses this maybe.

What do you think?

@pedro-cze
Copy link
Author

pedro-cze commented Oct 23, 2020

Hi @niraj8 and thanks for your reply :)
True is that I might be overthinking this but on the other hand the name generation depends on a .yml file that can theoretically contain anything. But I am ok with what you suggest. IMHO if the operationId doesn't conform the function name conventions, we can just return the HTTP method name as is already the case if no operation id is provided plus I can add some "log warn" to log that the provided name is invalid.

Is that ok?

Thanks.

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.

Sonar method name rule violation when operationId has whitespaces
2 participants