OpenAPITools / OpenAPITools/openapi-generator

[BUG] Exception Thrown for Missing Non-Required Query Parameters in C# Generated Code

Open
#17,451 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I am encountering an issue where the C# server code generated by OpenAPI Generator (version 7.1.0) throws exceptions when non-required query parameters are absent in a request. This problem arises despite these parameters not being marked as required in my OpenAPI document, which I created using Stoplight Studio (version 2.10.0).

Steps to Reproduce:

  1. OpenAPI Document Creation:

    • Using Stoplight Studio 2.10.0, I created an OpenAPI document. In this document, I have several query parameters not marked as required.
    • Example snippet from the YAML file:
      parameters:
         - schema:
             type: string
             nullable: true
           in: query
           name: data
           description: 'For more information, refer to ....'
           allowEmptyValue: true
      
    • Stoplight Studio does not set these parameters as nullable, I have added nullable manually..
  2. OpenAPI Generator Usage:

    • I used the OpenAPI Generator CLI (version 7.1.0) with the following command to generate the C# server code:
      openapi-generator-cli generate -i [path-to-myDoc.yaml] -g aspnetcore -o [output-directory] --additional-properties=aspnetCoreVersion=6.0,buildTarget=library,packageName=MyRestSvr,operationIsAsync=true,operationResultTask=true
      
  3. Encountered Issue:

    • In the generated C# server code, the absence of these query parameters (which are not required as per the OpenAPI document) leads to exceptions.

Workaround Implemented:

  • I manually modified the generated code to define these query parameters as nullable in C#. This resolved the issue.

Expected Behaviour:

  • The generated code should handle non-required query parameters without throwing exceptions when they are missing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided YAML parameter definition and the OpenAPI Generator CLI command targeting aspnetcore. Inspect the generated C# handling for absent optional query parameters and verify that generated server code accepts them without throwing exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.