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

[Kotlin] Add a new additional property to configure Jackson's failOnUnknownProperties #19506

Merged

Conversation

fistons
Copy link
Contributor

@fistons fistons commented Sep 1, 2024

This PR intents to fix #19408 and to have the same default behavior as the Java clients' i.e. being able to configure the Jackson's ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES.

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 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (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.6.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.

@wing328
Copy link
Member

wing328 commented Sep 4, 2024

@fistons thanks for the PR

let us know if you need help to complete this PR

cc
@dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06)

@fistons
Copy link
Contributor Author

fistons commented Sep 4, 2024

You are welcome! I still need to work on it, I will let you know if I need help

@fistons fistons marked this pull request as ready for review September 4, 2024 17:33
@fistons
Copy link
Contributor Author

fistons commented Sep 4, 2024

Should be good now!

Comment on lines 444 to 446
if (!additionalProperties.containsKey(FAIL_ON_UNKNOWN_PROPERTIES)) {
additionalProperties.put(FAIL_ON_UNKNOWN_PROPERTIES, false);
}
Copy link

Choose a reason for hiding this comment

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

does this allow setting FAIL_ON_UNKNOWN_PROPERTIES to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand the generator, FAIL_ON_UNKNOWN_PROPERTIES will be true if and only if the we specify the failOnUnknownProperties option to true.

Am I right?

Copy link

Choose a reason for hiding this comment

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

I'm new to the repository, so I may be wrong here, but reading these lines, it looks as though we only update the property value (and to false) if the property isn't included by the user configuration.

The other properties are in this format:

        if (additionalProperties.containsKey(KEY)) {
            setKey(additionalProperties.get(KEY).toString());
        }

such as:

        if (additionalProperties.containsKey(REQUEST_DATE_CONVERTER)) {
            setRequestDateConverter(additionalProperties.get(REQUEST_DATE_CONVERTER).toString());
        }

Which reads as though - if provided, we will override the value based on the provided value. I'm sure a unit test will make this clear, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, you are right, thanks!

I refactored this part and added a unit test for this.

Copy link

Choose a reason for hiding this comment

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

Should the changes in this file have a new unit test in KotlinClientCodegenModelTest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will add one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@akdoan1
Copy link

akdoan1 commented Sep 11, 2024

@wing328 can we get additional reviews on this? When is the cutoff to include this change in the 7.9.0 release on 2024-09-23?

@wing328 wing328 merged commit 425aa7d into OpenAPITools:master Sep 16, 2024
60 checks passed
@wing328 wing328 added this to the 7.9.0 milestone Sep 16, 2024
@wing328
Copy link
Member

wing328 commented Sep 16, 2024

thanks for the PR, which has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants