Giter Site home page Giter Site logo

Comments (5)

gonenduk avatar gonenduk commented on May 9, 2024 1

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

from express-openapi-validator.

gonenduk avatar gonenduk commented on May 9, 2024

Note: In the example above there is also an enum on the string value, but it can be removed for this sample. The issue is with the string type - not the enum.

from express-openapi-validator.

cdimascio avatar cdimascio commented on May 9, 2024

@gonenduk Can you ensure you are able to parse body text

For example, ensure you're express app is set up to to parse both text and json bodies. For example, you might use the bodyParser middleware:

e.g.

app.use(bodyParser.text());
app.use(bodyParser.json());

i have a hunch that perhaps everything is forced to json and thus the validator is getting req.body with a value of empty JSON object e.g. {}, rather than the expected string value e.g. whatever string the caller PUT

assuming this is the case, the validator should, at least, throw some kind of validation error stating that it received JSON not {} text instead of a string value (and if it can distinguish, perhaps a note about the body parser to help dev's sort the issue or even)

also, assuming this is the case, i wonder if the validator should optionally install relevant body parsers. something like this may overstep the scope of the validator. users should have choice. food for thought. if you have opinions, please share

from express-openapi-validator.

cdimascio avatar cdimascio commented on May 9, 2024

Fantastic! I added some notes to the README. Do you feel the validator should do more here, that is beyond some notes in the README it.

from express-openapi-validator.

gonenduk avatar gonenduk commented on May 9, 2024

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.

from express-openapi-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.