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

[Nim] Fix compilation in case of schema with enum constraint with an enum value being not a valid nim identifier #20780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sandwoodK
Copy link
Contributor

This is a fix for bug #20779

In case of a schema with an enum constraint, nim code generation creates a nim objtect type enum with the enum values of this schema enum.
It must be valid identifier otherwise the code can not compile.
The fix is to
1/ detect if it is a valid nim identifier, job done with the isValidIdentifier private function, using a pattern based on the definition of a nim valid identifier (see https://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-amp-keywords)
2/ If it is not a valid identifier, we surround the identifier with backticks.

  • [X ] Read the contribution guidelines.
  • [ X] 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.
  • [X ] 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.
  • [X ] 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)
  • [ X] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@hokamoto

@sandwoodK
Copy link
Contributor Author

Note : I have identified others cases where generated Nim code will not compile due to invalid identifiers, I prefer to have atomic PRs instead of a huge 'fix them all'.

I also need guidance of how to add unit tests for these edge cases so that the behaviour changes on generated code becomes more readeable when reviewing..

@wing328
Copy link
Member

wing328 commented Mar 4, 2025

thanks for the PR

please pm me via slack to quickly walk through adding a test

https://join.slack.com/t/openapi-generator/shared_invite/zt-2wmkn4s8g-n19PJ99Y6Vei74WMUIehQA

@wing328 wing328 added this to the 7.13.0 milestone Mar 4, 2025
If enum constraint contains one value which is not a valid nim
identifier, we must surround this identifier with backtick.
@sandwoodK sandwoodK force-pushed the fix_nim_compilation_enums_value_invalid_nim_identifier branch from bb4b91f to c2d3e6b Compare March 4, 2025 20:20
@wing328
Copy link
Member

wing328 commented Mar 7, 2025

i just merged #20819 into master

can you please pull the latest master into your branch?

and then update the test spec (modules/openapi-generator/src/test/resources/3_0/nim/petstore.yaml) with test schemas/endpoints.

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.

2 participants