-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: adds @tags convenience decorator #4416
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
Conversation
|
I wonder if we should expose such decorators under a namespace (for example, |
|
That's a question I don't myself have an opinion on as a developer. I do know that sometimes, vscode intellisense will auto-import in a way I wasn't expecting: for example, typing But at the same time, I could import * as oas from '@loopback/openapi-v3';
@oas.api({})
@oas.deprecated()
class MyController {
@oas.get('/greet')
public async greet() {}
}My only opinion as a developer is to be able to use some convenience decorators so that I don't have to write and maintain such verbose json blocks. |
|
@bajtos Please review. |
emonddr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I agree with @raymondfeng about : @oas.tag
- Wondering why todo controller from examples is being changed.
0671683 to
7623123
Compare
|
☝️ I am attempting to resolve build issues after the most recent rebase. |
68e2fc1 to
43ba86e
Compare
packages/openapi-v3/src/__tests__/unit/decorators/tags.decorator.unit.ts
Outdated
Show resolved
Hide resolved
packages/openapi-v3/src/__tests__/unit/decorators/tags.decorator.unit.ts
Outdated
Show resolved
Hide resolved
43ba86e to
55f199f
Compare
| ## Convenience Decorators | ||
|
|
||
| While you can supply a fully valid OpenAPI specification for the class-level | ||
| `@api` decorator, and full operation OpenAPI specification for `@op` and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@op -> @operation?
| allow you to supply specific OpenAPI information without requiring you to use | ||
| verbose JSON. | ||
|
|
||
| ## OAS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ## Shortcuts for OpenAPI Spec (OAS) Objects?
|
Thinking about OAS enhancers, would it be a good/practical idea to add an optional description for each tag that would populate a sibling extension property? This information can be used (and cleaned up) by enhancer that would populate "tags": [
"PingController"
],
"x-tags": [
{"description": "Api Ping response" }
], |
|
@mschnee Please address my last two comments so that we can land this PR soon. |
|
Busy week, sorry for the delay! I am making the requested updated now. @dougal83 I love the idea in general- the OAS spec has a top level For the first iteration of these convenience decorators, I'm trying to limit the scope to the direct developer experience of writing controllers. You could probably do this now by creating your own top-level tags object, and referencing it: // in tags file
export const myTags {
Foo: {
name: 'foo',
description: 'foo tag'
},
Bar: {
name: 'bar',
description: 'bar tag'
}
}
export const oasTags = Object.values(myTags); // use this in your api spec
// in controller
import { myTags } from '../../wherever'
@oas.tags(myTags.Foo.name, myTags.Bar.name)
class MyController {} |
55f199f to
d9e856a
Compare
|
Documentation updated. Thanks for your patience and quick response @raymondfeng ! I'm going to take all of your feedback here and apply it to my PRs for the |
|
@mschnee PR landed. Great contribution! 🥇 |
Partially implements: #4300
See: #4406
This has been split from #4406 as a more manageable, smaller PR.
Added
This PR adds
@oas.tagsto Controller classes and methods, and adds an array of tag strings in accordance with the OpenAPI Operation Object specification.As the spec defines
tagsas an optional property, this feature will only addtags: string[]when tags are set, and never an empty array of tags.Using the
@oas.tagsdecorator will set the tags on a path, and will be appended to any@tagsset on a class.This decorator is added to the
oasnamespace export in order to prevent naming conflicts with other popular decorators. The existing decorators in@loopback/openapi-v3have also been added to theoasnamespace (but not removed from the main export).Not supported
This PR has no bearing on the top-level
tagsentity in the OpeAPI Tag Object specification. Operation Tags in the spec are themselves convenience for easily grouping and sorting paths and operations, and don't require an entry in the top level.Examples
Checklist
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated