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

[BUG][CSHARP][generichost] Inheritance with allOF produce code which does not compile when child rewrite type of inherited property

Open McMlok opened this issue 1 year ago • 1 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [ ] Have you validated the input using an OpenAPI validator (example)?
  • [X] Have you tested with the latest master to confirm the issue still exists?
  • [X] Have you searched for related issues/PRs?
Description

When I use schema below generation of csharp generichost code produces invalid code. There is doubled property Code in Model/TestResult.cs. When I use aspnetcore (server) or csharp httpclient/restsharp it produces valid code in this class.

openapi-generator version

7.11.0

OpenAPI declaration file content or url
openapi: '3.0.2'
info:
  title: Inheritance test
  version: '1.0.0'

paths:
  /test/data:
    get:
      operationId: testOperation
      responses:
        '200':
          description: Test operation
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/TestResult"
components:
  schemas:
    Result:
      type: object
      properties:
        code:
          type: string
          description: Result code
        uuid:
          type: string
          description: Result unique identifier
        data:
          type: object
          description: list of named parameters for current message
          additionalProperties:
            type: string

    TestResult:
      type: object
      allOf:
        - $ref: '#/components/schemas/Result'
      properties:
        code:
          $ref: "#/components/schemas/TestResultCode"

    TestResultCode:
      type: string
      description: Result code
      enum:
        - APPROVED
        - MANUAL_APPROVAL_REQUIRED

Generation Details

java -jar .\openapi-generator-cli-7.11.0.jar generate -i ./service.yaml -g csharp -o ./out-debug-host/ --additional-properties=targetFramework=net8.0,excludeTests=true,nullableReferenceTypes=true,useOneOfDiscriminatorLookup=true,packageName=Test.Client.Generic,packageVersion=1.0.0,library=generichost

Steps to reproduce

Run CLI command above and run dotnet build in ./out-debug-host/ It fail with two errors in TestResult class

Suggest a fix

Only the child property code is produced in TestResult class. Same as when I generates aspnetcore or csharp with restsharp or httpclient libraries.

McMlok avatar Jan 23 '25 10:01 McMlok

The problem is that the vars and allVars contain different instances of CodegenProperties.

Image

devhl-labs avatar Feb 02 '25 22:02 devhl-labs