Skip to content

OpenAPI: Required method parameters become nullable with /GenerateOptionalParameters:true #1470

Closed
@bkoelman

Description

@bkoelman

When adding the /GenerateOptionalParameters:true option in NSwag generated clients, the request body parameter becomes nullable. For example:

public virtual async Task<ApiResponse<CountryPrimaryResponseDocument>> PatchCountryAsync(string id,
    IDictionary<string, string?>? query = null, CountryPatchRequestDocument? body = null,
    CancellationToken cancellationToken = default(CancellationToken))

This is incorrect because it always fails with HTTP 422.

The OAS for this method looks correct, as far as I'm aware:

"requestBody": {
  "description": "The attributes and relationships of the country to update. Omitted fields are left unchanged.",
  "content": {
    "application/vnd.api+json": {
      "schema": {
        "allOf": [
          {
            "$ref": "#/components/schemas/countryPatchRequestDocument"
          }
        ]
      }
    }
  }
}

I've opened this issue to investigate why this is happening.

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