swagger-api / swagger-api/swagger-codegen

Generate Spring Client - NullPointerException

Open
#9,101 1 comment 0 reactions 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

Description

Generating a spring client fails with NullPointerException and no explanation as to what is wrong.

Exception in thread "Thread-1" java.lang.NullPointerException
	at io.swagger.codegen.v3.generators.java.SpringCodegen.preprocessOpenAPI(SpringCodegen.java:421)
	at io.swagger.codegen.v3.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:190)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:713)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:342)
	at java.lang.Thread.run(Thread.java:745)

Full output here:

https://gist.github.com/EarthCitizen/9c03901e21ba588a4ce22a6824ff9ac8

Swagger-codegen version

3.0.4

Swagger declaration file content or url
openapi: '3.0.0'
into:
  title: Records OpenAPI document
  version: 1.0.0

components:
  schemas:
    Record:
      type: object
      properties:
        id:
          type: integer
          format: int64
        code:
          type: string
        info:
          type: string

paths:
  /records:
    get:
      description: Get the records
      responses:
        '200':
          description: A list of records
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Record'
Command line used for generation
spring-client $ swagger-codegen generate -v -l spring -i ../openapi.yaml
Steps to reproduce

Execute above command.

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/4625

Suggest a fix/enhancement

The output should specify what is missing instead of simply generating a NPE.

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 SpringCodegen.preprocessOpenAPI in SpringCodegen.java:421 and reproduce with the supplied OpenAPI document and swagger-codegen generate -v -l spring -i ../openapi.yaml command. Compare the failure with the related issue 4625 and make the generator report which input is missing instead of emitting only a NullPointerException.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.