Giter Site home page Giter Site logo

Comments (3)

Mick605 avatar Mick605 commented on May 25, 2024

The problem seems to come from the interception of the res.send function done in oas-validator.js, line 102

  /* Intercepts response */
  const oldSend = res.send;
  res.send = function send(data) {
    // here, data parameter can be either object or string
   ...
  }

The data parameter can either be of type object or string, depending on the way the response is generated:

  • when using res.send(object), data will be an object
  • when using res.json(object), data will be a JSON encoded string

It seems that there is not enough information in the current interceptor to differenciate these cases. Testing if data looks like a JSON encoded string is not a solution because someone could want to use res.send() to send an already JSON encoded string.

Intercepting also the res.json method in oas-validator.js seems to be tricky, because the original res.send from Express calls res.json internally in some cases, and res.json calls res.send internally too...

In my opinion, the interception should be made at a lower level, to avoid these problems. The interception itself could be made with an external library, such as express-interceptor. Using a low-level interceptor also has the benefit to allow more use cases of response generation, such as calling res.write() directly.

from oas-tools.

alesancor1 avatar alesancor1 commented on May 25, 2024

Hello, Mick, I agree with what you say about intercepting responses at a lower level. Ideally, it is the res.write( ) method what should be overriden, since it is what writes the data to the stream before calling res.end( ). I'll study how express-interceptor works and try to fix that.

from oas-tools.

agnoam avatar agnoam commented on May 25, 2024

Hey, any news about this?

from oas-tools.

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.