Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/compiler/core/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -217,6 +223,7 @@ async function getCompilerOptions(args: {
nostdlib?: boolean;
option?: string[];
watch?: boolean;
"diagnostic-level": string;
}): Promise<CompilerOptions> {
// Ensure output path
const outputPath = resolve(args["output-path"]);
Expand All @@ -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,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/compiler/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions packages/compiler/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LogLevel } from "./types";

export interface CompilerOptions {
miscOptions?: any;
outputPath?: string;
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/core/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function createProgram(
const duplicateSymbols = new Set<Sym>();
let error = false;

const logger = createLogger({ sink: host.logSink });
const logger = createLogger({ sink: host.logSink, level: options.diagnosticLevel });

const program: Program = {
compilerOptions: options,
Expand Down
4 changes: 4 additions & 0 deletions packages/compiler/core/semantic-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions packages/compiler/lib/lib.cadl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ namespace Cadl;
// model<K, V> = [K, V][];
// but templates aren't supported with model = yet.
@intrinsic model Map<K, V> {
@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> {
... T;
}

@doc("The template for adding updateable properties.")
@withUpdateableProperties
model UpdateableProperties<T> {
... T;
Expand Down
21 changes: 21 additions & 0 deletions packages/rest/lib/rest.cadl
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
import "../dist/rest.js";

@doc("The request has succeeded.")
model OkResponse<T> {
@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;
}
2 changes: 1 addition & 1 deletion packages/samples/test/output/mutation/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
2 changes: 1 addition & 1 deletion packages/samples/test/output/nested/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
4 changes: 2 additions & 2 deletions packages/samples/test/output/param-decorators/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand All @@ -58,7 +58,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
10 changes: 5 additions & 5 deletions packages/samples/test/output/petstore/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -55,7 +55,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -103,7 +103,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand All @@ -129,7 +129,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -183,7 +183,7 @@
],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -67,7 +67,7 @@
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"description": "The request has succeeded.",
"content": {
"application/json": {
"schema": {
Expand Down