loopbackio / loopbackio/loopback-next
Ordering the enhancers by group name for OpenAPI spec enhancer service
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Suggestion
See discussion in https://github.com/strongloop/loopback-next/pull/4258#discussion_r355542472, 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the OAI spec enhancer service and the CoreBindings.OAS_SPEC_ENHANCER_OPTIONS binding; review the linked pull-request discussion and observer-group loading behavior. Done means the service loads enhancers in configured group order and alphabetically within each group, with tests covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100