swagger-api / swagger-api/swagger-codegen

swagger-codegen-maven plugin 3.1.7 -SpringMvcApiReader parseMethod Nullpointer

Open
#8,864 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

[ERROR] Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.7:generate (default) on project disp-web: null: MojoExecutionException: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.7:generate (default) on project disp-web: null
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException
	at com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo.execute(ApiDocumentMojo.java:133)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.NullPointerException
	at com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader.parseMethod(SpringMvcApiReader.java:324)
	at com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader.read(SpringMvcApiReader.java:131)
	at com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader.read(SpringMvcApiReader.java:74)
	at com.github.kongchen.swagger.docgen.AbstractDocumentSource.loadDocuments(AbstractDocumentSource.java:104)
	at com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo.execute(ApiDocumentMojo.java:96)
	... 22 more

This happens when I add a @Pathvariable in my method. My method signature is as following:

@ApiOperation(value = "findAllTemplateThirdParty", notes = "Find all TemplateThirdParty Resources", response = TemplateThirdPartyResponse.class, tags = { "Template Resource" })
@ApiResponses(value = { 
	@ApiResponse(code = 200, message = "OK", response = TemplateThirdPartyResponse.class),
	@ApiResponse(code = 400, message = "BAD REQUEST", response = ApiResponseMessage.class),
	@ApiResponse(code = 401, message = "UNAUTHORIZED", response = Void.class),
	@ApiResponse(code = 404, message = "NOT FOUND", response = Void.class) })
@RequestMapping(value = "/admin/templates/{templateId}/thirdParties", 
	produces = { "application/json", "application/hal+json", "text/uri-list", "application/x-spring-data-compact+json" },
	consumes = { "application/json" }, method = RequestMethod.GET)
ResponseEntity<PagedResources<TemplateThirdPartyResponse>> findAllTemplateThirdPartyUsingGET(
	@ApiParam(value = "templateId", required = true) @PathVariable Integer templateId,
	@QuerydslPredicate(root = entities.TemplateThirdParty.class) Predicate predicate,
	@PageableDefault(sort = { "id" }) Pageable pageable,
	@RequestParam MultiValueMap<String, String> parameters);

Without the @Pathvariable, the swagger-codegen runs fine but not acceptable for me.
Please could you investigate the underlying issue?

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 at SpringMvcApiReader.parseMethod around line 324 and follow its callers in SpringMvcApiReader.read and AbstractDocumentSource.loadDocuments. Reproduce the Maven generation failure with the shown @PathVariable method signature, then identify the null value and verify generation succeeds while preserving the path variable in the generated API documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
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.