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

Disable FAIL_ON_UNKNOWN_PROPERTIES in generated JSON.java? #10306

Closed
marbrink opened this issue Sep 1, 2021 · 7 comments · Fixed by #19271
Closed

Disable FAIL_ON_UNKNOWN_PROPERTIES in generated JSON.java? #10306

marbrink opened this issue Sep 1, 2021 · 7 comments · Fixed by #19271

Comments

@marbrink
Copy link

marbrink commented Sep 1, 2021

Description

I get com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException because the API I am using has a new field.
But I want my client to be able to just ignore unknown properties.
In a previous project I used openapi generator 4.3.1 and this was the behaviour.
However in newer versions like 5.1.1 or 5.2.1 this doesn't work anymore. I can see that in the generated invoker.JSON.java the FAIL_ON_UNKNOWN_PROPERTIES changed from false to true.
How can I configure the openapi generator, to ignore unknown properties, like it was before?

openapi-generator version

Worked in 4.3.1. Not anymore in 5.x

@wing328
Copy link
Member

wing328 commented Sep 6, 2021

Can you try the following option by setting it to true?

	disallowAdditionalPropertiesIfNotPresent
	    If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default. (Default: true)
	        false - The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
	        true - Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.

@marbrink
Copy link
Author

marbrink commented Sep 6, 2021

true should be the default for that setting. But setting it to true or false doesn't seem to fix my problem.
I tried it like this in the pom.xml
<configOptions>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
</configOptions>

@snago
Copy link
Contributor

snago commented Jan 20, 2023

We ran into this as well. We "fixed" it with maven-antrun-plugin like this:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <configuration>
                <target>
                    <replace token="mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)"
                             value="mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)"
                             dir="target/generated-sources/openapi">
                        <include name="**/our_generated_client/invoker/JSON.java"/>
                    </replace>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

@josebarros2025
Copy link

This isnt really a fix, any way to force this annotation to be generated in the source code?

@dermot-hardy
Copy link

dermot-hardy commented Feb 20, 2024

I'm setting this to workaround the issue:

<additionalModelTypeAnnotations>@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)</additionalModelTypeAnnotations>

Here is an example:
https://github.com/JobService/job-service/blob/v7.0.0-source/job-service-internal-client/pom.xml#L104-L110

@josebarros2025
Copy link

I can confirm that works.

@fistons
Copy link
Contributor

fistons commented Jul 9, 2024

It works until the the generated code also include @JsonIgnoreProperties then compilation failure com.fasterxml.jackson.annotation.JsonIgnoreProperties is not a repeatable annotation type

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