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

added option to write a throwing exception for unknown enums values. #10356

Merged
merged 1 commit into from
Jun 30, 2020

Conversation

HugoMario
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

fixes #5950

@HugoMario
Copy link
Contributor Author

please build

@JonathanParrilla
Copy link
Contributor

please build

@JonathanParrilla
Copy link
Contributor

Please build

@lyubomyr-shaydariv
Copy link

@HugoMario
Thanks for bringing this to life! Just one question please: can this one also be backported onto the v2 branch?

@HugoMario HugoMario merged commit 1e490ac into master Jun 30, 2020
@HugoMario
Copy link
Contributor Author

@lyubomyr-shaydariv
it is: swagger-api/swagger-codegen-generators#713

@rDmT93
Copy link

rDmT93 commented Mar 16, 2021

How can I enable it for swagger-codegen-maven-plugin?

Thanks in advance.

@rDmT93
Copy link

rDmT93 commented Apr 26, 2021 via email

@cdprete
Copy link

cdprete commented Apr 26, 2021

In the meantime I found out how to do it: ... errorOnUnknownEnum=true ... Cosimo Damiano Prete @.***> escreveu no dia segunda, 26/04/2021 à(s) 11:14:

How can I enable it for swagger-codegen-maven-plugin? Thanks in advance. I've the same issue. I've tried specifying it as configOption as well as configuration option, but it looks like it's simply ignored. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#10356 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOMTQKSOA2V6R6RYVD74Q3TKU4GZANCNFSM4OLX5LCA .

Too bad that now the generation of the patterns is broken and therefore I cannot use this version...

@cdprete
Copy link

cdprete commented Feb 2, 2022

Nice to see that after almost an year this is still broken.
With

<plugin>
                    <groupId>io.swagger.codegen.v3</groupId>
                    <artifactId>swagger-codegen-maven-plugin</artifactId>
                    <version>3.0.32</version>
                    <dependencies>
                        <dependency>
                            <groupId>com.github.jknack</groupId>
                            <artifactId>handlebars</artifactId>
                            <version>4.3.0</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <inputSpec>${project.basedir}/src/main/resources/service-contract.yaml</inputSpec>
                                <modelPackage>com.cdprete.phonebook.dto</modelPackage>
                                <generateApis>false</generateApis>
                                <generateApiTests>false</generateApiTests>
                                <generateModelTests>false</generateModelTests>
                                <generateSupportingFiles>false</generateSupportingFiles>
                                <language>java</language>
                                <library>resttemplate</library>
                                <additionalProperties>
                                    <additionalProperty>errorOnUnknownEnum=true</additionalProperty>
                                </additionalProperties>
                                <configOptions>
                                    <booleanGetterPrefix>is</booleanGetterPrefix>
                                    <dateLibrary>java8</dateLibrary>
                                    <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                    <useBeanValidation>true</useBeanValidation>
                                    <performBeanValidation>true</performBeanValidation>
                                    <openApiNullable>false</openApiNullable>
                                </configOptions>
                            </configuration>
                        </execution>
                    </executions>

I get out

    @JsonCreator
    public static TypeEnum fromValue(String input) {
      for (TypeEnum b : TypeEnum.values()) {
        if (b.value.equals(input)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + text + "' for 'EmailAddress' enum.");
    }

See how the parameter is named input, but in the exception is concatenated (wrongly) as text...

@avachos
Copy link

avachos commented Feb 15, 2022

I have exactly the same issue as described above.

errorOnUnknownEnum=true

breaks compilation because parameter is named input, but in the exception is concatenated (wrongly) as text...

Any idea for work around or when it's going to be fixed?

@yannick-fernand
Copy link

hi @cdprete to get the return null, you will have to add the tag nullable: true to your enum into the swagger like this example:

MyEnum:
  type: string
  nullable: true
  enum:
     - VAL1
     - VAL2

cf.

@cdprete
Copy link

cdprete commented Dec 3, 2022

hi @cdprete to get the return null, you will have to add the tag nullable: true to your enum into the swagger like this example:

MyEnum:
  type: string
  nullable: true
  enum:
     - VAL1
     - VAL2

cf.

Hi @yannick-fernand.
null / optional is not the same as unknown :)

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.

[JAVA] Enum mapping make wrong value as null instead of throwing an exception
7 participants