OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] additionalModelTypeAnnotations value is escaped

Open
#5,533 5 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The annotations specified with additionalModelTypeAnnotations are escaped.
Thefore, using a special character like = leads to a compilation error.

openapi-generator version

4.2.x

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/examples/multi-module/sample-schema/src/main/resources/openapi.yaml

            <!-- activate the plugin -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.3.0-SNAPSHOT</version>
                <dependencies>
                    <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>sample-schema</artifactId>
                        <version>${project.parent.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>openapi.yaml</inputSpec>
                            <generatorName>java</generatorName>
                            <configOptions>
                                <additionalModelTypeAnnotations>@Foo(val=true)</additionalModelTypeAnnotations>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Command line used for generation

Just run the maven plugin.

Steps to reproduce

Inside additionalModelTypeAnnotations, add a value with any special character like @Foo(val=true).

Compilation will fail becaise the annotation is written like this: @Foo(val&#x3D;true)

Suggest a fix

Do not escape the value inside the template.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Maven plugin configuration in modules/openapi-generator-maven-plugin/examples/multi-module/sample-schema/src/main/resources/openapi.yaml and run the Maven plugin generation described in the issue. Trace how additionalModelTypeAnnotations reaches the Java template; done means @Foo(val=true) appears unchanged in the generated source and compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.