Skip to content

Adds check to consider the required flag on multipart forms in the C# Code generator#5023

Open
simonnieder wants to merge 1 commit intoRicoSuter:masterfrom
simonnieder:required-parameters-multiform
Open

Adds check to consider the required flag on multipart forms in the C# Code generator#5023
simonnieder wants to merge 1 commit intoRicoSuter:masterfrom
simonnieder:required-parameters-multiform

Conversation

@simonnieder
Copy link
Copy Markdown
Contributor

The problem is that for multipart forms the required fields are ignored. This causes the client to throw an ArgumentNullException even if the parameter is NOT required.

For

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

we would expect

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

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

However, we get

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

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

@AroglDarthu
Copy link
Copy Markdown

I think this would also solve issue #4174 and #4518 right?
@RicoSuter please accept the PR!

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.

2 participants