Skip to content

Remove null-checks for non-required properties (csharp code generation)#5191

Open
josch83 wants to merge 1 commit intoRicoSuter:masterfrom
josch83:fix/optional-multipart-request-parameters
Open

Remove null-checks for non-required properties (csharp code generation)#5191
josch83 wants to merge 1 commit intoRicoSuter:masterfrom
josch83:fix/optional-multipart-request-parameters

Conversation

@josch83
Copy link
Copy Markdown

@josch83 josch83 commented Jun 18, 2025

Same as described in #5023:

Given:

            "multipart/form-data": {
              "schema": {
                "required": [
                  "file"
                ],
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "description": "",
                    "format": "binary"
                  },
                  "fileDescription": {
                    "type": "string",
                    "description": ""
                  }
                }
              }, ...

Instead of:

                    if (file == null)
                        throw new System.ArgumentNullException("file");
                    else
                    {
                     ...
                    }

                    if (fileDescription != null)
                    {
                     ...
                    }

It generates:

                    if (file == null)
                        throw new System.ArgumentNullException("file");
                    else
                    {
                     ...
                    }

                    if (fileDescription == null)
                        throw new System.ArgumentNullException("fileDescription");
                    else
                    {
                     ...
                    }

This PR resolves the issue with a different approach (tested and used in our application)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant