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

Ordering the enhancers by group name for OpenAPI spec enhancer service #4385

Open
1 task
jannyHou opened this issue Jan 8, 2020 · 4 comments
Open
1 task

Comments

@jannyHou
Copy link
Contributor

jannyHou commented Jan 8, 2020

Suggestion

See discussion in #4258 (comment), when load spec enhancers, people should be able to specify order for them.

A proposal would be using a combination of group and alphabet order like how we load observers group by group in https://loopback.io/doc/en/lb4/Life-cycle.html#observer-groups.

Use Cases

When define an enhancer, you can specify the tag in the binding template like @bind(asSpecEnhancer({CoreTags.OAS_SPEC_ENHANCER_GROUP: 'path'}))

Then specify the enhancer order like:

app
  .bind(CoreBindings.OAS_SPEC_ENHANCER_OPTIONS)
  .to({orderedGroups: ['path', 'component', 'info']});

please note this is just a proposal, the story owner can think of better design to provide the group name and specify the group order through options

For enhancers in the same group, they are loaded according to the name(alphabetically)

Examples

Define a path spec enhancers with tag path and a component enhancer with tag component

@bind(asSpecEnhancer({CoreTags.OAS_SPEC_ENHANCER_GROUP: 'path'}))
export class PathSpecEnhancer implements OASEnhancer {
  name = 'path';
  modifySpec(spec: OpenApiSpec): OpenApiSpec {
    const PathPatchSpec = {
      // some spec
    };
    const mergedSpec = mergeOpenAPISpec(spec, PathPatchSpec);
    return mergedSpec;
  }
}

@bind(asSpecEnhancer({CoreTags.OAS_SPEC_ENHANCER_GROUP: 'component'}))
export class ComponentSpecEnhancer implements OASEnhancer {
  name = 'component';
  modifySpec(spec: OpenApiSpec): OpenApiSpec {
    const ComponentPatchSpec = {
      // some spec
    };
    const mergedSpec = mergeOpenAPISpec(spec, ComponentPatchSpec);
    return mergedSpec;
  }
}

Then specify the enhancer order like:

app
  .bind(CoreBindings.OAS_SPEC_ENHANCER_OPTIONS)
  .to({orderedGroups: ['path', 'component', 'info']});

Acceptance criteria

  • Allow the OAI spec enhancer service to load enhancers by group names.
@dougal83
Copy link
Contributor

dougal83 commented Jan 8, 2020

Another possibility would be to assign weight variable to each enhancer for fine control. Not sure how necessary it is though.

@dhmlau
Copy link
Member

dhmlau commented Mar 17, 2020

Since this issue is nice-to-have, I'm going to remove this from the epic #4391 which is target for Q2.

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@bajtos bajtos removed the p2 label Mar 11, 2021
@stale stale bot removed the stale label Mar 11, 2021
@stale
Copy link

stale bot commented Sep 7, 2021

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Sep 7, 2021
@achrinza achrinza removed the stale label Sep 8, 2021
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

5 participants