Skip to content

[BUG][csharp-netcore] Duplicate methods in model class #14350

@arvindpdmn

Description

@arvindpdmn

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When oneOf or anyOf constructs are used, the generated model file has duplicate constructor and duplicate getObject() method. There's no reference to the actual properties (aId, bId, cId, dId) in the generated file. These problems are not seen with allOf. The attached example YAML file uses oneOf. The same problem will be observed if it's replaced with anyOf.

With aspnetcore, the model file has no duplicates but shows other problems, such as no constructor. This issue focuses only on csharp-netcore.

openapi-generator version

Version used is 6.2.1. Did not test against the latest commit on the master branch.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'Problem example with OneOf'
paths: {}
components:
  schemas:
    SomeId:
      type: object
      properties:
        aId:
          $ref: '#/components/schemas/AId'
        bId:
          $ref: '#/components/schemas/BId'
        cId:
          $ref: '#/components/schemas/CId'
        dId:
          $ref: '#/components/schemas/DId'
      oneOf:
        - required: [ aId ]
        - required: [ bId ]
        - required: [ cId ]
    AId:
      type: integer
      minimum: 0
      maximum: 10
    BId:
      type: integer
    CId:
      type: integer
    DId:
      type: integer
Generation Details
java -jar C:\openapi-generator-cli.jar generate  -i C:\ModelExample.yaml -g csharp-netcore -o C:\out --additional-properties=targetFramework=net6.0  --additional-properties=packageName=Com.Example
Steps to reproduce

Just run the command above and check the generated model file. We will see the duplicates.

Related issues/PRs

This could be related: #8382

Suggest a fix

None at the moment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions