Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSwag studio incorrectly generates empty body #4927

Open
wim11be opened this issue Jun 27, 2024 · 1 comment
Open

NSwag studio incorrectly generates empty body #4927

wim11be opened this issue Jun 27, 2024 · 1 comment

Comments

@wim11be
Copy link

wim11be commented Jun 27, 2024

I have a spec, where a PUT request has no request body, only a response body defined:

'/redacted':
    put:
      security:
        - BearerAuth: []
      parameters:
        - description: Redacted
          in: path
          name: user
          required: true
          schema:
            $ref: '#/components/schemas/ObjectId'
        - description: The ID of the segment
          in: path
          name: segment
          required: true
          schema:
            $ref: '#/components/schemas/ObjectId'
      responses:
        '200':
          content:
            application/json; charset=utf-8:
              schema:
                $ref: '#/components/schemas/ResponseMessage'
              example:
                message: user removed from segment
          description: OK

Nswag studio generates an empty body for the content with the content type of the response. The generated code looks like this:
request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json; charset=utf-8");
This causes an exception since the Encoding and mediatype are to be separately defined in the StringContent constructor. Removing the charset=utf-8 manually solved the issue, but I worry that this error will sneak in again when a new spec is generated. Could you solve this issue?

Kind regards

@idea-lei
Copy link

same here #4919

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

No branches or pull requests

2 participants