OpenAPITools / OpenAPITools/openapi-generator
[BUG] Failing generation with PatternSyntaxException for security with - apiKey: []
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [y ] Have you provided a full/minimal spec to reproduce the issue?
- [y] Have you validated the input using an OpenAPI validator (example)?
- [n]Have you tested with the latest master to confirm the issue still exists?
DOES NOT BUILD, REQUIRES "org.gradle:gradle-tooling-api🫙7.6" WHICH DOES NOT EXIST IN MY WORLD - [y ] Have you searched for related issues/PRs?
- [y ] What's the actual output vs expected output?
- [n ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
This definition is copied from the documentation https://swagger.io/docs/specification/authentication/api-keys/ and leads to a generation error:
security:
- apiKey: []
- appId: []
[ERROR]
java.util.regex.PatternSyntaxException: Unclosed character class near index 22
^- apiKey: [[^\\]&&[]]$
The definition with space in between the brackets works:
security:
- apiKey: [ ]
- appId: [ ]
But even this fails with slightly older libraries (which exactly: don't know)
openapi-generator version
6.3.0
also 6.1.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: 0.0.1
title: Bugreport
description: API key openapitools demonstration
servers:
- url: http://localhost:8080/v3/api-docs/
- url: http://localhost:8080/swagger-ui.html
paths:
/example:
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
description: OK
'401':
description: Authorization failed
security:
- apiKey: []
- appId: []
components:
securitySchemes:
apiKey:
type: apiKey
in: header
name: X-API-KEY
appId:
type: apiKey
in: header
name: X-APP-ID
Generation Details
With mvn install.
Output:
[ERROR]
java.util.regex.PatternSyntaxException: Unclosed character class near index 22
^- apiKey: [[^\\]&&[]]$
^
at java.util.regex.Pattern.error (Pattern.java:2028)
at java.util.regex.Pattern.clazz (Pattern.java:2690)
at java.util.regex.Pattern.clazz (Pattern.java:2658)
at java.util.regex.Pattern.sequence (Pattern.java:2139)
at java.util.regex.Pattern.expr (Pattern.java:2069)
at java.util.regex.Pattern.compile (Pattern.java:1783)
at java.util.regex.Pattern.<init> (Pattern.java:1430)
at java.util.regex.Pattern.compile (Pattern.java:1095)
at sun.nio.fs.WindowsFileSystem.getPathMatcher (WindowsFileSystem.java:282)
at org.openapitools.codegen.ignore.rules.FileRule.<init> (FileRule.java:30)
at org.openapitools.codegen.ignore.rules.Rule.create (Rule.java:115)
at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.loadCodegenRules (CodegenIgnoreProcessor.java:121)
at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.loadFromFile (CodegenIgnoreProcessor.java:82)
at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.<init> (CodegenIgnoreProcessor.java:76)
at org.openapitools.codegen.DefaultGenerator.opts (DefaultGenerator.java:148)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:837)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.093 s
[INFO] Finished at: 2023-02-16T11:56:11+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openapitools:openapi-generator-maven-plugin:6.3.0:generate (bugreport-example-client) on project apikey-security-fails: Code generation failed. See above for the full exception. -> [Help 1]
My build definition for reference.
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- plugin configuration added for bug report -->
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-version}</version>
<executions>
<execution>
<id>bugreport-example-client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/apiKey-openapitools-bug.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-cloud</library>
<apiPackage>nl.bugreport.api</apiPackage>
<modelPackage>nl.bugreport.model</modelPackage>
<ignoreFileOverride>${project.basedir}/src/main/resources/apiKey-openapitools-bug.yaml</ignoreFileOverride>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My local example project is based on Spring Boot 2.7.7 and uses the newest available packages apart from that.
Steps to reproduce
Generate code.
Related issues/PRs
To my knowledge none.
Suggest a fix
Apparently the regular expression or the regex library has a bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.openapitools.codegen.ignore.rules.FileRule and the loading path through Rule.create, CodegenIgnoreProcessor.loadCodegenRules, and DefaultGenerator.opts. Reproduce the Maven generation using the supplied OpenAPI declaration and ignoreFileOverride, then trace how the empty security arrays reach the file-rule pattern handling. Done means generation completes successfully for the reported specification without the PatternSyntaxException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100