Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] [Csharp] distriminator property in subclass generated incorrect in the class constructor #20105

Closed
5 tasks done
WuZiHong opened this issue Nov 14, 2024 · 1 comment · Fixed by #20540
Closed
5 tasks done

Comments

@WuZiHong
Copy link

WuZiHong commented Nov 14, 2024

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?
Description

The openapi3 yaml content looks like:

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths: {}
components:
  schemas:
    CopyActivity:
      type: object
      required:
        - $schema
        - copyActivitytt
      properties:
        $schema:
          type: string
          enum:
            - ScopeActivity
        copyActivitytt:
          type: string
      allOf:
        - $ref: '#/components/schemas/EntityBase'
    EntityBase:
      type: object
      required:
        - $schema
      properties:
        $schema:
          type: string
      discriminator:
        propertyName: $schema
        mapping:
          ScopeActivity: '#/components/schemas/CopyActivity'

When I try to use this to generate csharp code, the constructor in the generated subclass is incorrect. Like below:
image

In the red box, the expected value should be default(stringEnum) instead of a string, as it cannot be correctly assigned.

openapi-generator version

7.9.0

Steps to reproduce

openapi3 yaml file -> csharp model classes

Could you please help check and tell me what I might have done wrong? Or is that should be a bug?

@WuZiHong WuZiHong changed the title [BUG] [Csharp] distriminator property in subclass generated incorrect in class construct function [BUG] [Csharp] distriminator property in subclass generated incorrect in the class constructor Nov 14, 2024
@WuZiHong
Copy link
Author

WuZiHong commented Nov 15, 2024

Interesting... when I changed the entity name from uppercase to lowercase (CopyActivity -> copyActivity, EntityBase -> entityBase), it generated the correct output.

Openapi3 yaml content:

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths: {}
components:
  schemas:
    copyActivity:
      type: object
      required:
        - $schema
      properties:
        $schema:
          type: string
          enum:
            - activities/copyActivity
      allOf:
        - $ref: '#/components/schemas/entityBase'
    entityBase:
      type: object
      required:
        - $schema
      properties:
        $schema:
          type: string
      discriminator:
        propertyName: $schema
        mapping:
          activities/copyActivity: '#/components/schemas/copyActivity'

The generated cshap code:
image

So... This should be an issue 🤣

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant