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.

Request body property is coerced e.g. ("123" coerced to123)

See original GitHub issue

Hi, I am using openapi: 3.0.2 with express-openAPI-validator ^2.0.0 I am getting the following problem: When I am using

new OpenApiValidator({
      apiSpec: this.openApiPath,
      validateResponses: false,
      **validateRequests:** true,
    }).install(this.app);

its changing the integer values to string like

body: { a: 1}

and I am getting

body: {a:"1"}

Please fix this problem as I am getting validation issue due to this

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
cdimasciocommented, May 31, 2020

@chittolina would you be interested in taking the first pass at solving this?

Some pointers:

  1. The following function creates an AJV validator for requests. It receives its options when a new RequestValidator is constructed. Basically, we need to create two validators here. 1 as-is and a second with the option coerceTypes: false.
  2. When validation occurs e.g. here, we need two separate validator calls:
    1. uses the existing validator and does not validate the body
    2. uses the new validator (i.e. th one withcoerceTypes:false), and validates only the body
  3. Finally, check both validators for errors here check both validators for errors.

Note: to quickly get a development environment setup, you can follow the instructions in [CONTRIBUTING.md]. You can also click the Gitpod button at the top of this issue or the Gitpod badge in the README.md to setup a cloud dev env in one click.

1reaction
cdimasciocommented, Oct 4, 2020

fixed in v4.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does type coercion with "+string" work in Javascript?
As the ECMAScript spec describes in section 12.5.6: 12.5.6 Unary + Operator. NOTE The unary + operator converts its operand to Number type....
Read more >
CoerceValueCallback Delegate (System.Windows)
Provides a template for a method that is called whenever a dependency property value is being re-evaluated, or coercion is specifically requested.
Read more >
10. Destructuring - Exploring JS
The parts of an object pattern are properties, the property values are again patterns (recursively). Array pattern. For example: [ «pattern», «pattern» ]....
Read more >
Introduction to FXML | JavaFX 8.0 - Oracle Help Center
The document introduces FXML, an XML-based declarative markup language for defining user interfaces in JavaFX 8.0 applications.
Read more >
Type Coercion with DataWeave - MuleSoft Documentation
In DataWeave, types can be coerced from one type to other using the as operator. Type coercion takes place at runtime. Before you...
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