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

Add OpenAPI enhancer service in @loopback/rest #4380

Open
jannyHou opened this issue Jan 7, 2020 · 4 comments
Open

Add OpenAPI enhancer service in @loopback/rest #4380

jannyHou opened this issue Jan 7, 2020 · 4 comments
Assignees

Comments

@jannyHou
Copy link
Contributor

@jannyHou jannyHou commented Jan 7, 2020

Suggestion

This is a follow-up story for #4258, after creating the oai enhancer service as extension point, we should add the service in @loopback/rest module so that other enhancers could register and contribute OpenAPI specs into the application(server).

Use Cases

Inside function getApiSpec(), you can apply an enhancer like:

getApiSpec (requestContext?: RequestContext): OpenApiSpec {
  // ...other code
  spec = this.OAIEnhancer.applyEnhancerByName('authorization-bearer');
}

Examples

Same as use cases

Acceptance criteria

@dhmlau

This comment has been minimized.

Copy link
Member

@dhmlau dhmlau commented Jan 15, 2020

@strongloop/loopback-next @strongloop/loopback-maintainers @mschnee

Call for contribution:
This task is part of the epic "Allow out-of-box token based authentication in API Explorer" , that we wish to get it done in 2020Q1. If you're interested in working on it, please leave a message here and we'll assign it to you. We'll take the first person who responds. 😬

Happy contributing!

@dougal83

This comment has been minimized.

Copy link
Contributor

@dougal83 dougal83 commented Jan 30, 2020

#4539 related pull.

@dougal83 dougal83 self-assigned this Jan 30, 2020
@dougal83

This comment has been minimized.

Copy link
Contributor

@dougal83 dougal83 commented Jan 31, 2020

Hi @jannyHou I've had a cursory look over the code and I do have a query on how to proceed with implementation. How would I handle the sync call to an async function(is there an example to study?)

The sync example above:

getApiSpec (requestContext?: RequestContext): OpenApiSpec {
  // ...other code
  spec = this.OASEnhancer.applyEnhancerByName('authorization-bearer');
}

The code in spec-enhancer.service.ts:

  async applyEnhancerByName(name: string): Promise<OpenApiSpec> {
    const enhancer = await this.getEnhancerByName(name);
    if (enhancer) this._spec = enhancer.modifySpec(this._spec);
    return this._spec;
  }

I've not really dealt with this issue before as I could use await. Is there is a particular trick to this implementation?

EDIT: I'll proceed by making getApiSpec async.
EDIT2: Would it be best to implement as a component like AuthStrategies contribution?

@dhmlau

This comment has been minimized.

Copy link
Member

@dhmlau dhmlau commented Feb 13, 2020

PR in progress: #4554

dougal83 added a commit to dougal83/loopback-next that referenced this issue Feb 17, 2020
add openapi spec enhancer to rest server

impl. strongloop#4380

Signed-off-by: Douglas McConnachie <dougal83+git@gmail.com>
dougal83 added a commit to dougal83/loopback-next that referenced this issue Feb 17, 2020
add openapi spec enhancer to rest server

impl. strongloop#4380

Signed-off-by: Douglas McConnachie <dougal83+git@gmail.com>
dougal83 added a commit to dougal83/loopback-next that referenced this issue Feb 17, 2020
add openapi spec enhancer to rest server

impl. strongloop#4380

Signed-off-by: Douglas McConnachie <dougal83+git@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.