Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send function to swagger.js #176

Closed
fehguy opened this issue Apr 3, 2013 · 20 comments
Closed

send function to swagger.js #176

fehguy opened this issue Apr 3, 2013 · 20 comments

Comments

@fehguy
Copy link
Contributor

fehguy commented Apr 3, 2013

Right now, need to reload swagger.js when key changes. Would be best if we can pass a function to swagger.js so it's read on each query.

@gaffa
Copy link

gaffa commented Jun 6, 2013

please support the same for additional header params :)

@paulhill
Copy link
Contributor

+1

Would be very nice to be able to have arbitrary headers defined as inputs in the banner.
I was attempting the get some OAuth2 hotness going in my API GUI.
Altering the banner was simple enough.
Any advice on how to alter swagger-ui in order to pull the params in as headers on every XHR?

@fehguy
Copy link
Contributor Author

fehguy commented Jun 24, 2013

getting there. We're just finishing up oauth 2 in the swagger spec for java, moving to node next.

@paulhill
Copy link
Contributor

Sweet :-)

-Paul Hill

On 2013-06-23, at 8:17 PM, Tony Tam [email protected] wrote:

getting there. We're just finishing up oauth 2 in the swagger spec for java, moving to node next.


Reply to this email directly or view it on GitHub.

@fehguy
Copy link
Contributor Author

fehguy commented Jun 24, 2013

also, if you missed it...

https://twitter.com/fehguy/status/348516794748776449

@paulhill
Copy link
Contributor

Dude, that's awesome. Your timing is perfect. I'm going to jump right on that.

-Paul Hill

On 2013-06-23, at 8:45 PM, Tony Tam [email protected] wrote:

also, if you missed it...

https://twitter.com/fehguy/status/348516794748776449


Reply to this email directly or view it on GitHub.

@fehguy
Copy link
Contributor Author

fehguy commented Jun 24, 2013

OK, let me know if you need help on it

@paulhill
Copy link
Contributor

While I've got your ear.
I recently had to do rather a dodgy hack to get two swagger UI instances running in the same node.js server.
Because of the requires cache you end up with one set of references by default.
I was going to convert the swagger node express project to export an object constructor but thought I'd better ask you if there was another way you had in mind or had seen?

-Paul Hill

On 2013-06-23, at 8:45 PM, Tony Tam [email protected] wrote:

also, if you missed it...

https://twitter.com/fehguy/status/348516794748776449


Reply to this email directly or view it on GitHub.

@paulhill
Copy link
Contributor

Sorry I meant 2 swagger-node-express instances.

On Sunday, June 23, 2013, Paul Hill wrote:

While I've got your ear.
I recently had to do rather a dodgy hack to get two swagger UI instances
running in the same node.js server.
Because of the requires cache you end up with one set of references by
default.
I was going to convert the swagger node express project to export an
object constructor but thought I'd better ask you if there was another way
you had in mind or had seen?

-Paul Hill

On 2013-06-23, at 8:45 PM, Tony Tam <[email protected]<javascript:_e({}, 'cvml', '[email protected]');>>
wrote:

also, if you missed it...

https://twitter.com/fehguy/status/348516794748776449


Reply to this email directly or view it on GitHubhttps://github.com//issues/176#issuecomment-19887864
.

@fehguy
Copy link
Contributor Author

fehguy commented Jun 24, 2013

eh, I haven't thought through that yet, so glad you brought it up before a refactor starts. Let's open a new ticket so it can be addressed

@paulhill
Copy link
Contributor

I don't mind doing it. Just wanted to check it didn't mess you up.
Let me know if I should do that or wait for the refactor.

On Sunday, June 23, 2013, Tony Tam wrote:

eh, I haven't thought through that yet, so glad you brought it up before a
refactor starts. Let's open a new ticket so it can be addressed


Reply to this email directly or view it on GitHubhttps://github.com//issues/176#issuecomment-19888884
.

