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

[DefaultGenerator] NullPointerException on code generation #855

Closed
hl191 opened this issue Aug 21, 2018 · 14 comments
Closed

[DefaultGenerator] NullPointerException on code generation #855

hl191 opened this issue Aug 21, 2018 · 14 comments

Comments

@hl191
Copy link

hl191 commented Aug 21, 2018

Description

Generating Code for yaml produces Nullpoint exception

Exception: null
    at org.openapitools.codegen.DefaultGenerator.processOperation (DefaultGenerator.java:941)
    at org.openapitools.codegen.DefaultGenerator.processPaths (DefaultGenerator.java:835)
    at org.openapitools.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:462)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:793)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:567)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    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:305)
    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:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    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: java.lang.NullPointerException
    at org.openapitools.codegen.DefaultCodegen.addHeaders (DefaultCodegen.java:3005)
    at org.openapitools.codegen.DefaultCodegen.fromResponse (DefaultCodegen.java:2455)
    at org.openapitools.codegen.DefaultCodegen.fromOperation (DefaultCodegen.java:2184)
    at org.openapitools.codegen.languages.AbstractJavaCodegen.fromOperation (AbstractJavaCodegen.java:1070)
    at org.openapitools.codegen.DefaultGenerator.processOperation (DefaultGenerator.java:909)
    at org.openapitools.codegen.DefaultGenerator.processPaths (DefaultGenerator.java:835)
    at org.openapitools.codegen.DefaultGenerator.generateApis (DefaultGenerator.java:462)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:793)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:567)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    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:305)
    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:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    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)

Tried inlining/modifying headers and responses with description.

openapi-generator version

openapi-generator-maven-plugin
version 3.1.0/3.2.0

generator: jaxrs-spec

OpenAPI declaration file content or url

https://berlingroup.stackstorage.com/s/d4KSrRW9bDYmrSg

Steps to reproduce

Use openapi-generator-maven-plugin to generate sources from given OpenAPI spec.

Suggest a fix/enhancement

Investigating NullPointerException

@jmini
Copy link
Member

jmini commented Aug 21, 2018

Thank you for this issue.

Your spec is almost 10500 lines. Having a minimal example to reproduce the issue would help.

Have you tried with the latest version 3.2.1 and/or 3.2.2-SNAPSHOT?

@rienafairefr
Copy link
Contributor

For what it's worth, with version 3.1.0 of the code, the stack trace says line 3005

3004  CodegenProperty cp = fromProperty(headers.getKey(), headers.getValue().getSchema());
3005 cp.setDescription(escapeText(headers.getValue().getDescription()));
3006 cp.setUnescapedDescription(headers.getValue().getDescription());
3007 properties.add(cp);

@rienafairefr
Copy link
Contributor

Just debugged the issue, it's coming from some header definitions, at least /components/parameters/X-Request-ID

I could reproduce the issue on branch v3.1.0 with this minimal yaml:

openapi: 3.0.1
components:
  headers:
    X-Request-ID:
      description: ID of the request, unique to the call, as determined by the initiating party.
      required: true
      example: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
      schema:
        type: string
        format: uuid

  responses:
    OK_200: 
      description: OK
      
      headers:
        X-Request-ID:
          $ref: "#/components/headers/X-Request-ID"

paths:
  /v1/{payment-service}/{paymentId}:

    get:
      summary: Get Payment Information
      description: Returns the content of a payment object
      
      responses: 
        '200':
          $ref: "#/components/responses/OK_200"

@jmini
Copy link
Member

jmini commented Aug 21, 2018

Reproduced with:

openapi: 3.0.1
info:
  title: Issue 855 example
  version: 1.0.0
components:
  headers:
    X-Request-ID:
      description: ID of the request, unique to the call, as determined by the initiating party.
      required: true
      example: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
      schema:
        type: string
        format: uuid

  responses:
    OK_200: 
      description: OK
      headers:
        X-Request-ID:
          $ref: "#/components/headers/X-Request-ID"

paths:
  /ping:
    get:
      summary: Get Payment Information
      description: Returns the content of a payment object
      responses: 
        '200':
          $ref: "#/components/responses/OK_200"

Referenced Header are not supported. We need to support this OAS3 feature.

Work around:

openapi: 3.0.1
info:
  title: Issue 855 example
  version: 1.0.0
components:
  responses:
    OK_200: 
      description: OK
      headers:
        X-Request-ID:
          description: ID of the request, unique to the call, as determined by the initiating party.
          required: true
          example: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
          schema:
            type: string
            format: uuid
paths:
  /ping:
    get:
      summary: Get Payment Information
      description: Returns the content of a payment object
      responses: 
        '200':
          $ref: "#/components/responses/OK_200"

Do you want to propose a fix for this?

In ModelUtils 2 methods are requested:

  • Header getReferencedHeader(OpenAPI, Header)
  • Header getHeader(OpenAPI, String)

They need to be called, at least at the point where there is a NPE. You will also need to add the OpenAPI instance as parameter of some methods in DefaultGenerator.

I can also have a look, but I have limited time.

@rienafairefr
Copy link
Contributor

@jmini I'm looking into it :-)

@rienafairefr
Copy link
Contributor

With #863 merged this should be fixed, don't think it will make it into the 3.2.2 release though

@hl191
Copy link
Author

hl191 commented Aug 21, 2018

@rienafairefr thanks, did u run the full yaml by any chance?

@rienafairefr
Copy link
Contributor

Yep, I tried with generator jaxrs-spec and the yaml you sent, no more NPE at that place. There might still be some bug lurking in there though, if there is, don't hesitate to file another issue.

@jmini
Copy link
Member

jmini commented Aug 22, 2018

@hl191 Please try with 3.2.2-SNAPSHOT

@hl191
Copy link
Author

hl191 commented Aug 22, 2018

Thanks, the NullPointer is gone.

There are some generated classes without member variables when using the full yaml. I will evaluate the created model and file another issue eventually.

@jmini
Copy link
Member

jmini commented Aug 22, 2018

Thank you for the feedback.

Please feel free to open other issues if requested.

@jmini jmini closed this as completed Aug 22, 2018
@sysmat
Copy link

sysmat commented Feb 12, 2019

When in responses using headers

401:
          description: klicatelj nima vloge upravitelj za osebni paket ali delo z
            organizacijo
          headers:
            reason:
              description: basic description what was wrong
              style: simple
            code:
              description: error code of what was wrong
              style: simple

env:

ver: 4.0.0-beta2
generatorName: java
openapi: 3.0.1

error:

 Exception: null
	at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1052)
	at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:946)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:512)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:900)
	at org.openapitools.codegen.plugin.CodeGenMojo.execute(CodeGenMojo.java:670)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
	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:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
	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: java.lang.NullPointerException
	at org.openapitools.codegen.DefaultCodegen.addHeaders(DefaultCodegen.java:3265)

@jmini
Copy link
Member

jmini commented Feb 12, 2019

@sysmat Your problem is that you do not have a Schema defined in your header.

It works when you write:

paths:
  /ping:
    get:
      operationId: pingGet
      responses:
        '201':
          description: OK
          headers:
            x-app-reason:
              description: basic description what was wrong
              style: simple
              schema:
                type: string
            x-app-error-code:
              description: error code of what was wrong
              style: simple
              schema:
                type: string

I have proposed an PR to use String when nothing is defined. See #2133. Fell free to continue the discussion there.

@jmini
Copy link
Member

jmini commented Feb 12, 2019

@sysmat you can try with the latest 4.0.0-SNAPSHOT

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

No branches or pull requests

4 participants