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
20.85k stars 6.34k forks source link

[BUG][C#] UNKNOWN_BASE_TYPE with ref on allOf #17962

Open acandylevey opened 5 months ago

acandylevey commented 5 months ago

Bug Report Checklist

Description

When generating the C# client when the request body has been put into a allOf via a $ref the generated code always contained UNKNOWN_BASE_TYPE.

This changed recently in our code base as we started using config.UseAllOfToExtendReferenceSchemas(); with Swashbuckle.

Prior to this, we always generated our schema as below which didn't cause any issues.

 application/json:
            schema:
              $ref: '#/components/schemas/CustomRequest'
openapi-generator version

7.3.0

OpenAPI declaration file content or url
/api/custom-endpoint:
    post:
      requestBody:
        content:
          application/json-patch+json:
            schema:
              allOf:
              - $ref: '#/components/schemas/CustomRequest'
          application/json:
            schema:
              allOf:
              - $ref: '#/components/schemas/CustomRequest'
          text/json:
            schema:
              allOf:
              - $ref: '#/components/schemas/CustomRequest'
          application/*+json:
            schema:
              allOf:
              - $ref: '#/components/schemas/CustomRequest'
      responses:
        "200":
          content:
            text/plain:
              schema:
                items:
                  $ref: '#/components/schemas/CustomResponse'
                type: array
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/CustomResponse'
                type: array
            text/json:
              schema:
                items:
                  $ref: '#/components/schemas/CustomResponse'
                type: array
          description: Success
      security:
      - API-Key: []
      tags:
      - CustomTag
Generation Details

openapi-generator-cli generate -i .\api-swagger.json -g csharp -o ./client -p disallowAdditionalPropertiesIfNotPresent=false -p targetFramework=net6.0 -p packageName=Org.Domain.Api-p netCoreProjectFile=true -p nullableReferenceTypes=true -p useCollection=true -p library=httpclient -p useSingleRequestParameter=true

Steps to reproduce

Generate with the above yaml and you'll get UNKNOWN_BASE_TYPE

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/2236

wing328 commented 5 months ago

can you please share the spec (minimal) to reproduce the issue?

I tired to reproduce with allOf in request/response but couldn't.

howlettt commented 3 weeks ago

I ran into this issue when using version 7.0.1 of the cli, updating to the latest 7.7.0 fixed it