OpenAPITools / OpenAPITools/openapi-generator

[BUG] [GO] Unknown newStrictDecoder function with model only

Open
#11,374 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

To reproduce:

  • generate go files with "client.go" into ".openapi-generator-ignore"

Expected:
Generated sources can be compile as usual

Actual:
It doesn't compile anymore because method "newStrictDecoder" doesn't exist (no client.go file)

Proposal:
move useful function into utils.go file.

Linked Issue : #8491

openapi-generator version

Latest Docker image openapi-generator-cli (generated today : 01/21/22)

OpenAPI declaration file content or url

Every valid openapi spec file

Generation Details

extract from generated source:

// Unmarshal JSON data into one of the pointers in the struct
func (dst *FormTemplateBodyItem) UnmarshalJSON(data []byte) error {
	var err error
	// use discriminator value to speed up the lookup
	var jsonDict map[string]interface{}
	err = newStrictDecoder(data).Decode(&jsonDict)
	if err != nil {
		return fmt.Errorf("Failed to unmarshal JSON into map for the discriminator lookup.")
	}
Steps to reproduce

Just add "client.go" into ".openapi-generator-ignore"

For information, I use generator with theses options:

generate -i "/openapi_spec.yaml" --strict-spec true --additional-properties=useOneOfDiscriminatorLookup=true -p enumClassPrefix=true -g go 
Related issues/PRs

Related to this issue #8491 https://github.com/OpenAPITools/openapi-generator/pull/8491/commits/31555e593f1a3de5d5c7756a80da2c3233029a11 --> commit 31555e593f1a3de5d5c7756a80da2c3233029a11

Suggest a fix

Move useful methods into utils.go

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 generation with useOneOfDiscriminatorLookup=true while adding client.go to .openapi-generator-ignore, then inspect the generated client.go and utils.go files. Confirm the missing newStrictDecoder reference and compile the generated sources; done means generation succeeds without client.go and the output compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.