swagger-api / swagger-api/swagger-codegen

Unable to Generate GO clients when schema has enums on it

Open
#12,430 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

When attempting to generate GO clients from a schema that uses Enums, it fails with error :

15:58:49.856 [main] INFO  i.s.c.v.g.t.AbstractTypeScriptClientCodegen - Template folder: null
15:58:49.856 [main] INFO  i.s.c.v.g.t.AbstractTypeScriptClientCodegen - Template engine: io.swagger.codegen.v3.templates.HandlebarTemplateEngine@e98770d
15:58:49.877 [Thread-0] INFO  i.s.c.v.g.t.AbstractTypeScriptClientCodegen - Template folder: null
15:58:49.878 [Thread-0] INFO  i.s.c.v.g.t.AbstractTypeScriptClientCodegen - Template engine: io.swagger.codegen.v3.templates.HandlebarTemplateEngine@53ba3063
Exception in thread "Thread-0" java.lang.RuntimeException: Could not process model 'ASchemaName'.Please make sure that your schema is correct!
	at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:391)
	at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:793)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "codegenModel.dataType" is null
	at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromModel(DefaultCodegenConfig.java:1466)
	at io.swagger.codegen.v3.generators.go.AbstractGoCodegen.fromModel(AbstractGoCodegen.java:565)
	at io.swagger.codegen.v3.DefaultGenerator.processModels(DefaultGenerator.java:1068)
	at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:380)
	... 3 more
Swagger-codegen version

Whichever version is in the docker image swaggerapi/swagger-codegen-cli-v3. 3.0.59?

Swagger declaration file content or url
openapi: 3.1.0

components:
  schemas:
    ASchemaName:
      type: string
      enum: [value1,value2,value3]
   
Command line used for generation

This works
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate -i /local/simplest.yml -l javascript -o /local/out/go

This does not
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate -i /local/simplest.yml -l go -o /local/out/go

Steps to reproduce

docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate -i /local/simplest.yml -l go -o /local/out/go

Related issues/PRs

Unknown

Suggest a fix/enhancement

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

Reproduce the failure with simplest.yml and the Docker generate command, then trace the reported path through DefaultCodegenConfig.fromModel and generators.go.AbstractGoCodegen.fromModel. Compare the Go and JavaScript runs and add regression coverage for the enum schema; done means Go client generation completes without the NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.