Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] [csharp-netcore] Inadequate constructor with oneOf constraint #15117

Open
4 of 6 tasks
arvindpdmn opened this issue Apr 3, 2023 · 2 comments
Open
4 of 6 tasks

Comments

@arvindpdmn
Copy link

arvindpdmn commented Apr 3, 2023

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 is used along with a specific set of codegen options, we see this problem. In the following example, SomethingMydata.cs has two constructors: SomethingMydata() and SomethingMydata(string actualInstance). When the latter is used, it's impossible to know if the input is "Alpha" or "HelloWorld". If application code wants to initialize Something with "Alpha" there's no proper way to do this. Note the "Alpha" can contain two properties: "abc" and "def". Thus, Alpha can't be reduced to a single string.

openapi-generator version

openapi-generator-cli-6.5.0-20230329.141901-70.jar from https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/6.5.0-SNAPSHOT/

Did not test with 6.5.0 which has just been released. However, I expect the same problem.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'oneOf constructor issue'
paths: {}
components:
  schemas:
    Something:
      type: object
      properties:
        mydata:
          oneOf:
            - $ref: '#/components/schemas/Alpha'
            - $ref: '#/components/schemas/HelloWorld'
      required:
        - mydata
    Alpha:
      type: object
      required:
        - abc
      properties:
        abc:
          $ref: '#/components/schemas/Abc'
        def:
          $ref: '#/components/schemas/Def'
    HelloWorld:
      type: string
      format: base64
      nullable: true
    Abc:
      type: string
      pattern: '^[A-Fa-f0-9]{32}$'
    Def:
      type: string
      pattern: '^[A-Fa-f0-9]{8,32}$'
Generation Details
java -jar lib/openapi-generator-cli-6.5.0-20230329.141901-70.jar generate -i OneOf.yaml -g csharp-netcore -o OneOf --additional-properties=targetFramework=net7.0,skipOneOfAnyOfGetter=true --additional-properties=packageName=Com.Example --skip-validate-spec --openapi-normalizer SIMPLIFY_BOOLEAN_ENUM=true,SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true,REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true,ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE=true,SIMPLIFY_ONEOF_ANYOF=true
Steps to reproduce

As above

Related issues/PRs
  1. [BUG][csharp-netcore] Duplicate methods in model class #14350
  2. [BUG] openapi-generator problem with nested oneOf? #2791
Suggest a fix

No idea at the moment.

@arvindpdmn arvindpdmn changed the title [BUG] [csharp-netcore [BUG] [csharp-netcore] Inadequate constructor with oneOf constraint Apr 3, 2023
@devhl-labs
Copy link
Contributor

Consider trying this with the generichost library.

@prajon84
Copy link
Contributor

prajon84 commented Jan 29, 2024

👋 Any update on the above oneOf issue so far? Since csharp-netcore is merged with csharp. Do we have any update with -g csharp and --library httpclient ?

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

No branches or pull requests

3 participants