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

uiConfig cant handle functions #25

Closed
2 tasks done
nada-one opened this issue Nov 8, 2022 · 4 comments · Fixed by #37
Closed
2 tasks done

uiConfig cant handle functions #25

nada-one opened this issue Nov 8, 2022 · 4 comments · Fixed by #37

Comments

@nada-one
Copy link

nada-one commented Nov 8, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hello!

Firstly, thanks for an awesome package! Such a huge help.

I got a question and I am hoping you can help me out on this. I am not quite sure but it seems that preauthorizeBasic and preauthorizeApiKey instance methods as documented in https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md are not yet supported by the package.

Are these options something that you plan to support in the future? If I overlooked it and that they're already supported, can you please provide an example on how I can pass them?

In swagger-ui-express, I am able to utilize the onComplete parameter to pass a function that invokes those instance methods as shown below:
{
tagsSorter: 'alpha',
onComplete: function () {
ui.preauthorizeBasic("basicAuth", "user", "pass");
ui.preauthorizeApiKey("apiKey", "apikey");
}

}

Thanks for the feedback in advance!

@Uzlopak
Copy link
Collaborator

Uzlopak commented Nov 8, 2022

You should be able to pass the configuration through uiConfig.

@nada-one
Copy link
Author

nada-one commented Nov 25, 2022

Tried passing the following to uiConfig but it doesn't work:

uiConfig: {
  onComplete: function () {
     ui.preauthorizeBasic("basicAuth", "user", "pass");
     ui.preauthorizeApiKey("apiKey", "apikey");
  }
}

Am I passing it incorrectly?

I ended up adding some custom code to achieve this in swagger-initializer.js though as a workaround.

@climba03003
Copy link
Member

swagger-ui-express is dynamic generate the JavaScript where as we statically provide the JavaScript.

I don't think .toString a function would be good and it somehow prone to error since people may think that variable will work inside the function.

@Uzlopak Uzlopak mentioned this issue Dec 2, 2022
2 tasks
@Uzlopak
Copy link
Collaborator

Uzlopak commented Dec 2, 2022

The issue is that the uiConfig is serialized to json and supplied by a rest-call. And functions cant be serialized.

So we have to find a way to provide the functions in a javascript file or somehow differently...

@Uzlopak Uzlopak changed the title Are preauthorizeBasic and preauthorizeApiKey instance methods currently supported? uiConfig cant handle functions Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants