Skip to content

Misused header name 'Content-Range' when generating .NET API client #21727

@BottlecapDave

Description

@BottlecapDave

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

When generating a csharp client from the provided spec, it adds a "known header" to the wrong header block. This causes a runtime issue when attempting to use the spec. In this scenario, I believe Content-Range should be added to the Content headers not the Request headers.

openapi-generator version

v7.14.0

OpenAPI declaration file content or url
{
  "x-generator": "NSwag v14.4.0.0 (NJsonSchema v11.3.2.0 (Newtonsoft.Json v13.0.0.0))",
  "openapi": "3.0.0",
  "info": {
    "title": "PROJECTNAME.Api",
    "version": "v1"
  },
  "paths": {
    "/v1/users/me/profile-image/{id}": {
      "put": {
        "tags": [
          "User"
        ],
        "summary": "Uploads a chunk of data for a piece of content.",
        "operationId": "User_WriteProfileImageContent",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The Id of the content the data is for.",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "x-position": 1
          },
          {
            "name": "Content-Part-Number",
            "x-originalName": "chunkNumber",
            "in": "header",
            "required": true,
            "description": "The number of the chunk being uploaded",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "x-position": 2
          },
          {
            "name": "Content-Range",
            "x-originalName": "contentRange",
            "in": "header",
            "required": true,
            "description": "The range of content being uploaded",
            "schema": {
              "type": "string"
            },
            "x-position": 3
          },
          {
            "name": "Client-Version",
            "in": "header",
            "description": "Optionally determines the version of the calling client",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "True if the final chunk; False otherwise",
            "content": {
              "application/json": {
                "schema": {
                  "type": "boolean"
                }
              }
            }
          },
          "400": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "422": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationErrorProblemDetails"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "text/plan": {}
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "text/plain": {}
            }
          },
          "426": {
            "description": "Client requires updating",
            "content": {
              "text/plain": {}
            }
          }
        },
        "security": [
          {
            "oauth2": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "UserDto": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "forename",
          "surname"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "forename": {
            "type": "string"
          },
          "surname": {
            "type": "string"
          },
          "profileImageId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          }
        }
      },
      "ValidationErrorProblemDetails": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ProblemDetails"
          },
          {
            "type": "object",
            "description": "Represents a variant of the problem details that includes validation errors",
            "additionalProperties": {
              "nullable": true
            },
            "properties": {
              "errors": {
                "type": "array",
                "description": "The collection of validation error messages",
                "nullable": true,
                "items": {
                  "$ref": "#/components/schemas/ValidationError"
                }
              }
            }
          }
        ]
      },
      "ValidationError": {
        "type": "object",
        "description": "Represents a validation error",
        "additionalProperties": false,
        "required": [
          "attribute",
          "path",
          "messages"
        ],
        "properties": {
          "attribute": {
            "type": "string",
            "description": "The attribute that the validation error was raised against."
          },
          "path": {
            "type": "string",
            "description": "The path to the attribute"
          },
          "value": {
            "description": "The value that was provided that caused the validation error",
            "nullable": true
          },
          "messages": {
            "description": "The raised validation error messages",
            "$ref": "#/components/schemas/ValidationErrorMessages"
          }
        }
      },
      "ValidationErrorMessages": {
        "type": "object",
        "description": "Represents a validation error message.",
        "additionalProperties": false,
        "required": [
          "developer",
          "friendly"
        ],
        "properties": {
          "developer": {
            "type": "string",
            "description": "The developer related error message"
          },
          "friendly": {
            "type": "string",
            "description": "The friendly error message. This can be presented to the user"
          }
        }
      },
      "ProblemDetails": {
        "type": "object",
        "additionalProperties": {
          "nullable": true
        },
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "RegisterUserRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "email",
          "forename",
          "surname",
          "isAdmin"
        ],
        "properties": {
          "email": {
            "type": "string"
          },
          "forename": {
            "type": "string"
          },
          "surname": {
            "type": "string"
          },
          "isAdmin": {
            "type": "boolean"
          }
        }
      },
      "VerifyUserRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "email",
          "token"
        ],
        "properties": {
          "email": {
            "type": "string"
          },
          "token": {
            "type": "string"
          }
        }
      },
      "CreateProfileImageFileRequest": {
        "type": "object",
        "description": "Request for creating a new storage item",
        "additionalProperties": false,
        "required": [
          "contentType",
          "fileName",
          "fileSizeInBytes",
          "additionalMetadata"
        ],
        "properties": {
          "contentType": {
            "type": "string",
            "description": "The type of content being uploaded."
          },
          "fileName": {
            "type": "string",
            "description": "The name of the file being uploaded."
          },
          "fileSizeInBytes": {
            "type": "integer",
            "description": "The size of the file being uploaded.",
            "format": "int32"
          },
          "additionalMetadata": {
            "type": "object",
            "description": "Additional metadata to associate with the file",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "UserProfileSize": {
        "type": "string",
        "description": "",
        "x-enumNames": [
          "Original",
          "Small"
        ],
        "enum": [
          "Original",
          "Small"
        ]
      }
    },
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "flows": {
          "implicit": {
            "authorizationUrl": "not-specified",
            "scopes": {
              "offline_access": "offline_access",
              "openid": "openid",
              "not-defined": "api-admin"
            }
          }
        }
      }
    }
  }
}
Generation Details

Settings

-p=useDateTimeOffset=true,nullableReferenceTypes=true,targetFramework=net8.0

Steps to reproduce
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