diff --git a/packages/compiler/core/cli.ts b/packages/compiler/core/cli.ts index f12c0e4b3a5..66e68c8deb7 100644 --- a/packages/compiler/core/cli.ts +++ b/packages/compiler/core/cli.ts @@ -57,6 +57,12 @@ async function main() { type: "boolean", default: false, describe: "Watch project files for changes and recompile.", + }) + .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) => { @@ -217,6 +223,7 @@ async function getCompilerOptions(args: { nostdlib?: boolean; option?: string[]; watch?: boolean; + "diagnostic-level": string; }): Promise { // Ensure output path const outputPath = resolve(args["output-path"]); @@ -239,6 +246,7 @@ async function getCompilerOptions(args: { swaggerOutputFile: resolve(args["output-path"], "openapi.json"), nostdlib: args["nostdlib"], watchForChanges: args["watch"], + diagnosticLevel: args["diagnostic-level"] as any, }; } 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..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,6 +8,7 @@ export interface CompilerOptions { noEmit?: boolean; watchForChanges?: boolean; serviceCodePath?: string; + 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, 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..661205253e5 100644 --- a/packages/compiler/lib/lib.cadl +++ b/packages/compiler/lib/lib.cadl @@ -22,15 +22,19 @@ 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 } +@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..1d615af6c81 100644 --- a/packages/rest/lib/rest.cadl +++ b/packages/rest/lib/rest.cadl @@ -1,43 +1,64 @@ 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; } +@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; } 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": {