From 19fdd167d853bd2e162b3443cf5869e2f53d01e8 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 31 Jul 2023 13:04:17 -0700 Subject: [PATCH 01/18] Migrate to 'yaml' package --- common/config/rush/pnpm-lock.yaml | 14 ++++++++------ packages/compiler/package.json | 3 +-- packages/compiler/src/config/config-loader.ts | 18 ++++++++++++------ .../compiler/src/core/cli/actions/info.ts | 9 +++------ packages/compiler/src/init/init.ts | 4 ++-- packages/compiler/src/yaml/index.ts | 2 ++ packages/compiler/src/yaml/types.ts | 12 ++++++++++++ packages/compiler/src/yaml/yaml-parser.ts | 19 +++++++++++++++++++ packages/compiler/test/cli.test.ts | 8 ++++---- 9 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 packages/compiler/src/yaml/index.ts create mode 100644 packages/compiler/src/yaml/types.ts create mode 100644 packages/compiler/src/yaml/yaml-parser.ts diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 5762cee366a..8ccd6f2ca7a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -119,9 +119,6 @@ importers: globby: specifier: ~13.1.1 version: 13.1.1 - js-yaml: - specifier: ~4.1.0 - version: 4.1.0 mustache: specifier: ~4.2.0 version: 4.2.0 @@ -146,6 +143,9 @@ importers: vscode-languageserver-textdocument: specifier: ~1.0.1 version: 1.0.1 + yaml: + specifier: ~2.3.1 + version: 2.3.1 yargs: specifier: ~17.7.1 version: 17.7.1 @@ -153,9 +153,6 @@ importers: '@types/babel__code-frame': specifier: ~7.0.3 version: 7.0.3 - '@types/js-yaml': - specifier: ~4.0.1 - version: 4.0.1 '@types/mocha': specifier: ~10.0.1 version: 10.0.1 @@ -15593,6 +15590,11 @@ packages: engines: {node: '>= 6'} dev: false + /yaml@2.3.1: + resolution: {integrity: sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==} + engines: {node: '>= 14'} + dev: false + /yargs-parser@20.2.4: resolution: {integrity: sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==} engines: {node: '>=10'} diff --git a/packages/compiler/package.json b/packages/compiler/package.json index 8c4cc9ae7f9..2a979c7a53e 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -77,7 +77,7 @@ "ajv": "~8.12.0", "picocolors": "~1.0.0", "globby": "~13.1.1", - "js-yaml": "~4.1.0", + "yaml": "~2.3.1", "mustache": "~4.2.0", "prettier": "~2.8.7", "prompts": "~2.4.1", @@ -90,7 +90,6 @@ }, "devDependencies": { "@types/babel__code-frame": "~7.0.3", - "@types/js-yaml": "~4.0.1", "@types/mocha": "~10.0.1", "@types/mustache": "~4.2.1", "@types/node": "~18.11.9", diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 92191851960..32ecca41137 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -1,9 +1,11 @@ -import jsyaml from "js-yaml"; import { createDiagnostic } from "../core/messages.js"; import { getDirectoryPath, isPathAbsolute, joinPaths, resolvePath } from "../core/path-utils.js"; import { createJSONSchemaValidator } from "../core/schema-validator.js"; -import { CompilerHost, Diagnostic, NoTarget } from "../core/types.js"; -import { deepClone, deepFreeze, doIO, loadFile, omitUndefined } from "../core/util.js"; +import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js"; +import { deepClone, deepFreeze, doIO, omitUndefined } from "../core/util.js"; +import { createSourceFile } from "../index.js"; +import { YamlScript } from "../yaml/types.js"; +import { parseYaml } from "../yaml/yaml-parser.js"; import { TypeSpecConfigJsonSchema } from "./config-schema.js"; import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js"; @@ -103,7 +105,7 @@ export async function loadTypeSpecConfigFile( host: CompilerHost, filePath: string ): Promise { - const config = await loadConfigFile(host, filePath, jsyaml.load); + const config = await loadConfigFile(host, filePath, parseYaml); if (config.diagnostics.length === 0 && config.extends) { const extendPath = resolvePath(getDirectoryPath(filePath), config.extends); const parent = await loadTypeSpecConfigFile(host, extendPath); @@ -160,12 +162,16 @@ async function searchConfigFile( async function loadConfigFile( host: CompilerHost, filename: string, - loadData: (content: string) => any + loadData: (content: SourceFile) => [YamlScript, readonly Diagnostic[]] ): Promise { let diagnostics: Diagnostic[] = []; const reportDiagnostic = (d: Diagnostic) => diagnostics.push(d); + const file = + (await doIO(host.readFile, filename, reportDiagnostic)) ?? createSourceFile("", filename); + const [yamlScript, yamlDiagnostics] = loadData(file); + yamlDiagnostics.forEach((d) => reportDiagnostic(d)); - let [data, file] = await loadFile(host, filename, loadData, reportDiagnostic); + let data: any = yamlScript.value; if (data) { diagnostics = diagnostics.concat(configValidator.validate(data, file)); diff --git a/packages/compiler/src/core/cli/actions/info.ts b/packages/compiler/src/core/cli/actions/info.ts index cf8cf975d80..9aadb601f43 100644 --- a/packages/compiler/src/core/cli/actions/info.ts +++ b/packages/compiler/src/core/cli/actions/info.ts @@ -1,8 +1,8 @@ /* eslint-disable no-console */ import { fileURLToPath } from "url"; +import { stringify } from "yaml"; import { loadTypeSpecConfigForPath } from "../../../config/config-loader.js"; import { CompilerHost, Diagnostic } from "../../types.js"; - /** * Print the resolved TypeSpec configuration. */ @@ -11,14 +11,11 @@ export async function printInfoAction(host: CompilerHost): Promise - excluded.includes(emitter) ? undefined : value; + const { diagnostics, filename, ...restOfConfig } = config; console.log(`User Config: ${config.filename ?? "No config file found"}`); console.log("-----------"); - console.log(jsyaml.dump(config, { replacer })); + console.log(stringify(restOfConfig)); console.log("-----------"); return config.diagnostics; } diff --git a/packages/compiler/src/init/init.ts b/packages/compiler/src/init/init.ts index e0a71574063..27933ce344e 100644 --- a/packages/compiler/src/init/init.ts +++ b/packages/compiler/src/init/init.ts @@ -1,8 +1,8 @@ import { readdir } from "fs/promises"; -import jsyaml from "js-yaml"; import Mustache from "mustache"; import prompts from "prompts"; import * as semver from "semver"; +import { stringify } from "yaml"; import { TypeSpecConfigFilename } from "../config/config-loader.js"; import { formatTypeSpec } from "../core/formatter.js"; import { createDiagnostic } from "../core/messages.js"; @@ -429,7 +429,7 @@ async function writeConfig(host: CompilerHost, config: ScaffoldingConfig) { if (!config.config) { return; } - const content = jsyaml.dump(config.config); + const content = stringify(config.config); return host.writeFile(joinPaths(config.directory, TypeSpecConfigFilename), content); } diff --git a/packages/compiler/src/yaml/index.ts b/packages/compiler/src/yaml/index.ts new file mode 100644 index 00000000000..b71ed72a603 --- /dev/null +++ b/packages/compiler/src/yaml/index.ts @@ -0,0 +1,2 @@ +export * from "./types.js"; +export * from "./yaml-parser.js"; diff --git a/packages/compiler/src/yaml/types.ts b/packages/compiler/src/yaml/types.ts new file mode 100644 index 00000000000..5720956f0a6 --- /dev/null +++ b/packages/compiler/src/yaml/types.ts @@ -0,0 +1,12 @@ +import { Document } from "yaml"; +import { SourceFile } from "../core/types.js"; + +export interface YamlScript { + readonly kind: "yaml-script"; + readonly file: SourceFile; + /** Value of the yaml script. */ + readonly value: unknown; + + /** @internal */ + readonly doc: Document.Parsed; +} diff --git a/packages/compiler/src/yaml/yaml-parser.ts b/packages/compiler/src/yaml/yaml-parser.ts new file mode 100644 index 00000000000..3b2994555f6 --- /dev/null +++ b/packages/compiler/src/yaml/yaml-parser.ts @@ -0,0 +1,19 @@ +import { parseDocument } from "yaml"; +import { createDiagnosticCollector, createSourceFile } from "../core/diagnostics.js"; +import { Diagnostic, SourceFile } from "../core/types.js"; +import { YamlScript } from "./types.js"; + +export function parseYaml(source: string | SourceFile): [YamlScript, readonly Diagnostic[]] { + const diagnostics = createDiagnosticCollector(); + + const file = typeof source === "string" ? createSourceFile(source, "") : source; + + const doc = parseDocument(file.text); + + return diagnostics.wrap({ + kind: "yaml-script", + file, + value: doc.toJSON(), + doc, + }); +} diff --git a/packages/compiler/test/cli.test.ts b/packages/compiler/test/cli.test.ts index f227038e195..712dc6d3239 100644 --- a/packages/compiler/test/cli.test.ts +++ b/packages/compiler/test/cli.test.ts @@ -1,5 +1,5 @@ import { deepStrictEqual, strictEqual } from "assert"; -import { dump } from "js-yaml"; +import { stringify } from "yaml"; import { TypeSpecRawConfig } from "../src/config/types.js"; import { CompileCliArgs, getCompilerOptions } from "../src/core/cli/actions/compile/args.js"; import { CompilerOptions } from "../src/core/options.js"; @@ -55,7 +55,7 @@ describe("compiler: cli", () => { beforeEach(() => { host.addTypeSpecFile( "ws/tspconfig.yaml", - dump({ + stringify({ parameters: { "custom-arg": { default: "/default-arg-value", @@ -156,7 +156,7 @@ describe("compiler: cli", () => { it("emit diagnostic if using relative path in config paths", async () => { host.addTypeSpecFile( "ws/tspconfig.yaml", - dump({ + stringify({ "output-dir": "./my-output", }) ); @@ -182,7 +182,7 @@ describe("compiler: cli", () => { args?: CompileCliArgs; config?: TypeSpecRawConfig; }) { - host.addTypeSpecFile("ws/tspconfig.yaml", dump(config ?? {})); + host.addTypeSpecFile("ws/tspconfig.yaml", stringify(config ?? {})); return (await resolveCompilerOptions(args ?? {})) ?? {}; } From e83e41d95b046744efec060aa7147ac65c135900 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 11:58:49 -0700 Subject: [PATCH 02/18] Fix server lib --- packages/compiler/src/server/serverlib.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/server/serverlib.ts b/packages/compiler/src/server/serverlib.ts index a10ff34b8a2..64165c5df5d 100644 --- a/packages/compiler/src/server/serverlib.ts +++ b/packages/compiler/src/server/serverlib.ts @@ -385,7 +385,7 @@ export function createServer(host: ServerHost): Server { ): Promise { const path = await getPath(document); const mainFile = await getMainFileForDocument(path); - const config = await getConfig(mainFile, path); + const config = await getConfig(mainFile); const options = { ...serverOptions, @@ -447,8 +447,11 @@ export function createServer(host: ServerHost): Server { } } - async function getConfig(mainFile: string, path: string): Promise { - const configPath = await findTypeSpecConfigPath(compilerHost, mainFile); + async function getConfig(mainFile: string): Promise { + const entrypointStat = await host.compilerHost.stat(mainFile); + + const lookupDir = entrypointStat.isDirectory() ? mainFile : getDirectoryPath(mainFile); + const configPath = await findTypeSpecConfigPath(compilerHost, lookupDir); if (!configPath) { return { ...defaultConfig, projectRoot: getDirectoryPath(mainFile) }; } From ab4be71e6f245f20d291776c395468210ed7a4e1 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 12:49:13 -0700 Subject: [PATCH 03/18] report yaml errors --- packages/compiler/src/yaml/yaml-parser.ts | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/yaml/yaml-parser.ts b/packages/compiler/src/yaml/yaml-parser.ts index 3b2994555f6..c43aaf145d7 100644 --- a/packages/compiler/src/yaml/yaml-parser.ts +++ b/packages/compiler/src/yaml/yaml-parser.ts @@ -1,6 +1,6 @@ -import { parseDocument } from "yaml"; +import { YAMLError, parseDocument } from "yaml"; import { createDiagnosticCollector, createSourceFile } from "../core/diagnostics.js"; -import { Diagnostic, SourceFile } from "../core/types.js"; +import { Diagnostic, DiagnosticSeverity, SourceFile } from "../core/types.js"; import { YamlScript } from "./types.js"; export function parseYaml(source: string | SourceFile): [YamlScript, readonly Diagnostic[]] { @@ -9,7 +9,13 @@ export function parseYaml(source: string | SourceFile): [YamlScript, readonly Di const file = typeof source === "string" ? createSourceFile(source, "") : source; const doc = parseDocument(file.text); - + for (const error of doc.errors) { + diagnostics.add(convertYamlErrorToDiagnostic("error", error, file)); + } + for (const warning of doc.warnings) { + diagnostics.add(convertYamlErrorToDiagnostic("warning", warning, file)); + } + console.log("Doc", doc); return diagnostics.wrap({ kind: "yaml-script", file, @@ -17,3 +23,16 @@ export function parseYaml(source: string | SourceFile): [YamlScript, readonly Di doc, }); } + +function convertYamlErrorToDiagnostic( + severity: DiagnosticSeverity, + error: YAMLError, + file: SourceFile +): Diagnostic { + return { + code: `yaml-${error.code.toLowerCase().replace(/_/g, "-")}`, + message: error.message, + severity, + target: { file, pos: error.pos[0], end: error.pos[1] }, + }; +} From 5a600d2381e253f00183111ff78b4c0013c5d79b Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 14:07:57 -0700 Subject: [PATCH 04/18] Report yaml position --- packages/compiler/src/config/config-loader.ts | 24 +++++--- packages/compiler/src/config/types.ts | 4 ++ packages/compiler/src/yaml/diagnostics.ts | 55 +++++++++++++++++++ packages/compiler/src/yaml/index.ts | 1 + packages/compiler/src/yaml/types.ts | 8 +++ packages/compiler/src/yaml/yaml-parser.ts | 1 - 6 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 packages/compiler/src/yaml/diagnostics.ts diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 32ecca41137..266216670e9 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -4,7 +4,8 @@ import { createJSONSchemaValidator } from "../core/schema-validator.js"; import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js"; import { deepClone, deepFreeze, doIO, omitUndefined } from "../core/util.js"; import { createSourceFile } from "../index.js"; -import { YamlScript } from "../yaml/types.js"; +import { createYamlTarget, getLocationOfYamlTarget } from "../yaml/index.js"; +import { YamlScript, YamlTarget } from "../yaml/types.js"; import { parseYaml } from "../yaml/yaml-parser.js"; import { TypeSpecConfigJsonSchema } from "./config-schema.js"; import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js"; @@ -189,6 +190,7 @@ async function loadConfigFile( return omitUndefined({ projectRoot: getDirectoryPath(filename), + file: yamlScript, filename, diagnostics, extends: data.extends, @@ -207,29 +209,35 @@ async function loadConfigFile( export function validateConfigPathsAbsolute(config: TypeSpecConfig): readonly Diagnostic[] { const diagnostics: Diagnostic[] = []; - function checkPath(value: string | undefined) { + function checkPath(value: string | undefined, path: string[]) { if (value === undefined) { return; } - const diagnostic = validatePathAbsolute(value); + const diagnostic = validatePathAbsolute( + value, + config.file ? createYamlTarget(config.file, path) : NoTarget + ); if (diagnostic) { diagnostics.push(diagnostic); } } - checkPath(config.outputDir); - for (const emitterOptions of Object.values(config.options ?? {})) { - checkPath(emitterOptions["emitter-output-dir"]); + checkPath(config.outputDir, ["output-dir"]); + for (const [emitterName, emitterOptions] of Object.entries(config.options ?? {})) { + checkPath(emitterOptions["emitter-output-dir"], ["options", emitterName, "emitter-output-dir"]); } return diagnostics; } -function validatePathAbsolute(path: string): Diagnostic | undefined { +function validatePathAbsolute( + path: string, + target: YamlTarget | typeof NoTarget +): Diagnostic | undefined { if (path.startsWith(".") || !isPathAbsolute(path)) { return createDiagnostic({ code: "config-path-absolute", format: { path }, - target: NoTarget, + target: target === NoTarget ? NoTarget : getLocationOfYamlTarget(target), }); } diff --git a/packages/compiler/src/config/types.ts b/packages/compiler/src/config/types.ts index c4414ccb69d..ec40bb6af63 100644 --- a/packages/compiler/src/config/types.ts +++ b/packages/compiler/src/config/types.ts @@ -1,4 +1,5 @@ import { Diagnostic, RuleRef } from "../core/index.js"; +import { YamlScript } from "../yaml/types.js"; /** * Represent the normalized user configuration. @@ -9,6 +10,9 @@ export interface TypeSpecConfig { */ projectRoot: string; + /** Yaml file used in this configuration. */ + file?: YamlScript; + /** * Path to the config file used to create this configuration. */ diff --git a/packages/compiler/src/yaml/diagnostics.ts b/packages/compiler/src/yaml/diagnostics.ts new file mode 100644 index 00000000000..4d0fd07c471 --- /dev/null +++ b/packages/compiler/src/yaml/diagnostics.ts @@ -0,0 +1,55 @@ +import { Node, isCollection, isMap, isScalar } from "yaml"; +import { findPair } from "yaml/util"; +import { SourceLocation } from "../core/types.js"; +import { YamlScript, YamlTarget, YamlTargetType } from "./types.js"; + +export function createYamlTarget( + file: YamlScript, + path: string[], + kind: YamlTargetType = "key" +): YamlTarget { + return { + file, + path, + kind, + }; +} + +export function getLocationOfYamlTarget(target: YamlTarget): SourceLocation { + const node: Node | undefined = findYamlNode(target); + return { + file: target.file.file, + pos: node?.range?.[0] ?? 0, + end: node?.range?.[1] ?? 0, + }; +} + +function findYamlNode(target: YamlTarget): Node | undefined { + let current: Node | null = target.file.doc.contents; + + for (let i = 0; i < target.path.length; i++) { + const key = target.path[i]; + const isLast = i === target.path.length - 1; + if (isScalar(current)) { + return current; + } else if (isCollection(current)) { + if (isLast) { + if (target.kind === "value" || !isMap(current)) { + return current.get(key, true); + } else { + const pair = findPair(current.items, key); + if (target.kind === "key") { + return pair?.key as any; + } else { + return pair as any; + } + } + } else { + current = current.get(key, true) as any; + } + } else { + continue; + } + } + return current ?? undefined; +} diff --git a/packages/compiler/src/yaml/index.ts b/packages/compiler/src/yaml/index.ts index b71ed72a603..1bb2e193cad 100644 --- a/packages/compiler/src/yaml/index.ts +++ b/packages/compiler/src/yaml/index.ts @@ -1,2 +1,3 @@ +export * from "./diagnostics.js"; export * from "./types.js"; export * from "./yaml-parser.js"; diff --git a/packages/compiler/src/yaml/types.ts b/packages/compiler/src/yaml/types.ts index 5720956f0a6..f0a1dd5b9e0 100644 --- a/packages/compiler/src/yaml/types.ts +++ b/packages/compiler/src/yaml/types.ts @@ -10,3 +10,11 @@ export interface YamlScript { /** @internal */ readonly doc: Document.Parsed; } + +export interface YamlTarget { + readonly file: YamlScript; + readonly path: string[]; + readonly kind: YamlTargetType; +} + +export type YamlTargetType = "value" | "key"; diff --git a/packages/compiler/src/yaml/yaml-parser.ts b/packages/compiler/src/yaml/yaml-parser.ts index c43aaf145d7..31dcaf8a1ac 100644 --- a/packages/compiler/src/yaml/yaml-parser.ts +++ b/packages/compiler/src/yaml/yaml-parser.ts @@ -15,7 +15,6 @@ export function parseYaml(source: string | SourceFile): [YamlScript, readonly Di for (const warning of doc.warnings) { diagnostics.add(convertYamlErrorToDiagnostic("warning", warning, file)); } - console.log("Doc", doc); return diagnostics.wrap({ kind: "yaml-script", file, From 1cb8d4972f9955f67982c161fda321b284ed815e Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 14:53:15 -0700 Subject: [PATCH 05/18] Allow YamlDiagnosticTarget --- packages/compiler/src/config/config-loader.ts | 10 +++++----- packages/compiler/src/core/diagnostics.ts | 7 ++++++- packages/compiler/src/core/types.ts | 6 +++++- packages/compiler/src/yaml/diagnostics.ts | 12 ++++++------ packages/compiler/src/yaml/types.ts | 14 ++++++++++---- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 266216670e9..05a105b3b47 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -4,8 +4,8 @@ import { createJSONSchemaValidator } from "../core/schema-validator.js"; import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js"; import { deepClone, deepFreeze, doIO, omitUndefined } from "../core/util.js"; import { createSourceFile } from "../index.js"; -import { createYamlTarget, getLocationOfYamlTarget } from "../yaml/index.js"; -import { YamlScript, YamlTarget } from "../yaml/types.js"; +import { createYamlDiagnosticTarget } from "../yaml/index.js"; +import { YamlDiagnosticTarget, YamlScript } from "../yaml/types.js"; import { parseYaml } from "../yaml/yaml-parser.js"; import { TypeSpecConfigJsonSchema } from "./config-schema.js"; import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js"; @@ -215,7 +215,7 @@ export function validateConfigPathsAbsolute(config: TypeSpecConfig): readonly Di } const diagnostic = validatePathAbsolute( value, - config.file ? createYamlTarget(config.file, path) : NoTarget + config.file ? createYamlDiagnosticTarget(config.file, path) : NoTarget ); if (diagnostic) { diagnostics.push(diagnostic); @@ -231,13 +231,13 @@ export function validateConfigPathsAbsolute(config: TypeSpecConfig): readonly Di function validatePathAbsolute( path: string, - target: YamlTarget | typeof NoTarget + target: YamlDiagnosticTarget | typeof NoTarget ): Diagnostic | undefined { if (path.startsWith(".") || !isPathAbsolute(path)) { return createDiagnostic({ code: "config-path-absolute", format: { path }, - target: target === NoTarget ? NoTarget : getLocationOfYamlTarget(target), + target, }); } diff --git a/packages/compiler/src/core/diagnostics.ts b/packages/compiler/src/core/diagnostics.ts index 6cfd429ebb1..5ca73384f66 100644 --- a/packages/compiler/src/core/diagnostics.ts +++ b/packages/compiler/src/core/diagnostics.ts @@ -1,3 +1,4 @@ +import { getLocationOfYamlDiagnosticTarget } from "../yaml/diagnostics.js"; import { CharCode } from "./charcode.js"; import { formatLog } from "./logger/index.js"; import { reportDiagnostic } from "./messages.js"; @@ -172,7 +173,11 @@ export function getSourceLocation( } if ("file" in target) { - return target; + if ("path" in target) { + return getLocationOfYamlDiagnosticTarget(target); + } else { + return target; + } } if (!("kind" in target)) { diff --git a/packages/compiler/src/core/types.ts b/packages/compiler/src/core/types.ts index a9820362405..e5f329dd834 100644 --- a/packages/compiler/src/core/types.ts +++ b/packages/compiler/src/core/types.ts @@ -1,6 +1,7 @@ import type { JSONSchemaType as AjvJSONSchemaType } from "ajv"; import { TypeEmitter } from "../emitter-framework/type-emitter.js"; import { AssetEmitter } from "../emitter-framework/types.js"; +import { YamlDiagnosticTarget } from "../yaml/types.js"; import { ModuleResolutionResult } from "./module-resolver.js"; import { Program } from "./program.js"; @@ -1732,9 +1733,12 @@ export interface SourceLocation extends TextRange { isSynthetic?: boolean; } +/** Used to explicitly specify that a diagnostic has no target. */ export const NoTarget = Symbol.for("NoTarget"); -export type DiagnosticTarget = Node | Type | Sym | SourceLocation; +/** Diagnostic target that can be used when working with TypeSpec types. */ +export type TypeSpecDiagnosticTarget = Node | Type | Sym; +export type DiagnosticTarget = TypeSpecDiagnosticTarget | YamlDiagnosticTarget | SourceLocation; export type DiagnosticSeverity = "error" | "warning"; diff --git a/packages/compiler/src/yaml/diagnostics.ts b/packages/compiler/src/yaml/diagnostics.ts index 4d0fd07c471..1ad140025a7 100644 --- a/packages/compiler/src/yaml/diagnostics.ts +++ b/packages/compiler/src/yaml/diagnostics.ts @@ -1,13 +1,13 @@ import { Node, isCollection, isMap, isScalar } from "yaml"; import { findPair } from "yaml/util"; import { SourceLocation } from "../core/types.js"; -import { YamlScript, YamlTarget, YamlTargetType } from "./types.js"; +import { YamlDiagnosticTarget, YamlDiagnosticTargetType, YamlScript } from "./types.js"; -export function createYamlTarget( +export function createYamlDiagnosticTarget( file: YamlScript, path: string[], - kind: YamlTargetType = "key" -): YamlTarget { + kind: YamlDiagnosticTargetType = "value" +): YamlDiagnosticTarget { return { file, path, @@ -15,7 +15,7 @@ export function createYamlTarget( }; } -export function getLocationOfYamlTarget(target: YamlTarget): SourceLocation { +export function getLocationOfYamlDiagnosticTarget(target: YamlDiagnosticTarget): SourceLocation { const node: Node | undefined = findYamlNode(target); return { file: target.file.file, @@ -24,7 +24,7 @@ export function getLocationOfYamlTarget(target: YamlTarget): SourceLocation { }; } -function findYamlNode(target: YamlTarget): Node | undefined { +function findYamlNode(target: YamlDiagnosticTarget): Node | undefined { let current: Node | null = target.file.doc.contents; for (let i = 0; i < target.path.length; i++) { diff --git a/packages/compiler/src/yaml/types.ts b/packages/compiler/src/yaml/types.ts index f0a1dd5b9e0..7d59cb5cfdc 100644 --- a/packages/compiler/src/yaml/types.ts +++ b/packages/compiler/src/yaml/types.ts @@ -7,14 +7,20 @@ export interface YamlScript { /** Value of the yaml script. */ readonly value: unknown; - /** @internal */ + /** @internal yaml library document. We do not expose this as the "yaml" library is not part of the contract. */ readonly doc: Document.Parsed; } -export interface YamlTarget { +/** + * Diagnostic target pointing to a specific yaml node. + */ +export interface YamlDiagnosticTarget { + /** Yaml script */ readonly file: YamlScript; + /** Path to the target node from the root of the document. */ readonly path: string[]; - readonly kind: YamlTargetType; + /** If targeting the value or the key in the case of a map. */ + readonly kind: YamlDiagnosticTargetType; } -export type YamlTargetType = "value" | "key"; +export type YamlDiagnosticTargetType = "value" | "key"; From 8d5bc778986844ee8334b633ab915d5856f55a4b Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 15:39:47 -0700 Subject: [PATCH 06/18] Show errors for schema validations --- packages/compiler/src/config/config-loader.ts | 2 +- packages/compiler/src/config/config-schema.ts | 1 + .../compiler/src/core/schema-validator.ts | 53 +++++++++++++++++-- packages/compiler/src/core/types.ts | 4 +- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 05a105b3b47..1904be8e0c5 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -175,7 +175,7 @@ async function loadConfigFile( let data: any = yamlScript.value; if (data) { - diagnostics = diagnostics.concat(configValidator.validate(data, file)); + diagnostics = diagnostics.concat(configValidator.validate(data, yamlScript)); } if (!data || diagnostics.length > 0) { diff --git a/packages/compiler/src/config/config-schema.ts b/packages/compiler/src/config/config-schema.ts index e712ab83f77..e717985d1a5 100644 --- a/packages/compiler/src/config/config-schema.ts +++ b/packages/compiler/src/config/config-schema.ts @@ -89,6 +89,7 @@ export const TypeSpecConfigJsonSchema: JSONSchemaType = { type: "object", nullable: true, required: [], + additionalProperties: false, properties: { extends: { type: "array", diff --git a/packages/compiler/src/core/schema-validator.ts b/packages/compiler/src/core/schema-validator.ts index 49bd50f3be1..0e9facf88c8 100644 --- a/packages/compiler/src/core/schema-validator.ts +++ b/packages/compiler/src/core/schema-validator.ts @@ -1,4 +1,6 @@ -import Ajv, { ErrorObject } from "ajv"; +import Ajv, { DefinedError } from "ajv"; +import { createYamlDiagnosticTarget } from "../yaml/diagnostics.js"; +import { YamlScript } from "../yaml/types.js"; import { compilerAssert } from "./diagnostics.js"; import { Diagnostic, JSONSchemaType, JSONSchemaValidator, NoTarget, SourceFile } from "./types.js"; @@ -18,7 +20,10 @@ export function createJSONSchemaValidator( return { validate }; - function validate(config: unknown, target: SourceFile | typeof NoTarget): Diagnostic[] { + function validate( + config: unknown, + target: YamlScript | SourceFile | typeof NoTarget + ): Diagnostic[] { const validate = ajv.compile(schema); const valid = validate(config); compilerAssert( @@ -39,8 +44,8 @@ export function createJSONSchemaValidator( const IGNORED_AJV_PARAMS = new Set(["type", "errors"]); function ajvErrorToDiagnostic( - error: ErrorObject, - target: SourceFile | typeof NoTarget + error: DefinedError, + target: YamlScript | SourceFile | typeof NoTarget ): Diagnostic { const messageLines = [`Schema violation: ${error.message} (${error.instancePath || "/"})`]; for (const [name, value] of Object.entries(error.params).filter( @@ -55,6 +60,44 @@ function ajvErrorToDiagnostic( code: "invalid-schema", message, severity: "error", - target: target === NoTarget ? target : { file: target, pos: 0, end: 0 }, + target: + target === NoTarget + ? target + : "kind" in target + ? createYamlDiagnosticTarget(target, getErrorPath(error), "key") + : { file: target, pos: 0, end: 0 }, }; } + +function getErrorPath(error: DefinedError): string[] { + const instancePath = parseJsonPointer(error.instancePath); + switch (error.keyword) { + case "additionalProperties": + return [...instancePath, error.params.additionalProperty]; + default: + return instancePath; + } +} + +/** + * Converts a json pointer into a array of reference tokens + */ +export function parseJsonPointer(pointer: string): string[] { + if (pointer === "") { + return []; + } + if (pointer.charAt(0) !== "/") { + compilerAssert(false, `Invalid JSON pointer: "${pointer}"`); + } + return pointer.substring(1).split(/\//).map(unescape); +} + +/** + * Unescape a reference token + * + * @param str + * @returns {string} + */ +function unescape(str: string): string { + return str.replace(/~1/g, "/").replace(/~0/g, "~"); +} diff --git a/packages/compiler/src/core/types.ts b/packages/compiler/src/core/types.ts index e5f329dd834..9585b7eeb77 100644 --- a/packages/compiler/src/core/types.ts +++ b/packages/compiler/src/core/types.ts @@ -1,7 +1,7 @@ import type { JSONSchemaType as AjvJSONSchemaType } from "ajv"; import { TypeEmitter } from "../emitter-framework/type-emitter.js"; import { AssetEmitter } from "../emitter-framework/types.js"; -import { YamlDiagnosticTarget } from "../yaml/types.js"; +import { YamlDiagnosticTarget, YamlScript } from "../yaml/types.js"; import { ModuleResolutionResult } from "./module-resolver.js"; import { Program } from "./program.js"; @@ -1952,7 +1952,7 @@ export interface JSONSchemaValidator { * @param target Source file target to use for diagnostics. * @returns Diagnostics produced by schema validation of the configuration. */ - validate(config: unknown, target: SourceFile | typeof NoTarget): Diagnostic[]; + validate(config: unknown, target: YamlScript | SourceFile | typeof NoTarget): Diagnostic[]; } /** @deprecated Use TypeSpecLibraryDef */ From 8567edb5c390eb5c89d9b7cf067bcaaa41555f8d Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 8 Aug 2023 15:55:17 -0700 Subject: [PATCH 07/18] Show all ajv errors --- packages/compiler/src/core/schema-validator.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/core/schema-validator.ts b/packages/compiler/src/core/schema-validator.ts index 0e9facf88c8..87d706241e1 100644 --- a/packages/compiler/src/core/schema-validator.ts +++ b/packages/compiler/src/core/schema-validator.ts @@ -1,4 +1,4 @@ -import Ajv, { DefinedError } from "ajv"; +import Ajv, { DefinedError, Options } from "ajv"; import { createYamlDiagnosticTarget } from "../yaml/diagnostics.js"; import { YamlScript } from "../yaml/types.js"; import { compilerAssert } from "./diagnostics.js"; @@ -16,7 +16,8 @@ export function createJSONSchemaValidator( const ajv = new (Ajv as any)({ strict: options.strict, coerceTypes: options.coerceTypes, - }); + allErrors: true, + } satisfies Options); return { validate }; @@ -47,7 +48,7 @@ function ajvErrorToDiagnostic( error: DefinedError, target: YamlScript | SourceFile | typeof NoTarget ): Diagnostic { - const messageLines = [`Schema violation: ${error.message} (${error.instancePath || "/"})`]; + const messageLines = [`Schema violation: ${error.message} (${error.instancePath ?? "/"})`]; for (const [name, value] of Object.entries(error.params).filter( ([name]) => !IGNORED_AJV_PARAMS.has(name) )) { From 71773adbd43e0b1d06b4b9e5923d4f5b8c6b3226 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 08:24:16 -0700 Subject: [PATCH 08/18] Remove abstraction for now --- packages/compiler/src/config/config-loader.ts | 10 +++--- packages/compiler/src/core/diagnostics.ts | 7 +--- .../compiler/src/core/schema-validator.ts | 4 +-- packages/compiler/src/core/types.ts | 4 +-- packages/compiler/src/yaml/diagnostics.ts | 36 +++++++++---------- 5 files changed, 26 insertions(+), 35 deletions(-) diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 1904be8e0c5..d186cb0c854 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -4,8 +4,8 @@ import { createJSONSchemaValidator } from "../core/schema-validator.js"; import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js"; import { deepClone, deepFreeze, doIO, omitUndefined } from "../core/util.js"; import { createSourceFile } from "../index.js"; -import { createYamlDiagnosticTarget } from "../yaml/index.js"; -import { YamlDiagnosticTarget, YamlScript } from "../yaml/types.js"; +import { getLocationInYamlScript } from "../yaml/index.js"; +import { YamlScript } from "../yaml/types.js"; import { parseYaml } from "../yaml/yaml-parser.js"; import { TypeSpecConfigJsonSchema } from "./config-schema.js"; import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js"; @@ -215,7 +215,7 @@ export function validateConfigPathsAbsolute(config: TypeSpecConfig): readonly Di } const diagnostic = validatePathAbsolute( value, - config.file ? createYamlDiagnosticTarget(config.file, path) : NoTarget + config.file ? { file: config.file, path } : NoTarget ); if (diagnostic) { diagnostics.push(diagnostic); @@ -231,13 +231,13 @@ export function validateConfigPathsAbsolute(config: TypeSpecConfig): readonly Di function validatePathAbsolute( path: string, - target: YamlDiagnosticTarget | typeof NoTarget + target: { file: YamlScript; path: string[] } | typeof NoTarget ): Diagnostic | undefined { if (path.startsWith(".") || !isPathAbsolute(path)) { return createDiagnostic({ code: "config-path-absolute", format: { path }, - target, + target: target === NoTarget ? target : getLocationInYamlScript(target.file, target.path), }); } diff --git a/packages/compiler/src/core/diagnostics.ts b/packages/compiler/src/core/diagnostics.ts index 5ca73384f66..6cfd429ebb1 100644 --- a/packages/compiler/src/core/diagnostics.ts +++ b/packages/compiler/src/core/diagnostics.ts @@ -1,4 +1,3 @@ -import { getLocationOfYamlDiagnosticTarget } from "../yaml/diagnostics.js"; import { CharCode } from "./charcode.js"; import { formatLog } from "./logger/index.js"; import { reportDiagnostic } from "./messages.js"; @@ -173,11 +172,7 @@ export function getSourceLocation( } if ("file" in target) { - if ("path" in target) { - return getLocationOfYamlDiagnosticTarget(target); - } else { - return target; - } + return target; } if (!("kind" in target)) { diff --git a/packages/compiler/src/core/schema-validator.ts b/packages/compiler/src/core/schema-validator.ts index 87d706241e1..e21b580111e 100644 --- a/packages/compiler/src/core/schema-validator.ts +++ b/packages/compiler/src/core/schema-validator.ts @@ -1,5 +1,5 @@ import Ajv, { DefinedError, Options } from "ajv"; -import { createYamlDiagnosticTarget } from "../yaml/diagnostics.js"; +import { getLocationInYamlScript } from "../yaml/diagnostics.js"; import { YamlScript } from "../yaml/types.js"; import { compilerAssert } from "./diagnostics.js"; import { Diagnostic, JSONSchemaType, JSONSchemaValidator, NoTarget, SourceFile } from "./types.js"; @@ -65,7 +65,7 @@ function ajvErrorToDiagnostic( target === NoTarget ? target : "kind" in target - ? createYamlDiagnosticTarget(target, getErrorPath(error), "key") + ? getLocationInYamlScript(target, getErrorPath(error), "key") : { file: target, pos: 0, end: 0 }, }; } diff --git a/packages/compiler/src/core/types.ts b/packages/compiler/src/core/types.ts index 9585b7eeb77..f8268d72b5c 100644 --- a/packages/compiler/src/core/types.ts +++ b/packages/compiler/src/core/types.ts @@ -1,7 +1,7 @@ import type { JSONSchemaType as AjvJSONSchemaType } from "ajv"; import { TypeEmitter } from "../emitter-framework/type-emitter.js"; import { AssetEmitter } from "../emitter-framework/types.js"; -import { YamlDiagnosticTarget, YamlScript } from "../yaml/types.js"; +import { YamlScript } from "../yaml/types.js"; import { ModuleResolutionResult } from "./module-resolver.js"; import { Program } from "./program.js"; @@ -1738,7 +1738,7 @@ export const NoTarget = Symbol.for("NoTarget"); /** Diagnostic target that can be used when working with TypeSpec types. */ export type TypeSpecDiagnosticTarget = Node | Type | Sym; -export type DiagnosticTarget = TypeSpecDiagnosticTarget | YamlDiagnosticTarget | SourceLocation; +export type DiagnosticTarget = TypeSpecDiagnosticTarget | SourceLocation; export type DiagnosticSeverity = "error" | "warning"; diff --git a/packages/compiler/src/yaml/diagnostics.ts b/packages/compiler/src/yaml/diagnostics.ts index 1ad140025a7..2abdecd50eb 100644 --- a/packages/compiler/src/yaml/diagnostics.ts +++ b/packages/compiler/src/yaml/diagnostics.ts @@ -1,44 +1,40 @@ import { Node, isCollection, isMap, isScalar } from "yaml"; import { findPair } from "yaml/util"; import { SourceLocation } from "../core/types.js"; -import { YamlDiagnosticTarget, YamlDiagnosticTargetType, YamlScript } from "./types.js"; +import { YamlDiagnosticTargetType, YamlScript } from "./types.js"; -export function createYamlDiagnosticTarget( +export function getLocationInYamlScript( file: YamlScript, path: string[], kind: YamlDiagnosticTargetType = "value" -): YamlDiagnosticTarget { +): SourceLocation { + const node: Node | undefined = findYamlNode(file, path, kind); return { - file, - path, - kind, - }; -} - -export function getLocationOfYamlDiagnosticTarget(target: YamlDiagnosticTarget): SourceLocation { - const node: Node | undefined = findYamlNode(target); - return { - file: target.file.file, + file: file.file, pos: node?.range?.[0] ?? 0, end: node?.range?.[1] ?? 0, }; } -function findYamlNode(target: YamlDiagnosticTarget): Node | undefined { - let current: Node | null = target.file.doc.contents; +function findYamlNode( + file: YamlScript, + path: string[], + kind: YamlDiagnosticTargetType = "value" +): Node | undefined { + let current: Node | null = file.doc.contents; - for (let i = 0; i < target.path.length; i++) { - const key = target.path[i]; - const isLast = i === target.path.length - 1; + for (let i = 0; i < path.length; i++) { + const key = path[i]; + const isLast = i === path.length - 1; if (isScalar(current)) { return current; } else if (isCollection(current)) { if (isLast) { - if (target.kind === "value" || !isMap(current)) { + if (kind === "value" || !isMap(current)) { return current.get(key, true); } else { const pair = findPair(current.items, key); - if (target.kind === "key") { + if (kind === "key") { return pair?.key as any; } else { return pair as any; From 003aa2a31f783f322d1c3775b25a2d059e4e6bc1 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 08:34:05 -0700 Subject: [PATCH 09/18] Add test for parser --- packages/compiler/src/config/config-loader.ts | 2 +- packages/compiler/src/yaml/index.ts | 2 +- .../src/yaml/{yaml-parser.ts => parser.ts} | 4 ++- packages/compiler/test/yaml/parser.test.ts | 25 +++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) rename packages/compiler/src/yaml/{yaml-parser.ts => parser.ts} (88%) create mode 100644 packages/compiler/test/yaml/parser.test.ts diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index d186cb0c854..c8608585c71 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -5,8 +5,8 @@ import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js import { deepClone, deepFreeze, doIO, omitUndefined } from "../core/util.js"; import { createSourceFile } from "../index.js"; import { getLocationInYamlScript } from "../yaml/index.js"; +import { parseYaml } from "../yaml/parser.js"; import { YamlScript } from "../yaml/types.js"; -import { parseYaml } from "../yaml/yaml-parser.js"; import { TypeSpecConfigJsonSchema } from "./config-schema.js"; import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js"; diff --git a/packages/compiler/src/yaml/index.ts b/packages/compiler/src/yaml/index.ts index 1bb2e193cad..2638e24bbf8 100644 --- a/packages/compiler/src/yaml/index.ts +++ b/packages/compiler/src/yaml/index.ts @@ -1,3 +1,3 @@ export * from "./diagnostics.js"; +export * from "./parser.js"; export * from "./types.js"; -export * from "./yaml-parser.js"; diff --git a/packages/compiler/src/yaml/yaml-parser.ts b/packages/compiler/src/yaml/parser.ts similarity index 88% rename from packages/compiler/src/yaml/yaml-parser.ts rename to packages/compiler/src/yaml/parser.ts index 31dcaf8a1ac..ee5ad615143 100644 --- a/packages/compiler/src/yaml/yaml-parser.ts +++ b/packages/compiler/src/yaml/parser.ts @@ -8,7 +8,9 @@ export function parseYaml(source: string | SourceFile): [YamlScript, readonly Di const file = typeof source === "string" ? createSourceFile(source, "") : source; - const doc = parseDocument(file.text); + const doc = parseDocument(file.text, { + prettyErrors: false, // We are handling the error display ourself to be consistent in the style. + }); for (const error of doc.errors) { diagnostics.add(convertYamlErrorToDiagnostic("error", error, file)); } diff --git a/packages/compiler/test/yaml/parser.test.ts b/packages/compiler/test/yaml/parser.test.ts new file mode 100644 index 00000000000..4e8baca4250 --- /dev/null +++ b/packages/compiler/test/yaml/parser.test.ts @@ -0,0 +1,25 @@ +import { deepStrictEqual } from "assert"; +import { expectDiagnosticEmpty, expectDiagnostics } from "../../src/testing/expect.js"; +import { parseYaml } from "../../src/yaml/parser.js"; + +describe("compiler: yaml: parser", () => { + it("parse yaml", () => { + const [yamlScript, diagnostics] = parseYaml(` + foo: 123 + bar: 456 + `); + expectDiagnosticEmpty(diagnostics); + deepStrictEqual(yamlScript.value, { foo: 123, bar: 456 }); + }); + + it("report errors as diagnostics", () => { + const [_, diagnostics] = parseYaml(` + foo: 123 + foo: 456 + `); + expectDiagnostics(diagnostics, { + code: "yaml-duplicate-key", + message: "Map keys must be unique", + }); + }); +}); From a0059db93d1367910826ebea518ca1d32e63b164 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 08:51:33 -0700 Subject: [PATCH 10/18] Add test for location resolution --- packages/compiler/src/yaml/types.ts | 12 --- .../compiler/test/yaml/diagnostics.test.ts | 83 +++++++++++++++++++ packages/compiler/test/yaml/parser.test.ts | 11 ++- 3 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 packages/compiler/test/yaml/diagnostics.test.ts diff --git a/packages/compiler/src/yaml/types.ts b/packages/compiler/src/yaml/types.ts index 7d59cb5cfdc..6fe808c26a7 100644 --- a/packages/compiler/src/yaml/types.ts +++ b/packages/compiler/src/yaml/types.ts @@ -11,16 +11,4 @@ export interface YamlScript { readonly doc: Document.Parsed; } -/** - * Diagnostic target pointing to a specific yaml node. - */ -export interface YamlDiagnosticTarget { - /** Yaml script */ - readonly file: YamlScript; - /** Path to the target node from the root of the document. */ - readonly path: string[]; - /** If targeting the value or the key in the case of a map. */ - readonly kind: YamlDiagnosticTargetType; -} - export type YamlDiagnosticTargetType = "value" | "key"; diff --git a/packages/compiler/test/yaml/diagnostics.test.ts b/packages/compiler/test/yaml/diagnostics.test.ts new file mode 100644 index 00000000000..be500486445 --- /dev/null +++ b/packages/compiler/test/yaml/diagnostics.test.ts @@ -0,0 +1,83 @@ +import { strictEqual } from "assert"; +import { expectDiagnosticEmpty } from "../../src/testing/expect.js"; +import { extractCursor } from "../../src/testing/test-server-host.js"; +import { getLocationInYamlScript } from "../../src/yaml/diagnostics.js"; +import { parseYaml } from "../../src/yaml/parser.js"; + +describe("compiler: yaml: diagnostics", () => { + function parseValidYaml(code: string) { + const [yamlScript, diagnostics] = parseYaml(code); + expectDiagnosticEmpty(diagnostics); + return yamlScript; + } + + function findRightLocation(code: string, path: string[]) { + const { pos, source } = extractCursor(code); + const yamlScript = parseValidYaml(source); + const location = getLocationInYamlScript(yamlScript, path); + strictEqual(location.pos, pos); + } + + function itFindKeyAndValueLocation(code: string, path: string[]) { + const { pos: keyPos, source: sourceWithoutKeyCursor } = extractCursor(code, "┆K┆"); + const { pos: valuePos, source } = extractCursor(sourceWithoutKeyCursor, "┆V┆"); + + it("value", () => { + const yamlScript = parseValidYaml(source); + const valueLocation = getLocationInYamlScript(yamlScript, path, "value"); + strictEqual(valueLocation.pos, valuePos); + }); + + it("key", () => { + const yamlScript = parseValidYaml(source); + const keyLocation = getLocationInYamlScript(yamlScript, path, "key"); + strictEqual(keyLocation.pos, keyPos); + }); + } + + describe("property at root", () => + itFindKeyAndValueLocation( + ` + one: abc + ┆K┆two: ┆V┆def + three: ghi + `, + ["two"] + )); + + describe("property at in nested object", () => + itFindKeyAndValueLocation( + ` + root: true + nested: + more: + one: abc + ┆K┆two: ┆V┆def + three: ghi + `, + ["nested", "more", "two"] + )); + + describe("property under array", () => + itFindKeyAndValueLocation( + ` + items: + - name: abc + - one: abc + ┆K┆two: ┆V┆def + three: ghi + `, + ["items", "1", "two"] + )); + + it("array item", () => + findRightLocation( + ` + items: + - name: abc + - ┆one: abc + three: ghi + `, + ["items", "1"] + )); +}); diff --git a/packages/compiler/test/yaml/parser.test.ts b/packages/compiler/test/yaml/parser.test.ts index 4e8baca4250..26e35a12df9 100644 --- a/packages/compiler/test/yaml/parser.test.ts +++ b/packages/compiler/test/yaml/parser.test.ts @@ -1,5 +1,6 @@ import { deepStrictEqual } from "assert"; import { expectDiagnosticEmpty, expectDiagnostics } from "../../src/testing/expect.js"; +import { extractCursor } from "../../src/testing/test-server-host.js"; import { parseYaml } from "../../src/yaml/parser.js"; describe("compiler: yaml: parser", () => { @@ -13,13 +14,15 @@ describe("compiler: yaml: parser", () => { }); it("report errors as diagnostics", () => { - const [_, diagnostics] = parseYaml(` - foo: 123 - foo: 456 - `); + const { pos, source } = extractCursor(` + foo: 123 + ┆foo: 456 + `); + const [_, diagnostics] = parseYaml(source); expectDiagnostics(diagnostics, { code: "yaml-duplicate-key", message: "Map keys must be unique", + pos, }); }); }); From d3c602c19d43b5b81816b0d0789cf8471fa66d5f Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 09:13:33 -0700 Subject: [PATCH 11/18] replace all js-yaml with yaml: --- common/config/rush/pnpm-lock.yaml | 40 ++++++------------- docs/extending-typespec/basics.md | 2 +- eng/scripts/package.json | 6 +-- packages/compiler/test/config/config.test.ts | 2 +- packages/json-schema/package.json | 4 +- .../json-schema/src/json-schema-emitter.ts | 4 +- packages/json-schema/test/utils.ts | 4 +- packages/migrate/package.json | 3 +- .../src/migrations/v0.41/typespec-rename.ts | 6 +-- packages/openapi3/package.json | 3 +- packages/openapi3/src/openapi.ts | 9 ++--- .../rollup.config.mjs | 2 +- packages/tspd/package.json | 3 +- packages/tspd/src/ref-doc/api-docs.ts | 4 +- 14 files changed, 32 insertions(+), 60 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 44fb0bb0d04..9a37b95abde 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -453,13 +453,10 @@ importers: ../../packages/json-schema: dependencies: - js-yaml: - specifier: ~4.1.0 - version: 4.1.0 + yaml: + specifier: ~2.3.1 + version: 2.3.1 devDependencies: - '@types/js-yaml': - specifier: ~4.0.1 - version: 4.0.1 '@types/mocha': specifier: ~10.0.1 version: 10.0.1 @@ -610,22 +607,19 @@ importers: globby: specifier: ~13.1.1 version: 13.1.1 - js-yaml: - specifier: ~4.1.0 - version: 4.1.0 prettier: specifier: ~3.0.1 version: 3.0.1 semver: specifier: ^7.3.8 version: 7.3.8 + yaml: + specifier: ~2.3.1 + version: 2.3.1 yargs: specifier: ~17.7.1 version: 17.7.1 devDependencies: - '@types/js-yaml': - specifier: ~4.0.1 - version: 4.0.1 '@types/mocha': specifier: ~10.0.1 version: 10.0.1 @@ -719,13 +713,10 @@ importers: ../../packages/openapi3: dependencies: - js-yaml: - specifier: ~4.1.0 - version: 4.1.0 + yaml: + specifier: ~2.3.1 + version: 2.3.1 devDependencies: - '@types/js-yaml': - specifier: ~4.0.1 - version: 4.0.1 '@types/mocha': specifier: ~10.0.1 version: 10.0.1 @@ -1256,22 +1247,19 @@ importers: '@typespec/compiler': specifier: workspace:~0.46.0 version: link:../compiler - js-yaml: - specifier: ~4.1.0 - version: 4.1.0 picocolors: specifier: ~1.0.0 version: 1.0.0 prettier: specifier: ~3.0.1 version: 3.0.1 + yaml: + specifier: ~2.3.1 + version: 2.3.1 yargs: specifier: ~17.7.1 version: 17.7.1 devDependencies: - '@types/js-yaml': - specifier: ~4.0.1 - version: 4.0.1 '@types/mocha': specifier: ~10.0.1 version: 10.0.1 @@ -6464,10 +6452,6 @@ packages: '@types/istanbul-lib-report': 3.0.0 dev: false - /@types/js-yaml@4.0.1: - resolution: {integrity: sha512-xdOvNmXmrZqqPy3kuCQ+fz6wA0xU5pji9cd1nDrflWaAWtYLLGk5ykW0H6yg5TVyehHP1pfmuuSaZkhP+kspVA==} - dev: true - /@types/json-schema@7.0.12: resolution: {integrity: sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==} diff --git a/docs/extending-typespec/basics.md b/docs/extending-typespec/basics.md index c2a04c7487a..36ce99e4887 100644 --- a/docs/extending-typespec/basics.md +++ b/docs/extending-typespec/basics.md @@ -150,7 +150,7 @@ TypeSpec libraries are defined using `peerDependencies` so we don't end-up with ```jsonc { "dependencies": { - "js-yaml": "~4.1.0" // This is a regular package this library/emitter will use + "yaml": "~2.3.1" // This is a regular package this library/emitter will use }, "peerDependencies": { // Those are all TypeSpec libraries this library/emitter depend on diff --git a/eng/scripts/package.json b/eng/scripts/package.json index 6e1754bd87e..3dbc1ca591c 100644 --- a/eng/scripts/package.json +++ b/eng/scripts/package.json @@ -1,7 +1,3 @@ { - "type": "module", - "dependencies": { - "autorest": "^3.3.2", - "js-yaml": "^4.1.0" - } + "type": "module" } diff --git a/packages/compiler/test/config/config.test.ts b/packages/compiler/test/config/config.test.ts index 921887ab662..70f6bbe2c4e 100644 --- a/packages/compiler/test/config/config.test.ts +++ b/packages/compiler/test/config/config.test.ts @@ -14,7 +14,7 @@ describe("compiler: config file loading", () => { const scenarioRoot = resolve(__dirname, "../../../test/config/scenarios"); const loadTestConfig = async (path: string, errorIfNotFound: boolean = true) => { const fullPath = join(scenarioRoot, path); - const { filename, projectRoot, ...config } = await loadTypeSpecConfigForPath( + const { filename, projectRoot, file, ...config } = await loadTypeSpecConfigForPath( NodeHost, fullPath, errorIfNotFound diff --git a/packages/json-schema/package.json b/packages/json-schema/package.json index 9797ad6e227..b21ecf3df15 100644 --- a/packages/json-schema/package.json +++ b/packages/json-schema/package.json @@ -61,12 +61,10 @@ "rimraf": "~5.0.1", "typescript": "~5.1.3", "ajv": "~8.12.0", - "@types/js-yaml": "~4.0.1", "@typespec/internal-build-utils": "workspace:~0.46.0", - "js-yaml": "~4.1.0", "ajv-formats": "~2.1.1" }, "dependencies": { - "js-yaml": "~4.1.0" + "yaml": "~2.3.1" } } diff --git a/packages/json-schema/src/json-schema-emitter.ts b/packages/json-schema/src/json-schema-emitter.ts index d6e73bf27c8..6509f7ae183 100644 --- a/packages/json-schema/src/json-schema-emitter.ts +++ b/packages/json-schema/src/json-schema-emitter.ts @@ -44,7 +44,7 @@ import { SourceFileScope, TypeEmitter, } from "@typespec/compiler/emitter-framework"; -import yaml from "js-yaml"; +import { stringify } from "yaml"; import { findBaseUri, getContains, @@ -592,7 +592,7 @@ export class JsonSchemaEmitter extends TypeEmitter, JSONSche if (this.emitter.getOptions()["file-type"] === "json") { serializedContent = JSON.stringify(content, null, 4); } else { - serializedContent = yaml.dump(content); + serializedContent = stringify(content); } return { diff --git a/packages/json-schema/test/utils.ts b/packages/json-schema/test/utils.ts index fe573f809d1..d2a1d36c183 100644 --- a/packages/json-schema/test/utils.ts +++ b/packages/json-schema/test/utils.ts @@ -1,6 +1,6 @@ import { createAssetEmitter } from "@typespec/compiler/emitter-framework"; import { createTestHost } from "@typespec/compiler/testing"; -import yaml from "js-yaml"; +import { parse } from "yaml"; import { JsonSchemaEmitter } from "../src/json-schema-emitter.js"; import { JSONSchemaEmitterOptions } from "../src/lib.js"; import { JsonSchemaTestLibrary } from "../src/testing/index.js"; @@ -52,7 +52,7 @@ export async function emitSchema( for (const file of files) { const sf = await emitter.getProgram().host.readFile(`./cadl-output/${file}`); if (options?.["file-type"] === "yaml") { - schemas[file] = yaml.load(sf.text); + schemas[file] = parse(sf.text); } else { schemas[file] = JSON.parse(sf.text); } diff --git a/packages/migrate/package.json b/packages/migrate/package.json index 4be11e301d0..05b15165b0b 100644 --- a/packages/migrate/package.json +++ b/packages/migrate/package.json @@ -48,12 +48,11 @@ "prettier": "~3.0.1", "semver": "^7.3.8", "yargs": "~17.7.1", - "js-yaml": "~4.1.0" + "yaml": "~2.3.1" }, "devDependencies": { "@types/mocha": "~10.0.1", "@types/node": "~18.11.9", - "@types/js-yaml": "~4.0.1", "@types/semver": "^7.3.13", "@types/yargs": "~17.0.24", "@typespec/compiler": "workspace:~0.46.0", diff --git a/packages/migrate/src/migrations/v0.41/typespec-rename.ts b/packages/migrate/src/migrations/v0.41/typespec-rename.ts index 009e66beb9c..732aff1b638 100644 --- a/packages/migrate/src/migrations/v0.41/typespec-rename.ts +++ b/packages/migrate/src/migrations/v0.41/typespec-rename.ts @@ -1,8 +1,8 @@ import type { Node, TypeSpecScriptNode } from "@typespec/compiler"; import { NodePackage, getAnyExtensionFromPath } from "@typespec/compiler"; import { readFile } from "fs/promises"; -import * as yaml from "js-yaml"; import * as path from "path"; +import * as yaml from "yaml"; import type { TypeSpecCompilerV0_40 } from "../../migration-config.js"; import { AstContentMigrateAction, @@ -221,7 +221,7 @@ export const migrateTspConfigFile = createFileContentMigration({ // load data & convert to new format if needed to let tspConfig: any; try { - tspConfig = yaml.load(content); + tspConfig = yaml.parse(content); // if config has older deprecated emitters format, convert to new format if (tspConfig?.emitters !== undefined) { (tspConfig as { emit: Array }).emit = []; @@ -239,7 +239,7 @@ export const migrateTspConfigFile = createFileContentMigration({ tspConfig.emitters = undefined; if (tspConfig.options.length === 0) tspConfig.options = undefined; - content = yaml.dump(tspConfig); + content = yaml.stringify(tspConfig); } } catch (err) { console.warn( diff --git a/packages/openapi3/package.json b/packages/openapi3/package.json index ee2c53cf390..1fc9b027203 100644 --- a/packages/openapi3/package.json +++ b/packages/openapi3/package.json @@ -53,7 +53,7 @@ "!dist/test/**" ], "dependencies": { - "js-yaml": "~4.1.0" + "yaml": "~2.3.1" }, "peerDependencies": { "@typespec/versioning": "workspace:~0.46.0", @@ -65,7 +65,6 @@ "devDependencies": { "@types/mocha": "~10.0.1", "@types/node": "~18.11.9", - "@types/js-yaml": "~4.0.1", "@typespec/compiler": "workspace:~0.46.0", "@typespec/http": "workspace:~0.46.0", "@typespec/rest": "workspace:~0.46.0", diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index 8e64c6dc478..7d36ec17017 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -97,7 +97,7 @@ import { shouldInline, } from "@typespec/openapi"; import { buildVersionProjections } from "@typespec/versioning"; -import yaml from "js-yaml"; +import { stringify } from "yaml"; import { getOneOf, getRef } from "./decorators.js"; import { FileType, OpenAPI3EmitterOptions, reportDiagnostic } from "./lib.js"; import { @@ -2045,11 +2045,8 @@ function serializeDocument(root: OpenAPI3Document, fileType: FileType): string { case "json": return prettierOutput(JSON.stringify(root, null, 2)); case "yaml": - return yaml.dump(root, { - noRefs: true, - replacer: function (key, value) { - return value instanceof Ref ? value.toJSON() : value; - }, + return stringify(root, (key, value) => { + return value instanceof Ref ? value.toJSON() : value; }); } } diff --git a/packages/prettier-plugin-typespec/rollup.config.mjs b/packages/prettier-plugin-typespec/rollup.config.mjs index e7ed0d41620..4184dc6eeb8 100644 --- a/packages/prettier-plugin-typespec/rollup.config.mjs +++ b/packages/prettier-plugin-typespec/rollup.config.mjs @@ -19,7 +19,7 @@ export default defineConfig({ treeshake: { // Ignore those 2 modules are they aren't used in the code needed for the formatter. // Otherwise rollup think they have side effect and to include a lot of unnecessary code in the bundle. - moduleSideEffects: ["ajv", "js-yaml"], + moduleSideEffects: ["ajv"], }, plugins: [ resolve({ preferBuiltins: true }), diff --git a/packages/tspd/package.json b/packages/tspd/package.json index d71a8a55371..52fecd294f5 100644 --- a/packages/tspd/package.json +++ b/packages/tspd/package.json @@ -54,7 +54,7 @@ ], "dependencies": { "@typespec/compiler": "workspace:~0.46.0", - "js-yaml": "~4.1.0", + "yaml": "~2.3.1", "prettier": "~3.0.1", "picocolors": "~1.0.0", "yargs": "~17.7.1" @@ -65,7 +65,6 @@ "@typespec/prettier-plugin-typespec": "workspace:~0.46.0", "@types/mocha": "~10.0.1", "@types/node": "~18.11.9", - "@types/js-yaml": "~4.0.1", "@types/yargs": "~17.0.24", "c8": "~8.0.0", "eslint": "^8.42.0", diff --git a/packages/tspd/src/ref-doc/api-docs.ts b/packages/tspd/src/ref-doc/api-docs.ts index ed4a9db7bc4..863f89eb100 100644 --- a/packages/tspd/src/ref-doc/api-docs.ts +++ b/packages/tspd/src/ref-doc/api-docs.ts @@ -1,8 +1,8 @@ import { joinPaths } from "@typespec/compiler"; import { writeFile } from "fs/promises"; -import { dump } from "js-yaml"; import { Application, DeclarationReflection, PageEvent, ReflectionKind } from "typedoc"; import { PluginOptions, load } from "typedoc-plugin-markdown"; +import { stringify } from "yaml"; export async function generateJsApiDocs(libraryPath: string, outputDir: string) { const app = new Application(); @@ -66,7 +66,7 @@ export function loadRenderer(app: Application) { } function createFrontMatter(model: DeclarationReflection) { - return ["---", dump(createFrontMatterData(model)), "---", ""].join("\n"); + return ["---", stringify(createFrontMatterData(model)), "---", ""].join("\n"); } function createFrontMatterData(model: DeclarationReflection) { From 89ab03540230e1b288e3434a5b1f92ea3a9065cf Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 09:15:55 -0700 Subject: [PATCH 12/18] Error location --- .../feature-yaml-ast_2023-08-09-16-14.json | 15 +++++++++++++++ .../feature-yaml-ast_2023-08-09-16-14.json | 10 ++++++++++ .../feature-yaml-ast_2023-08-09-16-14.json | 10 ++++++++++ .../feature-yaml-ast_2023-08-09-16-14.json | 10 ++++++++++ .../feature-yaml-ast_2023-08-09-16-14.json | 10 ++++++++++ 5 files changed, 55 insertions(+) create mode 100644 common/changes/@typespec/compiler/feature-yaml-ast_2023-08-09-16-14.json create mode 100644 common/changes/@typespec/json-schema/feature-yaml-ast_2023-08-09-16-14.json create mode 100644 common/changes/@typespec/migrate/feature-yaml-ast_2023-08-09-16-14.json create mode 100644 common/changes/@typespec/openapi3/feature-yaml-ast_2023-08-09-16-14.json create mode 100644 common/changes/@typespec/prettier-plugin-typespec/feature-yaml-ast_2023-08-09-16-14.json diff --git a/common/changes/@typespec/compiler/feature-yaml-ast_2023-08-09-16-14.json b/common/changes/@typespec/compiler/feature-yaml-ast_2023-08-09-16-14.json new file mode 100644 index 00000000000..213a1a3af0f --- /dev/null +++ b/common/changes/@typespec/compiler/feature-yaml-ast_2023-08-09-16-14.json @@ -0,0 +1,15 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "Changed yaml parser from `js-yaml` to `yaml`", + "type": "none" + }, + { + "packageName": "@typespec/compiler", + "comment": "Parsing and validation of the tspconfig.yaml will not report the error location.", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} diff --git a/common/changes/@typespec/json-schema/feature-yaml-ast_2023-08-09-16-14.json b/common/changes/@typespec/json-schema/feature-yaml-ast_2023-08-09-16-14.json new file mode 100644 index 00000000000..45dc5b87f29 --- /dev/null +++ b/common/changes/@typespec/json-schema/feature-yaml-ast_2023-08-09-16-14.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/json-schema", + "comment": "Changed yaml parser from `js-yaml` to `yaml`", + "type": "none" + } + ], + "packageName": "@typespec/json-schema" +} \ No newline at end of file diff --git a/common/changes/@typespec/migrate/feature-yaml-ast_2023-08-09-16-14.json b/common/changes/@typespec/migrate/feature-yaml-ast_2023-08-09-16-14.json new file mode 100644 index 00000000000..0ba5281da7d --- /dev/null +++ b/common/changes/@typespec/migrate/feature-yaml-ast_2023-08-09-16-14.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/migrate", + "comment": "Changed yaml parser from `js-yaml` to `yaml`", + "type": "none" + } + ], + "packageName": "@typespec/migrate" +} \ No newline at end of file diff --git a/common/changes/@typespec/openapi3/feature-yaml-ast_2023-08-09-16-14.json b/common/changes/@typespec/openapi3/feature-yaml-ast_2023-08-09-16-14.json new file mode 100644 index 00000000000..212eec718a3 --- /dev/null +++ b/common/changes/@typespec/openapi3/feature-yaml-ast_2023-08-09-16-14.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/openapi3", + "comment": "Changed yaml parser from `js-yaml` to `yaml`", + "type": "none" + } + ], + "packageName": "@typespec/openapi3" +} \ No newline at end of file diff --git a/common/changes/@typespec/prettier-plugin-typespec/feature-yaml-ast_2023-08-09-16-14.json b/common/changes/@typespec/prettier-plugin-typespec/feature-yaml-ast_2023-08-09-16-14.json new file mode 100644 index 00000000000..6c41a3f9663 --- /dev/null +++ b/common/changes/@typespec/prettier-plugin-typespec/feature-yaml-ast_2023-08-09-16-14.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/prettier-plugin-typespec", + "comment": "Changed yaml parser from `js-yaml` to `yaml`", + "type": "none" + } + ], + "packageName": "@typespec/prettier-plugin-typespec" +} \ No newline at end of file From 0d949187a25b557350ae65df70b96c388c59d4e2 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 09:34:41 -0700 Subject: [PATCH 13/18] Fix merge conflict --- common/config/rush/pnpm-lock.yaml | 208 +++++++++++++++--------------- packages/json-schema/package.json | 6 - packages/openapi3/package.json | 12 -- packages/tspd/package.json | 7 +- 4 files changed, 105 insertions(+), 128 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 9a37b95abde..78e5180a6ab 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -17,13 +17,13 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec c8: specifier: ~8.0.0 @@ -68,7 +68,7 @@ importers: specifier: ~3.0.1 version: 3.0.1(rollup@3.24.0) '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler rollup: specifier: ~3.24.0 @@ -81,7 +81,7 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec c8: specifier: ~8.0.0 @@ -175,10 +175,10 @@ importers: specifier: ~17.0.24 version: 17.0.24 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils c8: specifier: ~8.0.0 @@ -211,7 +211,7 @@ importers: specifier: ~0.5.19 version: 0.5.19 tmlanguage-generator: - specifier: workspace:~0.4.2 + specifier: workspace:~0.4.3 version: link:../tmlanguage-generator typescript: specifier: ~5.1.3 @@ -272,7 +272,7 @@ importers: specifier: ^6.2.1 version: 6.2.1(eslint@8.42.0)(typescript@5.1.3) '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec c8: specifier: ~8.0.0 @@ -330,10 +330,10 @@ importers: specifier: ~18.2.4 version: 18.2.4 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec c8: specifier: ~8.0.0 @@ -366,16 +366,16 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/tspd': specifier: workspace:~0.46.0 @@ -424,7 +424,7 @@ importers: specifier: ~17.0.24 version: 17.0.24 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec c8: specifier: ~8.0.0 @@ -464,19 +464,19 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/tspd': specifier: workspace:~0.46.0 @@ -518,10 +518,10 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec c8: specifier: ~8.0.0 @@ -554,13 +554,13 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec c8: specifier: ~8.0.0 @@ -587,7 +587,7 @@ importers: ../../packages/migrate: dependencies: '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/compiler-v0.37': specifier: npm:@cadl-lang/compiler@0.37.0 @@ -633,10 +633,10 @@ importers: specifier: ~17.0.24 version: 17.0.24 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec c8: specifier: ~8.0.0 @@ -669,22 +669,22 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/tspd': specifier: workspace:~0.46.0 @@ -724,31 +724,31 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/openapi': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/tspd': specifier: workspace:~0.46.0 version: link:../tspd '@typespec/versioning': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../versioning c8: specifier: ~8.0.0 @@ -784,28 +784,28 @@ importers: specifier: ~2.0.190 version: 2.0.190(react@18.2.0) '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/html-program-viewer': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../html-program-viewer '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/openapi': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi '@typespec/openapi3': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi3 '@typespec/protobuf': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../protobuf '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/versioning': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../versioning debounce: specifier: ~1.2.1 @@ -869,7 +869,7 @@ importers: specifier: workspace:~0.1.0 version: link:../bundler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@vitejs/plugin-react': specifier: ~4.0.0 @@ -911,34 +911,34 @@ importers: specifier: ^11.11.1 version: 11.11.1(@types/react@18.2.9)(react@18.2.0) '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/html-program-viewer': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../html-program-viewer '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/json-schema': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../json-schema '@typespec/openapi': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi '@typespec/openapi3': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi3 '@typespec/playground': specifier: workspace:~0.44.0 version: link:../playground '@typespec/protobuf': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../protobuf '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/versioning': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../versioning react: specifier: ~18.2.0 @@ -978,7 +978,7 @@ importers: specifier: workspace:~0.1.0 version: link:../bundler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@vitejs/plugin-react': specifier: ~4.0.0 @@ -1033,10 +1033,10 @@ importers: specifier: ~5.0.2 version: 5.0.2(rollup@3.24.0) '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils mocha: specifier: ~10.2.0 @@ -1066,13 +1066,13 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/tspd': specifier: workspace:~0.46.0 @@ -1105,19 +1105,19 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/tspd': specifier: workspace:~0.46.0 @@ -1150,25 +1150,25 @@ importers: specifier: workspace:~0.45.0 version: link:../best-practices '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/html-program-viewer': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../html-program-viewer '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/openapi': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi '@typespec/openapi3': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi3 '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/versioning': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../versioning devDependencies: '@types/mocha': @@ -1178,10 +1178,10 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils autorest: specifier: ~3.3.2 @@ -1208,7 +1208,7 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils ecmarkup: specifier: ~12.0.3 @@ -1230,7 +1230,7 @@ importers: specifier: ~3.0.2 version: 3.0.2 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec eslint: specifier: ^8.42.0 @@ -1245,7 +1245,7 @@ importers: ../../packages/tspd: dependencies: '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler picocolors: specifier: ~1.0.0 @@ -1270,10 +1270,10 @@ importers: specifier: ~17.0.24 version: 17.0.24 '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/prettier-plugin-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../prettier-plugin-typespec c8: specifier: ~8.0.0 @@ -1309,10 +1309,10 @@ importers: ../../packages/typespec-vs: devDependencies: '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils typespec-vscode: - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../typespec-vscode ../../packages/typespec-vscode: @@ -1333,13 +1333,13 @@ importers: specifier: ~1.53.0 version: 1.53.0 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/internal-build-utils': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../internal-build-utils '@vscode/vsce': specifier: ~2.15.0 @@ -1381,16 +1381,16 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/eslint-plugin': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-plugin-typespec '@typespec/library-linter': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../library-linter '@typespec/tspd': specifier: workspace:~0.46.0 @@ -1454,28 +1454,28 @@ importers: specifier: ~18.11.9 version: 18.11.9 '@typespec/compiler': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../compiler '@typespec/eslint-config-typespec': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../eslint-config-typespec '@typespec/http': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../http '@typespec/json-schema': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../json-schema '@typespec/openapi': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi '@typespec/openapi3': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../openapi3 '@typespec/protobuf': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../protobuf '@typespec/rest': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../rest '@typespec/spec': specifier: workspace:* @@ -1484,7 +1484,7 @@ importers: specifier: workspace:~0.46.0 version: link:../tspd '@typespec/versioning': - specifier: workspace:~0.46.0 + specifier: workspace:~0.47.0 version: link:../versioning dotenv: specifier: ~16.1.3 diff --git a/packages/json-schema/package.json b/packages/json-schema/package.json index f3fc8a1b5e8..8e40177600d 100644 --- a/packages/json-schema/package.json +++ b/packages/json-schema/package.json @@ -61,13 +61,7 @@ "rimraf": "~5.0.1", "typescript": "~5.1.3", "ajv": "~8.12.0", -<<<<<<< HEAD - "@typespec/internal-build-utils": "workspace:~0.46.0", -======= - "@types/js-yaml": "~4.0.1", "@typespec/internal-build-utils": "workspace:~0.47.0", - "js-yaml": "~4.1.0", ->>>>>>> 2f512c77a1841f89ea0bf26b443d4eac902a1092 "ajv-formats": "~2.1.1" }, "dependencies": { diff --git a/packages/openapi3/package.json b/packages/openapi3/package.json index 75ac9c8240f..e0c838e9c62 100644 --- a/packages/openapi3/package.json +++ b/packages/openapi3/package.json @@ -65,17 +65,6 @@ "devDependencies": { "@types/mocha": "~10.0.1", "@types/node": "~18.11.9", -<<<<<<< HEAD - "@typespec/compiler": "workspace:~0.46.0", - "@typespec/http": "workspace:~0.46.0", - "@typespec/rest": "workspace:~0.46.0", - "@typespec/openapi": "workspace:~0.46.0", - "@typespec/versioning": "workspace:~0.46.0", - "@typespec/eslint-config-typespec": "workspace:~0.46.0", - "@typespec/library-linter": "workspace:~0.46.0", - "@typespec/eslint-plugin": "workspace:~0.46.0", -======= - "@types/js-yaml": "~4.0.1", "@typespec/compiler": "workspace:~0.47.0", "@typespec/http": "workspace:~0.47.0", "@typespec/rest": "workspace:~0.47.0", @@ -84,7 +73,6 @@ "@typespec/eslint-config-typespec": "workspace:~0.47.0", "@typespec/library-linter": "workspace:~0.47.0", "@typespec/eslint-plugin": "workspace:~0.47.0", ->>>>>>> 2f512c77a1841f89ea0bf26b443d4eac902a1092 "@typespec/tspd": "workspace:~0.46.0", "eslint": "^8.42.0", "mocha": "~10.2.0", diff --git a/packages/tspd/package.json b/packages/tspd/package.json index 612d24413b1..a5715a028f2 100644 --- a/packages/tspd/package.json +++ b/packages/tspd/package.json @@ -53,13 +53,8 @@ "!dist/test/**" ], "dependencies": { -<<<<<<< HEAD - "@typespec/compiler": "workspace:~0.46.0", - "yaml": "~2.3.1", -======= "@typespec/compiler": "workspace:~0.47.0", - "js-yaml": "~4.1.0", ->>>>>>> 2f512c77a1841f89ea0bf26b443d4eac902a1092 + "yaml": "~2.3.1", "prettier": "~3.0.1", "picocolors": "~1.0.0", "yargs": "~17.7.1" From 75849c79a9f20e14432449ad04e524272f196bed Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 09:56:51 -0700 Subject: [PATCH 14/18] Regen samples slight diff --- packages/openapi3/src/openapi.ts | 12 ++- .../@typespec/openapi3/openapi.yaml | 2 +- .../binary/@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 2 +- .../encoding/@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 28 +++---- .../@typespec/openapi3/openapi.yaml | 42 +++++----- .../@typespec/openapi3/openapi.yaml | 2 +- .../nested/@typespec/openapi3/openapi.yaml | 2 +- .../nullable/@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 2 +- .../optional/@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 4 +- .../petstore/@typespec/openapi3/openapi.yaml | 23 +++--- .../@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 2 +- .../petstore/@typespec/openapi3/openapi.yaml | 77 ++++++++++--------- .../@typespec/openapi3/openapi.yaml | 6 +- .../simple/@typespec/openapi3/openapi.yaml | 6 +- .../tags/@typespec/openapi3/openapi.yaml | 28 +++---- .../@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 12 ++- .../@typespec/openapi3/openapi.yaml | 26 +++---- .../body-time/@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.yaml | 7 +- .../@typespec/openapi3/openapi.yaml | 19 ++--- .../@typespec/openapi3/openapi.yaml | 2 +- .../@typespec/openapi3/openapi.v1.yaml | 5 +- .../@typespec/openapi3/openapi.v2.yaml | 5 +- .../@typespec/openapi3/openapi.yaml | 4 +- 30 files changed, 160 insertions(+), 172 deletions(-) diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index 7d36ec17017..a5eaccd9b54 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -2045,9 +2045,15 @@ function serializeDocument(root: OpenAPI3Document, fileType: FileType): string { case "json": return prettierOutput(JSON.stringify(root, null, 2)); case "yaml": - return stringify(root, (key, value) => { - return value instanceof Ref ? value.toJSON() : value; - }); + return stringify( + root, + (key, value) => { + return value instanceof Ref ? value.toJSON() : value; + }, + { + singleQuote: true, + } + ); } } diff --git a/packages/samples/test/output/authentication/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/authentication/@typespec/openapi3/openapi.yaml index 1e8ce4690f1..4d9c864c674 100644 --- a/packages/samples/test/output/authentication/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/authentication/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Authenticated service - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/binary/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/binary/@typespec/openapi3/openapi.yaml index 71b4d0366fb..d5cde34d8b8 100644 --- a/packages/samples/test/output/binary/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/binary/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Binary sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /test/base64: diff --git a/packages/samples/test/output/documentation/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/documentation/@typespec/openapi3/openapi.yaml index dced47b14ac..76a53895bdd 100644 --- a/packages/samples/test/output/documentation/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/documentation/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Documentaion sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /foo/DefaultDescriptions: diff --git a/packages/samples/test/output/encoding/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/encoding/@typespec/openapi3/openapi.yaml index 2597ab1842b..501729d94fd 100644 --- a/packages/samples/test/output/encoding/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/encoding/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: (title) - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/grpc-kiosk-example/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/grpc-kiosk-example/@typespec/openapi3/openapi.yaml index 14f6f668cda..6407129b0dc 100644 --- a/packages/samples/test/output/grpc-kiosk-example/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/grpc-kiosk-example/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Grpc Kiosk sample - version: '0000-00-00' + version: 0000-00-00 tags: - name: Display paths: @@ -50,7 +50,7 @@ paths: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/kiosks/{id}: + '/v1/kiosks/{id}': get: tags: - Display @@ -90,16 +90,15 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/kiosks/{kiosk_id}/sign: + '/v1/kiosks/{kiosk_id}/sign': get: tags: - Display @@ -164,7 +163,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ListSignsResponse' - /v1/signs/{id}: + '/v1/signs/{id}': get: tags: - Display @@ -204,16 +203,15 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/signs/{sign_id}: + '/v1/signs/{sign_id}': post: tags: - Display @@ -223,9 +221,8 @@ paths: - $ref: '#/components/parameters/SetSignIdForKioskIdsRequest.sign_id' responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' default: description: An unexpected error response. content: @@ -304,8 +301,7 @@ components: An object that represents a latitude/longitude pair. This is expressed as a - pair of doubles to represent degrees latitude and degrees longitude. - Unless + pair of doubles to represent degrees latitude and degrees longitude. Unless specified otherwise, this must conform to the diff --git a/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml index ee1312ea996..b215a2a182d 100644 --- a/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Grpc Library sample - version: '0000-00-00' + version: 0000-00-00 tags: - name: LibraryService paths: @@ -40,8 +40,10 @@ paths: Lists shelves. The order is unspecified but deterministic. Newly created shelves will not necessarily be added to the end of this list. parameters: - - $ref: '#/components/parameters/ListRequestBase.page_size' - - $ref: '#/components/parameters/ListRequestBase.page_token' + - &a1 + $ref: '#/components/parameters/ListRequestBase.page_size' + - &a2 + $ref: '#/components/parameters/ListRequestBase.page_token' responses: '200': description: The request has succeeded. @@ -55,7 +57,7 @@ paths: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/shelves/shelf_name/books/{name}: + '/v1/shelves/shelf_name/books/{name}': get: tags: - LibraryService @@ -85,16 +87,15 @@ paths: - $ref: '#/components/parameters/DeleteBookRequest' responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/shelves/{name}: + '/v1/shelves/{name}': get: tags: - LibraryService @@ -124,16 +125,15 @@ paths: - $ref: '#/components/parameters/DeleteShelfRequest' responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' default: description: An unexpected error response. content: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/shelves/{name}/books: + '/v1/shelves/{name}/books': post: tags: - LibraryService @@ -174,8 +174,8 @@ paths: Returns NOT_FOUND if the shelf does not exist. parameters: - $ref: '#/components/parameters/ListBooksRequest.name' - - $ref: '#/components/parameters/ListRequestBase.page_size' - - $ref: '#/components/parameters/ListRequestBase.page_token' + - *a1 + - *a2 responses: '200': description: The request has succeeded. @@ -189,7 +189,7 @@ paths: application/json: schema: $ref: '#/components/schemas/RpcStatus' - /v1/shelves/{name}:merge: + '/v1/shelves/{name}:merge': post: tags: - LibraryService @@ -201,8 +201,7 @@ paths: `other_shelf_name`. Returns the updated shelf. - The book ids of the moved books may not be the same as the original - books. + The book ids of the moved books may not be the same as the original books. Returns NOT_FOUND if either shelf does not exist. @@ -365,8 +364,7 @@ components: [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] - field in the subsequent call to `ListShelves` method to retrieve the - next + field in the subsequent call to `ListShelves` method to retrieve the next page of results. description: Response message for LibraryService.ListBooks. @@ -384,8 +382,7 @@ components: [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] - field in the subsequent call to `ListShelves` method to retrieve the - next + field in the subsequent call to `ListShelves` method to retrieve the next page of results. ListShelvesResponse: @@ -405,8 +402,7 @@ components: [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] - field in the subsequent call to `ListShelves` method to retrieve the - next + field in the subsequent call to `ListShelves` method to retrieve the next page of results. description: Response message for LibraryService.ListShelves. diff --git a/packages/samples/test/output/multiple-types-union/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/multiple-types-union/@typespec/openapi3/openapi.yaml index e71853fff38..59bba49c47e 100644 --- a/packages/samples/test/output/multiple-types-union/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/multiple-types-union/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Pet Store Service - version: '2021-03-25' + version: 2021-03-25 tags: [] paths: /: diff --git a/packages/samples/test/output/nested/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/nested/@typespec/openapi3/openapi.yaml index 11b81f96d79..95e56adf8d5 100644 --- a/packages/samples/test/output/nested/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/nested/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Nested sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/nullable/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/nullable/@typespec/openapi3/openapi.yaml index be81d9bf00f..fc7e8b6c308 100644 --- a/packages/samples/test/output/nullable/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/nullable/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Nullable sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /test: diff --git a/packages/samples/test/output/openapi-extensions/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/openapi-extensions/@typespec/openapi3/openapi.yaml index a07619863fe..4b8cc2c6c05 100644 --- a/packages/samples/test/output/openapi-extensions/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/openapi-extensions/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: (title) - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/optional/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/optional/@typespec/openapi3/openapi.yaml index 717c4fce22f..8fa818f0e0e 100644 --- a/packages/samples/test/output/optional/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/optional/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Optional sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /test: diff --git a/packages/samples/test/output/param-decorators/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/param-decorators/@typespec/openapi3/openapi.yaml index be75cb4e41f..14d43adbff8 100644 --- a/packages/samples/test/output/param-decorators/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/param-decorators/@typespec/openapi3/openapi.yaml @@ -1,10 +1,10 @@ openapi: 3.0.0 info: title: Parameter Decorators - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: - /thing/{name}: + '/thing/{name}': get: operationId: Operations_getThing parameters: diff --git a/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml index 8a9126edde4..fe86f6a54ec 100644 --- a/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml @@ -1,12 +1,11 @@ openapi: 3.0.0 info: title: Pet Store Service - version: '2021-03-25' - description: >- - This is a sample server Petstore server. You can find out more about - Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, - #swagger](http://swagger.io/irc/). For this sample, you can use the api key - `special-key` to test the authorization filters. + version: 2021-03-25 + description: 'This is a sample server Petstore server. You can find out more + about Swagger at [http://swagger.io](http://swagger.io) or on + [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you + can use the api key `special-key` to test the authorization filters.' tags: [] paths: /pets: @@ -54,12 +53,13 @@ paths: application/json: schema: $ref: '#/components/schemas/Pet' - /pets/{petId}: + '/pets/{petId}': delete: operationId: Pets_delete description: Delete a pet. parameters: - - $ref: '#/components/parameters/PetId' + - &a1 + $ref: '#/components/parameters/PetId' responses: '200': description: The request has succeeded. @@ -73,7 +73,7 @@ paths: operationId: Pets_read description: Returns a pet. Supports eTags. parameters: - - $ref: '#/components/parameters/PetId' + - *a1 responses: '200': description: The request has succeeded. @@ -82,8 +82,7 @@ paths: schema: $ref: '#/components/schemas/Pet' '304': - description: >- - The client has made a conditional request and the resource has not + description: The client has made a conditional request and the resource has not been modified. content: application/json: @@ -95,7 +94,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - /pets/{petId}/toys: + '/pets/{petId}/toys': get: operationId: ListPetToysResponse_list parameters: diff --git a/packages/samples/test/output/polymorphism/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/polymorphism/@typespec/openapi3/openapi.yaml index f693b2a8ce9..39aa6ecc319 100644 --- a/packages/samples/test/output/polymorphism/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/polymorphism/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Polymorphism sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /Pets: diff --git a/packages/samples/test/output/projected-names/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/projected-names/@typespec/openapi3/openapi.yaml index 31b3a6acac0..09cee483eae 100644 --- a/packages/samples/test/output/projected-names/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/projected-names/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Sample showcasing projected names - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml index e34378fcb74..5b43a4b47ab 100644 --- a/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Pet Store Service - version: '2021-03-25' + version: 2021-03-25 tags: [] paths: /checkups: @@ -22,12 +22,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /checkups/{checkupId}: + '/checkups/{checkupId}': patch: operationId: Checkups_createOrUpdate description: Creates or update an instance of the resource. parameters: - - $ref: '#/components/parameters/CheckupKey' + - &a2 + $ref: '#/components/parameters/CheckupKey' responses: '200': description: The request has succeeded. @@ -100,12 +101,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /owners/{ownerId}: + '/owners/{ownerId}': get: operationId: Owners_get description: Gets an instance of the resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - &a1 + $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -123,7 +125,7 @@ paths: operationId: Owners_update description: Updates an existing instance of the resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - *a1 responses: '200': description: The request has succeeded. @@ -147,7 +149,7 @@ paths: operationId: Owners_delete description: Deletes an existing instance of the resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - *a1 responses: '200': description: Resource deleted successfully. @@ -157,12 +159,12 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /owners/{ownerId}/checkups: + '/owners/{ownerId}/checkups': get: operationId: OwnerCheckups_list description: Lists all instances of the extension resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - *a1 responses: '200': description: The request has succeeded. @@ -176,13 +178,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /owners/{ownerId}/checkups/{checkupId}: + '/owners/{ownerId}/checkups/{checkupId}': patch: operationId: OwnerCheckups_createOrUpdate description: Creates or update an instance of the extension resource. parameters: - - $ref: '#/components/parameters/OwnerKey' - - $ref: '#/components/parameters/CheckupKey' + - *a1 + - *a2 responses: '200': description: The request has succeeded. @@ -208,12 +210,12 @@ paths: application/json: schema: $ref: '#/components/schemas/CheckupUpdate' - /owners/{ownerId}/insurance: + '/owners/{ownerId}/insurance': get: operationId: OwnerInsurance_get description: Gets the singleton resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - *a1 responses: '200': description: The request has succeeded. @@ -231,7 +233,7 @@ paths: operationId: OwnerInsurance_update description: Updates the singleton resource. parameters: - - $ref: '#/components/parameters/OwnerKey' + - *a1 responses: '200': description: The request has succeeded. @@ -298,12 +300,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /pets/{petId}: + '/pets/{petId}': get: operationId: Pets_get description: Gets an instance of the resource. parameters: - - $ref: '#/components/parameters/PetKey' + - &a3 + $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -321,7 +324,7 @@ paths: operationId: Pets_update description: Updates an existing instance of the resource. parameters: - - $ref: '#/components/parameters/PetKey' + - *a3 responses: '200': description: The request has succeeded. @@ -345,7 +348,7 @@ paths: operationId: Pets_delete description: Deletes an existing instance of the resource. parameters: - - $ref: '#/components/parameters/PetKey' + - *a3 responses: '200': description: Resource deleted successfully. @@ -355,12 +358,12 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /pets/{petId}/checkups: + '/pets/{petId}/checkups': get: operationId: PetCheckups_list description: Lists all instances of the extension resource. parameters: - - $ref: '#/components/parameters/PetKey' + - *a3 responses: '200': description: The request has succeeded. @@ -374,13 +377,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /pets/{petId}/checkups/{checkupId}: + '/pets/{petId}/checkups/{checkupId}': patch: operationId: PetCheckups_createOrUpdate description: Creates or update an instance of the extension resource. parameters: - - $ref: '#/components/parameters/PetKey' - - $ref: '#/components/parameters/CheckupKey' + - *a3 + - *a2 responses: '200': description: The request has succeeded. @@ -406,12 +409,12 @@ paths: application/json: schema: $ref: '#/components/schemas/CheckupUpdate' - /pets/{petId}/insurance: + '/pets/{petId}/insurance': get: operationId: PetInsurance_get description: Gets the singleton resource. parameters: - - $ref: '#/components/parameters/PetKey' + - *a3 responses: '200': description: The request has succeeded. @@ -429,7 +432,7 @@ paths: operationId: PetInsurance_update description: Updates the singleton resource. parameters: - - $ref: '#/components/parameters/PetKey' + - *a3 responses: '200': description: The request has succeeded. @@ -449,7 +452,7 @@ paths: application/json: schema: $ref: '#/components/schemas/InsuranceUpdate' - /pets/{petId}/toys: + '/pets/{petId}/toys': get: operationId: Toys_list parameters: @@ -472,13 +475,15 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /pets/{petId}/toys/{toyId}: + '/pets/{petId}/toys/{toyId}': get: operationId: Toys_get description: Gets an instance of the resource. parameters: - - $ref: '#/components/parameters/ToyKey.petId' - - $ref: '#/components/parameters/ToyKey.toyId' + - &a4 + $ref: '#/components/parameters/ToyKey.petId' + - &a5 + $ref: '#/components/parameters/ToyKey.toyId' responses: '200': description: The request has succeeded. @@ -492,13 +497,13 @@ paths: application/json: schema: $ref: '#/components/schemas/PetStoreError' - /pets/{petId}/toys/{toyId}/insurance: + '/pets/{petId}/toys/{toyId}/insurance': get: operationId: ToyInsurance_get description: Gets the singleton resource. parameters: - - $ref: '#/components/parameters/ToyKey.petId' - - $ref: '#/components/parameters/ToyKey.toyId' + - *a4 + - *a5 responses: '200': description: The request has succeeded. @@ -516,8 +521,8 @@ paths: operationId: ToyInsurance_update description: Updates the singleton resource. parameters: - - $ref: '#/components/parameters/ToyKey.petId' - - $ref: '#/components/parameters/ToyKey.toyId' + - *a4 + - *a5 responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/signatures/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/signatures/@typespec/openapi3/openapi.yaml index ea284fc7e03..ac7e4f7a1f7 100644 --- a/packages/samples/test/output/signatures/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/signatures/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: (title) - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /accountProfiles: @@ -28,7 +28,7 @@ paths: application/json: schema: $ref: '#/components/schemas/AccountProfile' - /accountProfiles/{name}: + '/accountProfiles/{name}': get: operationId: AccountProfiles_get description: Reads an instance of the AccountProfile resource. @@ -75,7 +75,7 @@ paths: application/json: schema: $ref: '#/components/schemas/CodeSignAccount' - /codeSignAccounts/{name}: + '/codeSignAccounts/{name}': get: operationId: CodeSignAccounts_get description: Reads an instance of the CodeSignAccount resource. diff --git a/packages/samples/test/output/simple/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/simple/@typespec/openapi3/openapi.yaml index 15512b5a75e..d73bca8270f 100644 --- a/packages/samples/test/output/simple/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/simple/@typespec/openapi3/openapi.yaml @@ -1,10 +1,10 @@ openapi: 3.0.0 info: title: (title) - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: - /alpha/{id}: + '/alpha/{id}': get: operationId: doAlpha parameters: @@ -20,7 +20,7 @@ paths: application/json: schema: type: string - /beta/{id}: + '/beta/{id}': get: operationId: doBeta parameters: diff --git a/packages/samples/test/output/tags/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/tags/@typespec/openapi3/openapi.yaml index d2614394838..358b7fa26d7 100644 --- a/packages/samples/test/output/tags/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/tags/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Tags sample - version: '0000-00-00' + version: 0000-00-00 tags: - name: foo - name: tag1 @@ -26,7 +26,7 @@ paths: type: array items: $ref: '#/components/schemas/Resp' - /bar/{id}: + '/bar/{id}': post: tags: - tag3 @@ -41,10 +41,9 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. - /foo/{id}: + description: 'There is no content to send for this request, but the headers may + be useful. ' + '/foo/{id}': get: tags: - foo @@ -60,9 +59,8 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' post: tags: - foo @@ -79,10 +77,9 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. - /nested/{id}: + description: 'There is no content to send for this request, but the headers may + be useful. ' + '/nested/{id}': post: tags: - outer @@ -99,9 +96,8 @@ paths: format: int32 responses: '204': - description: >- - There is no content to send for this request, but the headers may be - useful. + description: 'There is no content to send for this request, but the headers may + be useful. ' components: schemas: Resp: diff --git a/packages/samples/test/output/testserver/body-boolean/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/body-boolean/@typespec/openapi3/openapi.yaml index a215656267b..028923fae9f 100644 --- a/packages/samples/test/output/testserver/body-boolean/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/body-boolean/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /bool/false: diff --git a/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml index f1908b77928..6d0b030c411 100644 --- a/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /complex/array/valid: @@ -44,7 +44,7 @@ paths: /complex/basic/valid: get: operationId: Complex_getValid - description: 'Get complex type {id: 2, name: ''abc'', color: ''YELLOW''}' + description: "Get complex type {id: 2, name: 'abc', color: 'YELLOW'}" parameters: [] responses: '200': @@ -61,7 +61,7 @@ paths: $ref: '#/components/schemas/Error' put: operationId: Complex_putValid - description: 'Please put {id: 2, name: ''abc'', color: ''Magenta''}' + description: "Please put {id: 2, name: 'abc', color: 'Magenta'}" parameters: [] responses: '200': @@ -506,8 +506,7 @@ components: description: Basic Id name: type: string - description: >- - Name property with a very long description that does not fit on a + description: Name property with a very long description that does not fit on a single line and a line break. color: $ref: '#/components/schemas/CMYKColors' @@ -572,8 +571,7 @@ components: format: double required: - field1 - - >- - field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose + - field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose DurationWrapper: type: object properties: diff --git a/packages/samples/test/output/testserver/body-string/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/body-string/@typespec/openapi3/openapi.yaml index b47d1b059be..cc8392b5a86 100644 --- a/packages/samples/test/output/testserver/body-string/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/body-string/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: - name: String Operations paths: @@ -180,8 +180,7 @@ paths: tags: - String Operations operationId: String_getMbcs - description: >- - Get mbcs string value + description: Get mbcs string value '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' parameters: [] responses: @@ -192,8 +191,7 @@ paths: schema: type: string enum: - - >- - 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€ + - 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€ default: description: An unexpected error response. content: @@ -204,8 +202,7 @@ paths: tags: - String Operations operationId: String_putMbCs - description: >- - Put mbcs string value + description: Put mbcs string value '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' parameters: [] responses: @@ -224,8 +221,7 @@ paths: schema: type: string enum: - - >- - 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€ + - 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€ /string/null: get: tags: @@ -274,8 +270,7 @@ paths: tags: - String Operations operationId: String_getWhitespace - description: >- - Get string value with leading and trailing whitespace + description: Get string value with leading and trailing whitespace 'Now is the time for all good men to come to the aid of their country' parameters: [] @@ -287,7 +282,8 @@ paths: schema: type: string enum: - - ' Now is the time for all good men to come to the aid of their country ' + - ' Now is the time for all good men to come to the aid of + their country ' default: description: An unexpected error response. content: @@ -298,8 +294,7 @@ paths: tags: - String Operations operationId: String_putWhitespace - description: >- - Get string value with leading and trailing whitespace + description: Get string value with leading and trailing whitespace 'Now is the time for all good men to come to the aid of their country' parameters: [] @@ -319,7 +314,8 @@ paths: schema: type: string enum: - - ' Now is the time for all good men to come to the aid of their country ' + - ' Now is the time for all good men to come to the aid of + their country ' components: schemas: Colors: diff --git a/packages/samples/test/output/testserver/body-time/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/body-time/@typespec/openapi3/openapi.yaml index 208189b3278..5a3b1cf9063 100644 --- a/packages/samples/test/output/testserver/body-time/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/body-time/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /time: diff --git a/packages/samples/test/output/testserver/media-types/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/media-types/@typespec/openapi3/openapi.yaml index 2a6d5653b8e..3e19743938e 100644 --- a/packages/samples/test/output/testserver/media-types/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/media-types/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /mediatypes/analyze: @@ -38,9 +38,8 @@ paths: /mediatypes/contentTypeWithEncoding: post: operationId: contentTypeWithEncoding - description: >- - Pass in contentType 'text/plain; encoding=UTF-8' to pass test. Value for - input does not matter + description: Pass in contentType 'text/plain; encoding=UTF-8' to pass test. + Value for input does not matter parameters: [] responses: '200': diff --git a/packages/samples/test/output/testserver/multiple-inheritance/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/multiple-inheritance/@typespec/openapi3/openapi.yaml index e0efdedad0d..9bc9746081c 100644 --- a/packages/samples/test/output/testserver/multiple-inheritance/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/multiple-inheritance/@typespec/openapi3/openapi.yaml @@ -1,15 +1,13 @@ openapi: 3.0.0 info: title: sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /multipleInheritance/cat: get: operationId: MultipleInheritance_getCat - description: >- - Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is - true + description: Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true parameters: [] responses: '200': @@ -26,9 +24,8 @@ paths: type: string put: operationId: MultipleInheritance_putCat - description: >- - Put a cat with name 'Boots' where likesMilk and hisses is false, meows - is true + description: Put a cat with name 'Boots' where likesMilk and hisses is false, + meows is true parameters: [] responses: '200': @@ -134,9 +131,8 @@ paths: /multipleInheritance/kitten: get: operationId: MultipleInheritance_getKitten - description: >- - Get a kitten with name 'Gatito' where likesMilk and meows is true, and - hisses and eatsMiceYet is false + description: Get a kitten with name 'Gatito' where likesMilk and meows is true, + and hisses and eatsMiceYet is false parameters: [] responses: '200': @@ -153,8 +149,7 @@ paths: type: string put: operationId: MultipleInheritance_putKitten - description: >- - Put a kitten with name 'Kitty' where likesMilk and hisses is false, + description: Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true parameters: [] responses: diff --git a/packages/samples/test/output/use-versioned-lib/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/use-versioned-lib/@typespec/openapi3/openapi.yaml index aafeb968005..a2902f091c6 100644 --- a/packages/samples/test/output/use-versioned-lib/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/use-versioned-lib/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Pet Store Service - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /: diff --git a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml index 4ce6522266c..8e513a820f2 100644 --- a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml +++ b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml @@ -8,7 +8,8 @@ paths: get: operationId: MyService_getPet parameters: - - $ref: '#/components/parameters/ApiVersionParam' + - &a1 + $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. @@ -20,7 +21,7 @@ paths: post: operationId: MyService_walkCat parameters: - - $ref: '#/components/parameters/ApiVersionParam' + - *a1 responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml index 6c84a673131..950b444a2f4 100644 --- a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml +++ b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml @@ -8,7 +8,8 @@ paths: get: operationId: MyService_getPet parameters: - - $ref: '#/components/parameters/ApiVersionParam' + - &a1 + $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. @@ -20,7 +21,7 @@ paths: post: operationId: MyService_walkDog parameters: - - $ref: '#/components/parameters/ApiVersionParam' + - *a1 responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/visibility/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/visibility/@typespec/openapi3/openapi.yaml index c9e363c62c1..8d087ebf112 100644 --- a/packages/samples/test/output/visibility/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/visibility/@typespec/openapi3/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: Visibility sample - version: '0000-00-00' + version: 0000-00-00 tags: [] paths: /hello: @@ -70,7 +70,7 @@ paths: application/json: schema: $ref: '#/components/schemas/PersonUpdate' - /hello/{id}: + '/hello/{id}': get: operationId: Hello_read parameters: From 035c42e60a0472841de3fe0f06f806ad6ae04322 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 9 Aug 2023 10:22:04 -0700 Subject: [PATCH 15/18] Fix tests --- packages/compiler/src/core/schema-validator.ts | 2 +- packages/openapi3/test/output-file.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/core/schema-validator.ts b/packages/compiler/src/core/schema-validator.ts index e21b580111e..1cdb2d9cdde 100644 --- a/packages/compiler/src/core/schema-validator.ts +++ b/packages/compiler/src/core/schema-validator.ts @@ -48,7 +48,7 @@ function ajvErrorToDiagnostic( error: DefinedError, target: YamlScript | SourceFile | typeof NoTarget ): Diagnostic { - const messageLines = [`Schema violation: ${error.message} (${error.instancePath ?? "/"})`]; + const messageLines = [`Schema violation: ${error.message} (${error.instancePath || "/"})`]; for (const [name, value] of Object.entries(error.params).filter( ([name]) => !IGNORED_AJV_PARAMS.has(name) )) { diff --git a/packages/openapi3/test/output-file.test.ts b/packages/openapi3/test/output-file.test.ts index 3bac2f1e3a2..184ae1ca6e6 100644 --- a/packages/openapi3/test/output-file.test.ts +++ b/packages/openapi3/test/output-file.test.ts @@ -27,7 +27,7 @@ describe("openapi3: output file", () => { `openapi: 3.0.0`, `info:`, ` title: (title)`, - ` version: '0000-00-00'`, + ` version: 0000-00-00`, `tags: []`, `paths: {}`, `components: {}`, From 0fca712316632f573c0c636591aae852be301912 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Fri, 18 Aug 2023 08:26:22 -0700 Subject: [PATCH 16/18] Disable alias --- packages/openapi3/src/openapi.ts | 1 + .../@typespec/openapi3/openapi.yaml | 10 ++-- .../petstore/@typespec/openapi3/openapi.yaml | 5 +- .../petstore/@typespec/openapi3/openapi.yaml | 51 +++++++++---------- .../@typespec/openapi3/openapi.v1.yaml | 5 +- .../@typespec/openapi3/openapi.v2.yaml | 5 +- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index a5eaccd9b54..dd246b0dd98 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -2052,6 +2052,7 @@ function serializeDocument(root: OpenAPI3Document, fileType: FileType): string { }, { singleQuote: true, + aliasDuplicateObjects: false, } ); } diff --git a/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml index b215a2a182d..4f7449941bd 100644 --- a/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/grpc-library-example/@typespec/openapi3/openapi.yaml @@ -40,10 +40,8 @@ paths: Lists shelves. The order is unspecified but deterministic. Newly created shelves will not necessarily be added to the end of this list. parameters: - - &a1 - $ref: '#/components/parameters/ListRequestBase.page_size' - - &a2 - $ref: '#/components/parameters/ListRequestBase.page_token' + - $ref: '#/components/parameters/ListRequestBase.page_size' + - $ref: '#/components/parameters/ListRequestBase.page_token' responses: '200': description: The request has succeeded. @@ -174,8 +172,8 @@ paths: Returns NOT_FOUND if the shelf does not exist. parameters: - $ref: '#/components/parameters/ListBooksRequest.name' - - *a1 - - *a2 + - $ref: '#/components/parameters/ListRequestBase.page_size' + - $ref: '#/components/parameters/ListRequestBase.page_token' responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml index fe86f6a54ec..4fb97d0751e 100644 --- a/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/petstore/@typespec/openapi3/openapi.yaml @@ -58,8 +58,7 @@ paths: operationId: Pets_delete description: Delete a pet. parameters: - - &a1 - $ref: '#/components/parameters/PetId' + - $ref: '#/components/parameters/PetId' responses: '200': description: The request has succeeded. @@ -73,7 +72,7 @@ paths: operationId: Pets_read description: Returns a pet. Supports eTags. parameters: - - *a1 + - $ref: '#/components/parameters/PetId' responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml index 5b43a4b47ab..79605f4777f 100644 --- a/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/rest/petstore/@typespec/openapi3/openapi.yaml @@ -27,8 +27,7 @@ paths: operationId: Checkups_createOrUpdate description: Creates or update an instance of the resource. parameters: - - &a2 - $ref: '#/components/parameters/CheckupKey' + - $ref: '#/components/parameters/CheckupKey' responses: '200': description: The request has succeeded. @@ -106,8 +105,7 @@ paths: operationId: Owners_get description: Gets an instance of the resource. parameters: - - &a1 - $ref: '#/components/parameters/OwnerKey' + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -125,7 +123,7 @@ paths: operationId: Owners_update description: Updates an existing instance of the resource. parameters: - - *a1 + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -149,7 +147,7 @@ paths: operationId: Owners_delete description: Deletes an existing instance of the resource. parameters: - - *a1 + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: Resource deleted successfully. @@ -164,7 +162,7 @@ paths: operationId: OwnerCheckups_list description: Lists all instances of the extension resource. parameters: - - *a1 + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -183,8 +181,8 @@ paths: operationId: OwnerCheckups_createOrUpdate description: Creates or update an instance of the extension resource. parameters: - - *a1 - - *a2 + - $ref: '#/components/parameters/OwnerKey' + - $ref: '#/components/parameters/CheckupKey' responses: '200': description: The request has succeeded. @@ -215,7 +213,7 @@ paths: operationId: OwnerInsurance_get description: Gets the singleton resource. parameters: - - *a1 + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -233,7 +231,7 @@ paths: operationId: OwnerInsurance_update description: Updates the singleton resource. parameters: - - *a1 + - $ref: '#/components/parameters/OwnerKey' responses: '200': description: The request has succeeded. @@ -305,8 +303,7 @@ paths: operationId: Pets_get description: Gets an instance of the resource. parameters: - - &a3 - $ref: '#/components/parameters/PetKey' + - $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -324,7 +321,7 @@ paths: operationId: Pets_update description: Updates an existing instance of the resource. parameters: - - *a3 + - $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -348,7 +345,7 @@ paths: operationId: Pets_delete description: Deletes an existing instance of the resource. parameters: - - *a3 + - $ref: '#/components/parameters/PetKey' responses: '200': description: Resource deleted successfully. @@ -363,7 +360,7 @@ paths: operationId: PetCheckups_list description: Lists all instances of the extension resource. parameters: - - *a3 + - $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -382,8 +379,8 @@ paths: operationId: PetCheckups_createOrUpdate description: Creates or update an instance of the extension resource. parameters: - - *a3 - - *a2 + - $ref: '#/components/parameters/PetKey' + - $ref: '#/components/parameters/CheckupKey' responses: '200': description: The request has succeeded. @@ -414,7 +411,7 @@ paths: operationId: PetInsurance_get description: Gets the singleton resource. parameters: - - *a3 + - $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -432,7 +429,7 @@ paths: operationId: PetInsurance_update description: Updates the singleton resource. parameters: - - *a3 + - $ref: '#/components/parameters/PetKey' responses: '200': description: The request has succeeded. @@ -480,10 +477,8 @@ paths: operationId: Toys_get description: Gets an instance of the resource. parameters: - - &a4 - $ref: '#/components/parameters/ToyKey.petId' - - &a5 - $ref: '#/components/parameters/ToyKey.toyId' + - $ref: '#/components/parameters/ToyKey.petId' + - $ref: '#/components/parameters/ToyKey.toyId' responses: '200': description: The request has succeeded. @@ -502,8 +497,8 @@ paths: operationId: ToyInsurance_get description: Gets the singleton resource. parameters: - - *a4 - - *a5 + - $ref: '#/components/parameters/ToyKey.petId' + - $ref: '#/components/parameters/ToyKey.toyId' responses: '200': description: The request has succeeded. @@ -521,8 +516,8 @@ paths: operationId: ToyInsurance_update description: Updates the singleton resource. parameters: - - *a4 - - *a5 + - $ref: '#/components/parameters/ToyKey.petId' + - $ref: '#/components/parameters/ToyKey.toyId' responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml index 8e513a820f2..4ce6522266c 100644 --- a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml +++ b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v1.yaml @@ -8,8 +8,7 @@ paths: get: operationId: MyService_getPet parameters: - - &a1 - $ref: '#/components/parameters/ApiVersionParam' + - $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. @@ -21,7 +20,7 @@ paths: post: operationId: MyService_walkCat parameters: - - *a1 + - $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. diff --git a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml index 950b444a2f4..6c84a673131 100644 --- a/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml +++ b/packages/samples/test/output/versioning/@typespec/openapi3/openapi.v2.yaml @@ -8,8 +8,7 @@ paths: get: operationId: MyService_getPet parameters: - - &a1 - $ref: '#/components/parameters/ApiVersionParam' + - $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. @@ -21,7 +20,7 @@ paths: post: operationId: MyService_walkDog parameters: - - *a1 + - $ref: '#/components/parameters/ApiVersionParam' responses: '200': description: The request has succeeded. From a2c41762fcc6e373d9d4c23ac90f03275a086cc7 Mon Sep 17 00:00:00 2001 From: Microsoft Auto Changeset Bot Date: Tue, 5 Sep 2023 08:22:39 -0700 Subject: [PATCH 17/18] . --- packages/compiler/src/server/serverlib.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler/src/server/serverlib.ts b/packages/compiler/src/server/serverlib.ts index 1875af81a1c..160040bffa7 100644 --- a/packages/compiler/src/server/serverlib.ts +++ b/packages/compiler/src/server/serverlib.ts @@ -447,7 +447,7 @@ export function createServer(host: ServerHost): Server { } } - async function getConfig(mainFile: string, path: string): Promise { + async function getConfig(mainFile: string): Promise { const entrypointStat = await host.compilerHost.stat(mainFile); const lookupDir = entrypointStat.isDirectory() ? mainFile : getDirectoryPath(mainFile); From e903794e4ddc964da9b90f520bafb7ed38253759 Mon Sep 17 00:00:00 2001 From: Microsoft Auto Changeset Bot Date: Tue, 5 Sep 2023 08:48:02 -0700 Subject: [PATCH 18/18] regen --- .../body-complex/@typespec/openapi3/openapi.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml b/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml index ef1d8f09640..8f2531e8381 100644 --- a/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml +++ b/packages/samples/test/output/testserver/body-complex/@typespec/openapi3/openapi.yaml @@ -564,8 +564,7 @@ components: type: object required: - field1 - - >- - field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose + - field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose properties: field1: type: number @@ -573,12 +572,6 @@ components: field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose: type: number format: double -<<<<<<< HEAD - required: - - field1 - - field_56_zeros_after_the_dot_and_negative_zero_before_dot_and_this_is_a_long_field_name_on_purpose -======= ->>>>>>> c42321c71cca3d33a488a04b0d10d7560e9676cc DurationWrapper: type: object required: