Skip to content

[BUG][CSHARP][GENERICHOST] JsonConverter validation does not handle non-required nullable reference types correctly. #23190

@alec-petersen

Description

@alec-petersen

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

If you leave a property as non-required and enable nullable reference types the Read/WriteProperties in the JsonConvert will still require non-null values.

(Read)

if (message.IsSet && message.Value == null)
    throw new ArgumentNullException(nameof(message), "Property is not nullable for class HelloWorldPostRequest.");

and

(WriteProperties)

if (helloWorldPostRequest.MessageOption.IsSet && helloWorldPostRequest.Message == null)
    throw new ArgumentNullException(nameof(helloWorldPostRequest.Message), "Property is required for class HelloWorldPostRequest.");
openapi-generator version

7.20.0

OpenAPI declaration file content or url

(Just using one of the sample specs)

openapi: 3.1.0                                                                                                                                                                                            
  info:                                                                                                                                                                                                     
    title: Minimal reproduction for csharp webhook bug                                                                                                                                                      
    version: 1.0.0                                                                                                                                                                                          
    description: This is an example API to reproduce a bug with webhooks in csharp codegen
  tags:
    - name: Test
      description: This is a test
  webhooks:
    helloWorld:
      post:
        summary: Example webhook
        responses:
          "204":
            description: Webhook processed
          "500":
            description: Webhook not processed
        description: Send when an example is needed
        requestBody:
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                description: The payload of the HelloWorld webhook
          description: Contains the details of the hello world webhook
Generation Details

Latest, nullableReferenceTypes as true.

Steps to reproduce

Generate using the generichost csharp library.

Related issues/PRs
Suggest a fix

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