[go: nahoru, domu]

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][C#/aspnetcore] Invalid C# code generated with version 7.4.0 #18081

Closed
5 of 6 tasks
JonasPed opened this issue Mar 12, 2024 · 8 comments
Closed
5 of 6 tasks

[BUG][C#/aspnetcore] Invalid C# code generated with version 7.4.0 #18081

JonasPed opened this issue Mar 12, 2024 · 8 comments

Comments

@JonasPed
Copy link

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

The latest release (v7.4.0) can generate C# code that does not compile when generating for aspnetcore and setting nullableReferenceTypes=true.

It happens when a property is optional and declared with "nullable: true". See the problem property in the example OpenAPI document. In the model class it generates the property where the type is declared with double question marks (??) instead of a single question mark.

Using version v7.3.0 it works fine.

openapi-generator version

7.4.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: A bug report
  description: Example for bug report
  version: "1.0.0"
tags:
  - name: demo
    description: Demo tag

paths:
  /v1/example:
    get:
      tags:
        - demo
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/demoResponse'
                
components:
  schemas:
    demoResponse:
      type: object
      required:
        - ok
      properties:
        problem:
          type: string
          nullable: true
          description: This generates code that can not compile. 
        ok:
          type: string
          nullable: true
          description: This genrates code that can compile.
Generation Details

Using docker image:
docker run --rm --user $(id -u) -v $(pwd)/Documentation:/local openapitools/openapi-generator-cli:latest-release generate -i /local/api.yaml -o /local/Generated -g aspnetcore -p nullableReferenceTypes=true

or cli
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/api.yaml -o ./output -g aspnetcore -p nullableReferenceTypes=true

Steps to reproduce
  1. Run below command to generate code from OpenAPI document.
    java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/api.yaml -o ./output -g aspnetcore -p nullableReferenceTypes=true
  2. Run below command to build dotnet solution.
    dotnet build output/
Related issues/PRs
Suggest a fix
@wing328
Copy link
Member
wing328 commented Mar 13, 2024

thanks for reporting the issue.

I think it's caused by #17934

@JFCote can you please take a look? shall we revert the change for the time being?

@JFCote
Copy link
Member
JFCote commented Mar 13, 2024

Hi @wing328 ,
I already declared the bug a couple of days after my changes but didn't had the time to fix it before the release: #18005

I think we can safely revert the change and I'll try to do a safer change next time. In the end, it needs to "accumulate" all the reason to be nullable and only render one ? and with the way the code is working, it needs a little bit of work.

Do you take care of the revert or do you want me to do it @wing328 ?

@devhl-labs
Copy link
Contributor

There is OptionalParameterLambda which can mitigate this.

@mpo-wd
Copy link
mpo-wd commented Jun 25, 2024

We are having the same issues with the latest versions and a C# 6 / ASP.NET Core 6 codebase. We forced our build process to v7.3.0 for now.

@wing328
Copy link
Member
wing328 commented Jun 25, 2024

@mpo-wd if you or anyone would like to contribute a PR or sponsor the fix, please let us know.

@JFCote
Copy link
Member
JFCote commented Jun 25, 2024

@wing328 I will definitely try to do a fix in the upcoming weeks but if someone can chime in before that, I will do the review.
Sorry about that, been a crazy year!

@JFCote
Copy link
Member
JFCote commented Jul 3, 2024

@wing328 I created a PR to fix this issue here: #19062

@wing328
Copy link
Member
wing328 commented Jul 6, 2024

PR merged. thanks for the fix

@wing328 wing328 closed this as completed Jul 6, 2024
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

5 participants