question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

body type string is not recognized

See original GitHub issue

When expecting a body parameter of type string (not a json!) - an error is returned saying the body parameter is not a string even if it is. Bellow is a sample yaml code that shows it. The references are for the definitions of the id param and the returned values (not relevant here).

  /users/{id}/role:
    parameters:
    - $ref: '#/components/parameters/idParam'
    put:
      tags:
        - Users
      description: Set user role
      responses:
        '204':
          $ref: '#/components/responses/NoContentResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
      requestBody:
        content:
          text/plain:
            schema:
              type: string
              enum:
                - user
                - moderator
                - admin
        description: New role
        required: true

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gonendukcommented, Oct 9, 2019

Thanks! That was the problem 😃 In the code I added: app.use(express.json()); app.use(express.text());

0reactions
gonendukcommented, Oct 9, 2019

Not sure there is anything you can do in the validator in this case. Maybe extend the error message after saying it should be a string, add the type you got - in my case i believe it was undefined (it was not a json and there was no parser for text so req.body left undefined) maybe adding the typeof req.body to the error message info will help. But I’m not so sure about this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 4/5 HttpClient: Argument of type string is not ...
Type 'string' is not assignable to type '"body"'. Here is my version of the code: login(credentials: Credentials): Observable<any> { const ...
Read more >
String was not recognized as a valid DateTime. clientRequestId
Solved: Hi, I am very new to Power Automate and this is one of my first flows, it is getting stuck at the...
Read more >
Strings - Manual - PHP
A string is series of characters, where a character is the same as a byte. This means that PHP only supports a 256-character...
Read more >
Fixing common type problems - Dart
Fix: Specify the type explicitly ... The example can be fixed by explicitly defining the map's type to be <String, num> . var...
Read more >
Resolve template validation or template format errors in ... - AWS
For "Unrecognized parameter type: XXXXXXXX" or "Invalid template parameter ... For "Every Condition member must be a string" errors, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found