Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1327
Closed
Open
Issue created Oct 26, 2018 by Administrator@rootContributor

[C#] aspdotnetcore (C# server) generation does not support byte/binary body

Created by: grmcdorman

Description

When an OpenAPI spec describes the request with a body parameter of either: schema: { "type": "string", "format": "binary" } or schema: { "type": "string", "format": "byte" } the generated controller, correctly, has a [FromBody] System.IO.Stream or [FromBody] byte[] parameter. However, Swashbuckle out of the box does not support either type of parameter, resulting in 415 responses to any request sent, regardless of content type.

openapi-generator version

Discovered using the current git main branch.

OpenAPI declaration file content or url

'/data': { 'put': { 'parameters': [ { "name": "data", "in": "body", "description": "Binary body data", "required": true, "schema": { "type": "string", "format": "byte" } } }

Command line used for generation

java -jar <openapi-generator-cli.jar> generate -i <openapi.json> -g aspnetcore -o -c

Steps to reproduce

Specify an operation with the body as described above.

Related issues/PRs
Suggest a fix/enhancement

The scheme described at https://weblog.west-wind.com/posts/2017/Sep/14/Accepting-Raw-Request-Body-Content-in-ASPNET-Core-API-Controllers#Binary-Data provides a solution for forwarding the body in the appropriate format.

In addition, it is necessary to tell Swashbuckle that the content type is to be 'application/octet-stream'. (Currently OpenAPI-generator does not tell Swashbuckle the expected content type, or the response type, at all). Either a specific 'application/octect-stream' decorator (see https://stackoverflow.com/questions/41141137/how-can-i-tell-swashbuckle-that-the-body-content-is-required) or a more generic decorator in the style suggested at https://stackoverflow.com/questions/34990291/swashbuckle-swagger-how-to-annotate-content-types is needed.

Thus, there would be three steps to implement this scheme:

  1. Create new .mustache files to generate the BinaryPayloadAttribute and BinaryPayloadFilter (or equivalent generic classes). The same files can be used for ASP .Net Core 2.0 and 2.1.
  2. Decorate controller methods appropriately in controller.mustache.
  3. In Startup.mustache, add the new filter: // Support binary payloads. c.OperationFilter();
Assignee
Assign to
Time tracking