@fehguy
Copy link
Contributor Author

fehguy commented Jun 24, 2013

sure, please feel free

@paulhill
Copy link
Contributor

Ok, I've written it as an object constructor export. Will test it tomorrow and submit a pull request.
I'm not super excited about making it an object (all those noisy this.) but can't think of a better way.

-Paul Hill

On 2013-06-23, at 9:48 PM, Tony Tam [email protected] wrote:

sure, please feel free


Reply to this email directly or view it on GitHub.

@paulhill
Copy link
Contributor

I ended up writing a little requires cache name-spacing gizmo that made it
un-necessary to turn it into an object.

I did write the code for the object thing so I'll just email it to you if
you are keen on taking that path. It's arguably the right way to do things
if you want it to be able to run in a browser. I can't imagine why one
would serve an API out of a browser but who knows.

My little cache name spacing gizmo works better in my case because I know I
can assume Node.js as the environment. I can load as many swagger-node-js
instances as I like and don't have to alter the module with all those noisy
prototype and this references.

:-)

On Sunday, June 23, 2013, Paul Hill wrote:

Ok, I've written it as an object constructor export. Will test it tomorrow
and submit a pull request.
I'm not super excited about making it an object (all those noisy this.)
but can't think of a better way.

-Paul Hill

On 2013-06-23, at 9:48 PM, Tony Tam <[email protected]<javascript:_e({}, 'cvml', '[email protected]');>>
wrote:

sure, please feel free


Reply to this email directly or view it on GitHubhttps://github.com//issues/176#issuecomment-19888969
.

@paulhill
Copy link
Contributor

@paulhill
Copy link
Contributor

Sorry to co-opt this thread. Still looking forward to arbitrary headers for auth in swagger-ui

@fehguy
Copy link
Contributor Author

fehguy commented Jul 12, 2013

You can now add any header params you like, programmatically. See in swagger-js, which is integrated in this branch of swagger-ui:

https://github.com/wordnik/swagger-ui/tree/develop-2.0

@fehguy fehguy closed this as completed Jul 12, 2013
@paulhill
Copy link
Contributor

That functionality has been there for a while. But I believe the intention was to make it so the user could enter an oauth token in an input field to be sent as a header on each subsequent request.

-Paul Hill

On 2013-07-11, at 10:26 PM, Tony Tam [email protected] wrote:

You can now add any header params you like, programmatically. See in swagger-js, which is integrated in this branch of swagger-ui:

https://github.com/wordnik/swagger-ui/tree/develop-2.0


Reply to this email directly or view it on GitHub.

@diaspar
Copy link

diaspar commented Aug 22, 2013

hey @fehguy and @paulhill . Do you mind pointing where to look for custom headers by method?

Is not develop-2.0 behind master?

I want to modify swagger-ui to sign all requests using something like amazon does http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html. Theoretically It should intercept the ajax request, use some of the parameters for create the hasg, add a custom http header with the hash and then allow the ajax call to continue.

Thanks, swagger is great.

@fehguy
Copy link
Contributor Author

fehguy commented Aug 22, 2013

hi @diaspar swagger-ui is now up-to-date, develop-2.0 is obsolete (and going away soon). I think we chatted on irc (or somebody else today asked the exact same question) but you should look here:

https://github.com/wordnik/swagger-ui#custom-header-parameters---for-basic-auth-etc

and of course you can write your own signing routine by making something like this:

https://github.com/wordnik/swagger-js/blob/master/src/swagger.coffee#L792

class ApiKeyAuthorization
  type: null
  name: null
  value: null

  constructor: (name, value, type) ->
    @name = name
    @value = value
    @type = type

  apply: (obj) ->
    if @type == "query"
      if obj.url.indexOf('?') > 0
        obj.url = obj.url + "&" + @name + "=" + @value
      else
        obj.url = obj.url + "?" + @name + "=" + @value
      true
    else if @type == "header"
      obj.headers[@name] = @value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants