From a37a70f46527b4d061cc936943a9356c26a70cd2 Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Fri, 8 Nov 2024 13:06:39 +0800 Subject: [PATCH 1/8] update doc for allowEmptyValue --- .../docs/docs/getting-started/typespec-for-openapi-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md index db5c7e82a4..bbf8a799fc 100644 --- a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md +++ b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md @@ -300,7 +300,7 @@ The following fields of a parameter object are common to both OpenAPI v2 and v3: | `in` | decorator | `@query`, `@path`, `@header`, `@body` | | `description` | `@doc` decorator | | | `required` | from parameter "optionality" | a "?" following the parameter name indicates it is optional (`required: false`), otherwise it is required (`required: true`) | -| `allowEmptyValue` | | Not currently supported. | +| `allowEmptyValue` | | Not supported, this field is `NOT RECOMMENDED` in OpenAPI v3.0.4 | ### OpenAPI v2 From dff9620da89d98a3aceea4da540e67f0f54e1c7a Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Fri, 8 Nov 2024 13:49:54 +0800 Subject: [PATCH 2/8] deprecate for parameters --- packages/openapi3/src/openapi.ts | 4 +++ packages/openapi3/test/openapi-output.test.ts | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index 6659ccdb19..41c1bc9e62 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -1249,6 +1249,10 @@ function createOAPIEmitter( Object.assign(param, attributes); } + if (isDeprecated(program, parameter.param)) { + param.deprecated = true; + } + return param; } diff --git a/packages/openapi3/test/openapi-output.test.ts b/packages/openapi3/test/openapi-output.test.ts index 4a5add228c..6a09f6b894 100644 --- a/packages/openapi3/test/openapi-output.test.ts +++ b/packages/openapi3/test/openapi-output.test.ts @@ -168,6 +168,34 @@ describe("openapi3: operations", () => { strictEqual(res.paths["/"].get.deprecated, true); }); + + it("deprecate inline parameters with #deprecated", async () => { + const res = await openApiFor( + ` + op read( + #deprecated "Cannot use foo" + @query foo: string, + ): void; + `, + ); + + strictEqual(res.paths["/"].get.parameters[0].deprecated, true); + }); + + it("deprecate parameters with #deprecated", async () => { + const res = await openApiFor( + ` + model PetId { + #deprecated "Cannot use foo" + @query foo: string; + } + op get(...PetId): void; + `, + ); + + strictEqual(res.paths["/"].get.parameters[0]["$ref"], "#/components/parameters/PetId"); + strictEqual(res.components.parameters.PetId.deprecated, true); + }); }); describe("openapi3: request", () => { From 0dbac2d3aa8f611ff612da4246e99243b7b7988b Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Fri, 8 Nov 2024 14:57:55 +0800 Subject: [PATCH 3/8] up changed log --- .../changes/ParameterObjectMissing-2024-10-8-14-57-38.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/ParameterObjectMissing-2024-10-8-14-57-38.md diff --git a/.chronus/changes/ParameterObjectMissing-2024-10-8-14-57-38.md b/.chronus/changes/ParameterObjectMissing-2024-10-8-14-57-38.md new file mode 100644 index 0000000000..88ae53a89e --- /dev/null +++ b/.chronus/changes/ParameterObjectMissing-2024-10-8-14-57-38.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/openapi3" +--- + +Add support for `#deprecated` for OpenAPI3Parameter \ No newline at end of file From 418ed21f95a94ba0236883edb6c1523f9e6056a0 Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Mon, 11 Nov 2024 11:50:03 +0800 Subject: [PATCH 4/8] up doc --- .../docs/docs/getting-started/typespec-for-openapi-dev.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md index bbf8a799fc..6d75b02e54 100644 --- a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md +++ b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md @@ -224,7 +224,7 @@ The fields in an OpenAPI operation object are specified with the following TypeS | `requestBody` | parameter with `@body` decorator | see [Request Body Object](#request-body-object-oas3) | | `responses` | `op` return type(s) | see [Responses Object](#responses-object) | | `callbacks` | | Not currently supported. | -| `deprecated` | `@deprecated` decorator | | +| `deprecated` | `#deprecated` decorator | | | `security` | | see [Security Schemes Object](#securityDefinitions--securitySchemes-Object). | | `servers` | `@server` decorator | Can be specified multiple times. | @@ -300,7 +300,7 @@ The following fields of a parameter object are common to both OpenAPI v2 and v3: | `in` | decorator | `@query`, `@path`, `@header`, `@body` | | `description` | `@doc` decorator | | | `required` | from parameter "optionality" | a "?" following the parameter name indicates it is optional (`required: false`), otherwise it is required (`required: true`) | -| `allowEmptyValue` | | Not supported, this field is `NOT RECOMMENDED` in OpenAPI v3.0.4 | +| `allowEmptyValue` | | Not supported, this field is `NOT RECOMMENDED` in OpenAPI. | ### OpenAPI v2 @@ -334,7 +334,7 @@ The following fields of a parameter object are specific to OpenAPI v3: | `style` | `format` parameter on `@query` or `@header` | | | `explode` | `format` parameter on `@query` or `@header` | | | `schema` | parameter schema | see [Schema Object](#schema-object) | -| `deprecated` | | Not currently supported. | +| `deprecated` | | `#deprecated` decorator. | | `example` | | Not currently supported. | | `examples` | | Not currently supported. | | `content` | | Not currently supported. | From 71eecea4efdef090153777d0098d357d6071c32f Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Tue, 12 Nov 2024 17:35:33 +0800 Subject: [PATCH 5/8] up --- packages/openapi3/test/openapi-output.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/openapi3/test/openapi-output.test.ts b/packages/openapi3/test/openapi-output.test.ts index 6a09f6b894..5230e5b080 100644 --- a/packages/openapi3/test/openapi-output.test.ts +++ b/packages/openapi3/test/openapi-output.test.ts @@ -196,6 +196,25 @@ describe("openapi3: operations", () => { strictEqual(res.paths["/"].get.parameters[0]["$ref"], "#/components/parameters/PetId"); strictEqual(res.components.parameters.PetId.deprecated, true); }); + + it("deprecate one in multi parameters with #deprecated", async () => { + const res = await openApiFor( + ` + model PetId { + #deprecated "Cannot use foo" + @query foo: string; + + @path name: string, + } + op get(...PetId): void; + `, + ); + const getThing = res.paths["/{name}"].get; + strictEqual(getThing.parameters[0]["$ref"], "#/components/parameters/PetId.foo"); + strictEqual(getThing.parameters[1]["$ref"], "#/components/parameters/PetId.name"); + strictEqual(res.components.parameters["PetId.foo"].deprecated, true); + strictEqual(res.components.parameters["PetId.name"].deprecated, undefined); + }); }); describe("openapi3: request", () => { From 10fb3b7810cc820cc02d387eb20c2478711f0a0c Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Thu, 14 Nov 2024 07:41:35 +0800 Subject: [PATCH 6/8] Update website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md Co-authored-by: Christopher Radek <14189820+chrisradek@users.noreply.github.com> --- .../docs/docs/getting-started/typespec-for-openapi-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md index 5f1872aea5..23bf4b04b0 100644 --- a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md +++ b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md @@ -343,7 +343,7 @@ The following fields of a parameter object are specific to OpenAPI v3: | `style` | `format` parameter on `@query` or `@header` | | | `explode` | `format` parameter on `@query` or `@header` | | | `schema` | parameter schema | see [Schema Object](#schema-object) | -| `deprecated` | | `#deprecated` decorator. | +| `deprecated` | `#deprecated` directive. | | | `example` | | Not currently supported. | | `examples` | | Not currently supported. | | `content` | | Not currently supported. | From c0cb74516c5691d92fc52912bffd0d6c7e3c9e76 Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Thu, 14 Nov 2024 07:41:50 +0800 Subject: [PATCH 7/8] Update website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md Co-authored-by: Christopher Radek <14189820+chrisradek@users.noreply.github.com> --- .../docs/docs/getting-started/typespec-for-openapi-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md index 23bf4b04b0..2cfa9df4cf 100644 --- a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md +++ b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md @@ -231,7 +231,7 @@ The fields in an OpenAPI operation object are specified with the following TypeS | `requestBody` | parameter with `@body` decorator | see [Request Body Object](#request-body-object-oas3) | | `responses` | `op` return type(s) | see [Responses Object](#responses-object) | | `callbacks` | | Not currently supported. | -| `deprecated` | `#deprecated` decorator | | +| `deprecated` | `#deprecated` directive | | | `security` | | see [Security Schemes Object](#securityDefinitions--securitySchemes-Object). | | `servers` | `@server` decorator | Can be specified multiple times. | From ca0e1c458523b22602e4811d7753a3b68d491630 Mon Sep 17 00:00:00 2001 From: Kyle Zhang Date: Thu, 14 Nov 2024 07:45:24 +0800 Subject: [PATCH 8/8] format --- .../docs/docs/getting-started/typespec-for-openapi-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md index 2cfa9df4cf..a0177e6c30 100644 --- a/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md +++ b/website/src/content/docs/docs/getting-started/typespec-for-openapi-dev.md @@ -343,7 +343,7 @@ The following fields of a parameter object are specific to OpenAPI v3: | `style` | `format` parameter on `@query` or `@header` | | | `explode` | `format` parameter on `@query` or `@header` | | | `schema` | parameter schema | see [Schema Object](#schema-object) | -| `deprecated` | `#deprecated` directive. | | +| `deprecated` | `#deprecated` directive. | | | `example` | | Not currently supported. | | `examples` | | Not currently supported. | | `content` | | Not currently supported. |