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

Addresses issue #283 by adding oauth2 security scopes to operation docs #287

Closed

Conversation

jimmyjames
Copy link

This PR attempts to address issue discussed in issue #283

Operations often have a specific security scope associated with them, and currently that information is not available via ReDoc. This PR:

  • Renders a tooltip to the right of the operation header if there are OAuth2 security definitions for that operation.
  • In order to support HTML display in the tooltip, changes dependency on hint.css to html-hint.css (based on hint.css).

Some things to consider/review from those with more knowledge:

  • Other tooltips using hint appear to work OK (probably because html-hint is based on hint), but could use some consideration from domain-experts.
  • This pass only supports OAuth2 security definitions per operation as a first-pass - it does not consider api_keys. OK for a first pass?
  • This implementation does not attempt to handle any $ref to security definitions per-operation. I don't know if this is supported/common so worth considering (perhaps at least needs to be handled for the securityDefinitions lookup of the descriptions?).
  • Currently displays as ! styled similar to other tips like Parameters. Might be better to display as some sort of padlock icon (like Swagger UI) to be clearer, but per issue comments starting with the !

Copy link
Member

@RomanHotsiy RomanHotsiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimmyjames thanks for kicking it off and sorry for long reply! This looks good!

In order to support HTML display in the tooltip, changes dependency on hint.css to html-hint.css (based on hint.css).

I have a concern here as the html-hint seems to be not maintained heavily: last changes a year ago comparing to 6 days ago by hint.css

This pass only supports OAuth2 security definitions per operation as a first-pass - it does not consider api_keys. OK for a first pass?

absolutelly OK!

This implementation does not attempt to handle any $ref to security definitions per-operation.

I will test these changes on some major documentations powered by ReDoc and most likely will request some more changes.

Regarding padlock, just use svg. So replace ! by this:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="20px" height="20px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
  <path d="M384,224v-96C384,57.438,326.594,0,256,0c-70.578,0-128,57.438-128,128v96c-35.344,0-64,28.656-64,64v160c0,35.344,28.656,64,64,64h256c35.344,0,64-28.656,64-64V288C448,252.656,419.344,224,384,224z M272,379.094V432c0,8.844-7.156,16-16,16s-16-7.156-16-16v-52.906c-9.391-5.563-16-15.375-16-27.094c0-17.688,14.328-32,32-32s32,14.313,32,32C288,363.719,281.391,373.531,272,379.094z M320,224H192v-96c0-35.313,28.703-64,64-64c35.281,0,64,28.688,64,64V224z"/>
</svg>

@@ -137,6 +137,42 @@ export class SpecManager {
return obj;
}

getOperationScopes(operationPtr:string) {
let that = this;
function getSecurityDefinition(name:string, scope:string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transform this function to fat-arrow function and remove let that = this trick:

const getSecurityDefinition = (name: string, scope: string) => {
  // just use `this` here
}

@wilsonge
Copy link
Contributor

@jimmyjames are you planning on picking up the feedback changes here? I need these for a project so would be happy to pick up if you aren't planning to

@jimmyjames
Copy link
Author

Hey @wilsonge and @RomanGotsiy sorry for the late reply. @wilsonge if you have some bandwidth and can incorporate the feedback changes that would be great - it may be a little bit until I can get back to this. Thanks!

I will test these changes on some major documentations powered by ReDoc and most likely will request some more changes.

@RomanGotsiy did you get a chance to do this?

@wilsonge
Copy link
Contributor

@jimmyjames See jimmyjames#1

@jimmyjames
Copy link
Author

I'm not able to pull the changes and test in the next couple days; @wilsonge can you include a screenshot of how it will look?

Given the desire to not use html-hint, I'm wondering using tooltip is not the right approach at all (unless another solution using hints that supports html content is included), and instead just include the scopes as a subsection under the operation description. It definitely makes the OAuth2 scopes more prominent in the docs instead of tucked away, for better or worse.

@RomanGotsiy curious for your feedback, as well as if you had a chance to test further.

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Aug 2, 2017

Hey @jimmyjames,

sorry for delaying this for so long time. I was on vacation.
Now I'm back and I hope we will merge it soon!

Today I will release a new version of ReDoc (as there are a few fixes already merged) and then I will start testing this.
I aim to have this feature merged in the next release!

Given the desire to not use html-hint, I'm wondering using tooltip is not the right approach at all

Maybe we'll have to go back to html-hint. Will see. Give me a few days and we will merge it finally!

@RomanHotsiy
Copy link
Member

Hey @jimmyjames,

would you mind if I introduce this feature a bit later together with the rewrite to React (#327)?
This way I will have fewer things to migrate.

@jimmyjames
Copy link
Author

@RomanGotsiy sorry I missed this until now.

I understand wanting to minimize the amount of migration done. In our case, our API has many different scopes, and our most of our operations require different scopes. Not having the scopes required per operation shown in the docs is not acceptable for us, but we can fork/modify/host ourselves if we need to until migration is done and the feature is added.

@RomanHotsiy
Copy link
Member

@jimmyjames sorry for not answering for so long...
As far as you may know I'm working on React rewrite of Redoc (#357)

So basic version of this feature is already implemented there.
Hope you can help to improve it :)

Closing this PR in favor of React version.
Thanks!

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 this pull request may close these issues.

3 participants