OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.33k stars 6.46k forks source link

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

Open Benoit12345 opened 2 years ago

Benoit12345 commented 2 years ago
Description

To reproduce:

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

wing328 commented 2 years ago

@Benoit12345 thanks for reporting the issue

cc @aeneasr

SeanAsby commented 2 years ago

@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(<>)

aeneasr commented 2 years ago

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! :)