From ede4e8d6b5ec86ec5d16570e35c3d3557de6f80b Mon Sep 17 00:00:00 2001 From: jianye xi Date: Thu, 21 Oct 2021 17:22:39 +0800 Subject: [PATCH 1/5] add skip-build-check option & docs --- packages/compiler/core/cli.ts | 7 +++++++ packages/compiler/core/index.ts | 1 + packages/compiler/core/options.ts | 4 ++++ packages/compiler/core/semantic-walker.ts | 4 ++++ packages/compiler/lib/lib.cadl | 2 ++ packages/rest/lib/rest.cadl | 19 +++++++++++++++++++ 6 files changed, 37 insertions(+) diff --git a/packages/compiler/core/cli.ts b/packages/compiler/core/cli.ts index f12c0e4b3a5..3335c475e52 100644 --- a/packages/compiler/core/cli.ts +++ b/packages/compiler/core/cli.ts @@ -57,6 +57,11 @@ async function main() { type: "boolean", default: false, describe: "Watch project files for changes and recompile.", + }) + .option("skip-build-check", { + type: "boolean", + default: false, + describe: "Skip the checks in the onBuild method.", }); }, async (args) => { @@ -217,6 +222,7 @@ async function getCompilerOptions(args: { nostdlib?: boolean; option?: string[]; watch?: boolean; + "skip-build-check"?: boolean; }): Promise { // Ensure output path const outputPath = resolve(args["output-path"]); @@ -239,6 +245,7 @@ async function getCompilerOptions(args: { swaggerOutputFile: resolve(args["output-path"], "openapi.json"), nostdlib: args["nostdlib"], watchForChanges: args["watch"], + skipBuildCheck: args["skip-build-check"], }; } diff --git a/packages/compiler/core/index.ts b/packages/compiler/core/index.ts index b65315ef7b5..53645a125f8 100644 --- a/packages/compiler/core/index.ts +++ b/packages/compiler/core/index.ts @@ -4,6 +4,7 @@ export * from "./library.js"; export * from "./mutators.js"; export * from "./parser.js"; export * from "./program.js"; +export * from "./semantic-walker.js"; export * from "./types.js"; import * as formatter from "../formatter/index.js"; export const CadlPrettierPlugin = formatter; diff --git a/packages/compiler/core/options.ts b/packages/compiler/core/options.ts index 58d6451ac42..2c438c1e19a 100644 --- a/packages/compiler/core/options.ts +++ b/packages/compiler/core/options.ts @@ -6,6 +6,10 @@ export interface CompilerOptions { noEmit?: boolean; watchForChanges?: boolean; serviceCodePath?: string; + /** + * when true , turn off the build check. + */ + skipBuildCheck?: boolean; /** * When true, indicates that a compilation is being performed for live * analysis in the language server. diff --git a/packages/compiler/core/semantic-walker.ts b/packages/compiler/core/semantic-walker.ts index 8e86440393a..2ad0d17f163 100644 --- a/packages/compiler/core/semantic-walker.ts +++ b/packages/compiler/core/semantic-walker.ts @@ -72,6 +72,10 @@ function navigateOperationType( return; } eventEmitter.emit("operation", operation); + for (const parameter of operation.parameters.properties.values()) { + navigateType(parameter, eventEmitter, visited); + } + navigateType(operation.returnType, eventEmitter, visited); } function navigateModelType( diff --git a/packages/compiler/lib/lib.cadl b/packages/compiler/lib/lib.cadl index 1a383566e55..80de70224de 100644 --- a/packages/compiler/lib/lib.cadl +++ b/packages/compiler/lib/lib.cadl @@ -26,11 +26,13 @@ namespace Cadl; v: V } +@doc("The template for adding optional properties.") @withOptionalProperties model OptionalProperties { ... T; } +@doc("The template for adding updateable properties.") @withUpdateableProperties model UpdateableProperties { ... T; diff --git a/packages/rest/lib/rest.cadl b/packages/rest/lib/rest.cadl index 9df0e864814..577354a0e52 100644 --- a/packages/rest/lib/rest.cadl +++ b/packages/rest/lib/rest.cadl @@ -1,43 +1,62 @@ import "../dist/rest.js"; +@doc("The request has succeeded.") model OkResponse { @header statusCode: 200; @body body: T; } +@doc("The Location header.") model LocationHeader { + @doc("The Location header contains the URL where the status of the long running operation can be checked.") @header location: string; } +@doc("The request has succeeded and a new resource has been created as a result.") model CreatedResponse { + @doc("The status code.") @header statusCode: 201; } +@doc("The request has been received but not yet acted upon.") model AcceptedResponse { + @doc("The status code.") @header statusCode: 202; } +@doc("There is no content to send for this request, but the headers may be useful. ") model NoContentResponse { + @doc("The status code.") @header statusCode: 204; } +@doc("The URL of the requested resource has been changed permanently. The new URL is given in the response.") model MovedResponse { + @doc("The status code.") @header statusCode: 301; ... LocationHeader; } +@doc("This is used for caching purposes.") model NotModifiedResponse { + @doc("The status code.") @header statusCode: 304; } +@doc("The server could not understand the request due to invalid syntax.") model UnauthorizedResponse { + @doc("The status code.") @header statusCode: 401; } +@doc("The server can not find the requested resource.") model NotFoundResponse { + @doc("The status code.") @header statusCode: 404; } +@doc("This response is sent when a request conflicts with the current state of the server.") model ConflictResponse { + @doc("The status code.") @header statusCode: 409; } From 702a5cf8564a4b21fdd9b20c318e2e58b276fa68 Mon Sep 17 00:00:00 2001 From: jianye xi Date: Thu, 21 Oct 2021 20:26:36 +0800 Subject: [PATCH 2/5] add docs for built-in types --- packages/compiler/lib/lib.cadl | 2 ++ packages/rest/lib/rest.cadl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/compiler/lib/lib.cadl b/packages/compiler/lib/lib.cadl index 80de70224de..661205253e5 100644 --- a/packages/compiler/lib/lib.cadl +++ b/packages/compiler/lib/lib.cadl @@ -22,7 +22,9 @@ namespace Cadl; // model = [K, V][]; // but templates aren't supported with model = yet. @intrinsic model Map { + @doc("the key of the Map.") k: K, + @doc("the vaule of the Map.") v: V } diff --git a/packages/rest/lib/rest.cadl b/packages/rest/lib/rest.cadl index 577354a0e52..1d615af6c81 100644 --- a/packages/rest/lib/rest.cadl +++ b/packages/rest/lib/rest.cadl @@ -2,7 +2,9 @@ import "../dist/rest.js"; @doc("The request has succeeded.") model OkResponse { + @doc("The status code.") @header statusCode: 200; + @doc("The reponse body.") @body body: T; } From 2f9398a5d6f18a7b51f1f66ac0b2f82be8a48c94 Mon Sep 17 00:00:00 2001 From: jianye xi Date: Fri, 22 Oct 2021 11:02:08 +0800 Subject: [PATCH 3/5] use diagnostic level to instead --- packages/compiler/core/cli.ts | 13 +++++++------ packages/compiler/core/options.ts | 7 +++---- packages/compiler/core/program.ts | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/compiler/core/cli.ts b/packages/compiler/core/cli.ts index 3335c475e52..ee69003488c 100644 --- a/packages/compiler/core/cli.ts +++ b/packages/compiler/core/cli.ts @@ -58,10 +58,11 @@ async function main() { default: false, describe: "Watch project files for changes and recompile.", }) - .option("skip-build-check", { - type: "boolean", - default: false, - describe: "Skip the checks in the onBuild method.", + .option("diagnostic-level", { + type: "string", + default: "info", + choices: ["error", "warn", "info", "verbose", "debug"], + describe: "diagnostics of this level or above will be reported.", }); }, async (args) => { @@ -222,7 +223,7 @@ async function getCompilerOptions(args: { nostdlib?: boolean; option?: string[]; watch?: boolean; - "skip-build-check"?: boolean; + "diagnostic-level": string; }): Promise { // Ensure output path const outputPath = resolve(args["output-path"]); @@ -245,7 +246,7 @@ async function getCompilerOptions(args: { swaggerOutputFile: resolve(args["output-path"], "openapi.json"), nostdlib: args["nostdlib"], watchForChanges: args["watch"], - skipBuildCheck: args["skip-build-check"], + diagnosticLevel: args["diagnostic-level"] as any, }; } diff --git a/packages/compiler/core/options.ts b/packages/compiler/core/options.ts index 2c438c1e19a..fac7fc83dbb 100644 --- a/packages/compiler/core/options.ts +++ b/packages/compiler/core/options.ts @@ -1,3 +1,5 @@ +import { LogLevel } from "./types"; + export interface CompilerOptions { miscOptions?: any; outputPath?: string; @@ -6,10 +8,7 @@ export interface CompilerOptions { noEmit?: boolean; watchForChanges?: boolean; serviceCodePath?: string; - /** - * when true , turn off the build check. - */ - skipBuildCheck?: boolean; + diagnosticLevel?: LogLevel; /** * When true, indicates that a compilation is being performed for live * analysis in the language server. diff --git a/packages/compiler/core/program.ts b/packages/compiler/core/program.ts index 21442a52f1f..48d714707f4 100644 --- a/packages/compiler/core/program.ts +++ b/packages/compiler/core/program.ts @@ -64,7 +64,7 @@ export async function createProgram( const duplicateSymbols = new Set(); let error = false; - const logger = createLogger({ sink: host.logSink }); + const logger = createLogger({ sink: host.logSink, level: options.diagnosticLevel }); const program: Program = { compilerOptions: options, From b880971eeae907ffcca692e6bc5d5c0de4811546 Mon Sep 17 00:00:00 2001 From: jianye xi Date: Fri, 22 Oct 2021 11:27:06 +0800 Subject: [PATCH 4/5] update samples --- packages/samples/test/output/mutation/openapi.json | 2 +- packages/samples/test/output/nested/openapi.json | 2 +- .../samples/test/output/param-decorators/openapi.json | 4 ++-- packages/samples/test/output/petstore/openapi.json | 10 +++++----- .../test/output/testserver/body-boolean/openapi.json | 2 +- .../test/output/testserver/body-time/openapi.json | 4 ++-- .../test/output/testserver/media-types/openapi.json | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/samples/test/output/mutation/openapi.json b/packages/samples/test/output/mutation/openapi.json index 5f87a4fab67..6ded325c147 100644 --- a/packages/samples/test/output/mutation/openapi.json +++ b/packages/samples/test/output/mutation/openapi.json @@ -34,7 +34,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/nested/openapi.json b/packages/samples/test/output/nested/openapi.json index a18f7c8ac4a..69fd6097d85 100644 --- a/packages/samples/test/output/nested/openapi.json +++ b/packages/samples/test/output/nested/openapi.json @@ -17,7 +17,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/param-decorators/openapi.json b/packages/samples/test/output/param-decorators/openapi.json index 70421cac8de..4aad8f73e31 100644 --- a/packages/samples/test/output/param-decorators/openapi.json +++ b/packages/samples/test/output/param-decorators/openapi.json @@ -38,7 +38,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -58,7 +58,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/petstore/openapi.json b/packages/samples/test/output/petstore/openapi.json index 73a598bbe25..93e305afc66 100644 --- a/packages/samples/test/output/petstore/openapi.json +++ b/packages/samples/test/output/petstore/openapi.json @@ -22,7 +22,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -55,7 +55,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -103,7 +103,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -129,7 +129,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -183,7 +183,7 @@ ], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/testserver/body-boolean/openapi.json b/packages/samples/test/output/testserver/body-boolean/openapi.json index 555f24018ea..7bc714910a5 100644 --- a/packages/samples/test/output/testserver/body-boolean/openapi.json +++ b/packages/samples/test/output/testserver/body-boolean/openapi.json @@ -48,7 +48,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/testserver/body-time/openapi.json b/packages/samples/test/output/testserver/body-time/openapi.json index 4641bce43a2..9940a81ab51 100644 --- a/packages/samples/test/output/testserver/body-time/openapi.json +++ b/packages/samples/test/output/testserver/body-time/openapi.json @@ -18,7 +18,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -46,7 +46,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { diff --git a/packages/samples/test/output/testserver/media-types/openapi.json b/packages/samples/test/output/testserver/media-types/openapi.json index f5c48820e92..d14edc8319e 100644 --- a/packages/samples/test/output/testserver/media-types/openapi.json +++ b/packages/samples/test/output/testserver/media-types/openapi.json @@ -18,7 +18,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { @@ -67,7 +67,7 @@ "parameters": [], "responses": { "200": { - "description": "A successful response", + "description": "The request has succeeded.", "content": { "application/json": { "schema": { From bc1fc2d593a2657d0ce44ddfacf65ab02dbf0727 Mon Sep 17 00:00:00 2001 From: jianye xi Date: Fri, 22 Oct 2021 11:28:31 +0800 Subject: [PATCH 5/5] format describe --- packages/compiler/core/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler/core/cli.ts b/packages/compiler/core/cli.ts index ee69003488c..66e68c8deb7 100644 --- a/packages/compiler/core/cli.ts +++ b/packages/compiler/core/cli.ts @@ -62,7 +62,7 @@ async function main() { type: "string", default: "info", choices: ["error", "warn", "info", "verbose", "debug"], - describe: "diagnostics of this level or above will be reported.", + describe: "Diagnostics of this level or above will be reported.", }); }, async (args) => {