openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open Benoit12345 opened this issue 3 years ago • 3 comments

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

Benoit12345 avatar Jan 21 '22 14:01 Benoit12345

@Benoit12345 thanks for reporting the issue

cc @aeneasr

wing328 avatar Jan 22 '22 01:01 wing328

@wing328 Is there an estimate on fixing this? The generator currently generates code which does not compile because of this missing function. I've tried using useOneOfDiscriminatorLookup: true to avoid the problem, but that causes oneOf models without a discriminator to fail unmarshalling with Data matches more than one schema in oneOf(<>)

SeanAsby avatar Aug 02 '22 14:08 SeanAsby

I don't think that he can fix this, but he for sure can review the PR if you provide one, and so can I! :)

aeneasr avatar Aug 02 '22 14:08 aeneasr