Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Adding a easier way to access to params [Question ~ Request] #345

Closed
midudev opened this issue Feb 8, 2016 · 8 comments
Closed

Adding a easier way to access to params [Question ~ Request] #345

midudev opened this issue Feb 8, 2016 · 8 comments

Comments

@midudev
Copy link

midudev commented Feb 8, 2016

Working with swagger-tools I've found, on my opinion, that is too convoluted access to request params. I've added a manual middleware to deal with it and, so far, I'm pretty happy with the result.

    // Add an easier way to get params from swagger-tools
    app.use((req, res, next) => {
      function getParam (param) {
        if (req.swagger.params[ param ]) {
          return req.swagger.params[ param ].value
        }
      }

      req.getParams = () => {
        var obj = {}
        for (let param in req.swagger.params) {
          obj[param] = getParam(param)
        }
        return obj
      }
      req.getParam = getParam
      next()
    })

My question is, how are you dealing with this? Have you found another way to easily access the params? Would it be a good idea to add something like the middleware above in order to add a better way to access the value of the params to swagger-tools? Any feedback? Thanks for your awesome work!

@whitlockjc
Copy link
Member

I agree it's a lot to type. The new middleware I'm using to replace swagger-tools will not have this issue as everything is via an API: operation.getParameter(name, [location]). I don't see me fixing this in swagger-tools since I'm deprecating it (#335) soon but I will keep it open just in case.

@midudev
Copy link
Author

midudev commented Feb 8, 2016

Oh boy, so swagger-tools are being deprecated? 😢 I'll keep an eye open to the new library then. :) Thanks!

@whitlockjc
Copy link
Member

Deprecation is such a strong word. ;) swagger-tools is being broken up into specific modules, instead of one module containing everything (API, CLI, Middleware, ...). During this time we're taking a step back and rewriting the pieces based on all of the information we have now and releasing 1.0.0 versions for each component. Make sense?

@midudev
Copy link
Author

midudev commented Feb 8, 2016

Yeah, sure, it makes sense! 👍 But it was you the first to mention the word deprecating! 😛 I would say that's a fantastic idea to separate the modules and I hope to see a great evolution of the new modules. As we're going to build an API using swagger-tools at our company I'll try to be up to date on the ongoing development and try to give a hand. :)

@whitlockjc
Copy link
Member

Don't worry, there will be plenty of documentation on migrating from swagger-tools to whatever comes after it.

@midudev
Copy link
Author

midudev commented Feb 9, 2016

Fantastic. Thanks @whitlockjc

@jvivs
Copy link

jvivs commented May 8, 2016

@whitlockjc what github org are the individual modules being rewritten under? Or is there a roadmap listed somewhere? I'd like to help move things forward.

@whitlockjc
Copy link
Member

Right now here are the projects:

@midudev midudev closed this as completed Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants