-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: adds several convenience decorators #4406
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
This branch adds the following openapi convenience decorators - @deprecated - @tags - @response This branch adds the following features: - creates a `MethodMultiDecoratorFactory`, allowing multiple uses of the same decorator per method. - adds support for the schema keywords 'allOf', 'anyOf', 'oneOf', and 'not' in resolving schemas with the 'x-ts-type' extension - adds a `get-dist-file` to build as a utility to make it easier to debug a unit test file directly in vscode.
Looks like some stuff left over from a bad |
…-next into feature/more-decorators
|
@mschnee Thank you for the contribution. To make the review process easier, I suggest that we break down this PR into smaller ones and land them incrementally. For example, the 1st PR can be the one to add MethodMultiDecoratorFactory. |
|
@raymondfeng Sure, I can get that started today. |
|
@mschnee, thanks for breaking up the PRs into smaller ones. In order to avoid confusion and to avoid people reviewing this one, is it ok if you close this PR? Thanks! |
|
Done! Thanks for all the fast feedback. |
Warning
This PR is incomplete- I am issuing it to request a preliminary round of feedback.
There are a bunch of concepts involved here that I don't entirely grok- such as the specific implementations of the
DecoratorFactories, and a couple logical decisions that may be incorrect due to my amateur understanding of the OpenAPI specification.Implements #4300
This branch adds the following openapi convenience decorators
@deprecated()to a class or method@tags(tagNames: string [])to a class or method@response(code: number, spec: ModelOrSpec, options?: {contentType: string, description: string})to methods onlyThis branch adds the following features:
MethodMultiDecoratorFactory, allowing multiple uses of thesame decorator per method, see the
@response()decorator.'not' in resolving schemas with the 'x-ts-type' extension
get-dist-filescript topackages/buildas a utility to make it easier todebug a unit test file directly in vscode, see
Debug Current Test File" in.vscode/launch.json`Examples
The following TypeScript code:
The following typec
Will result in the following json:
{ "paths": { "/greet": { "get": { "responses": { "200": { "description": "Standard response for successful HTTP requests.", "content": { "application/json": { "schema": { "type": "object", "properties": { "x": { "type": "int", "default": 1 }, "y": { "type": "string", "default": "2" } } } }, "application/jsonc": { "schema": { "$ref": "#/components/schemas/SuccessModel" } }, "application/pdf": { "schema": { "type": "string", "format": "base64" } } } }, "404": { "description": "The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.", "content": { "application/jsonc": { "schema": { "anyOf": [ { "$ref": "#/components/schemas/FooError" }, { "$ref": "#/components/schemas/BarError" } ] } } } } }, "deprecated": true, "tags": [ "Foo", "Bar" ], "x-operation-name": "greet", "x-controller-name": "MyController", "operationId": "MyController.greet" } } }, "components": { "schemas": { "SuccessModel": { "title": "SuccessModel", "properties": { "message": { "type": "string" } }, "additionalProperties": false }, "FooError": { "title": "FooError", "properties": { "foo": { "type": "string" } }, "additionalProperties": false }, "BarError": { "title": "BarError", "properties": { "bar": { "type": "string" } }, "additionalProperties": false } } } }This PR is missing the following
@description()decoratorThis PR does NOT implement the following
@response(), use the response metadata to hint at the intended response code based on the returned object, or the thrown error, e.g. when a method is decorated as@response(401, SomeAuthError), then returning or catchingSomeAuthErrorshould hint that the response code should be a401instead of a500, without requiring the developer to explicitly set the response code by injecting theResponseobject.This PR has the following missing features or bugs:
reduceSpecContent- does not check if the schema already exists from an existing@opor@apidefinition. It should check if there is an existinganyOf/allOf/oneOfkeyword. What happens next is kind of a question: if there is no keyword block, the existing content should be added into ananyOf, if there is an existinganyOfblock, it should be used. If there's an existingallOforoneOfblock... what happens next is kind of undefined.examplesfrom the@response()decorator options.Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated