Skip to content

Commit

Permalink
Validate playground samples and fix docs to deprecated version (#2977)
Browse files Browse the repository at this point in the history
fix #1560

Json schema emitter also didn't respect the `noEmit` flag
  • Loading branch information
timotheeguerin committed Mar 4, 2024
1 parent de6bd7b commit abba29c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/json-schema"
---

Respect compiler `noEmit` flag
1 change: 0 additions & 1 deletion docs/getting-started/getting-started-http.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ using TypeSpec.Rest;
*/
@service({
title: "Pet Store Service",
version: "2021-03-25",
})
@server("https://example.com", "Single server endpoint")
namespace PetStore;
Expand Down
1 change: 0 additions & 1 deletion docs/getting-started/typespec-for-openapi-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ In TypeSpec this information is specified with [decorators on the namespace][typ
@doc("The Contoso Widget Service provides access to the Contoso Widget API.")
@service({
title: "Widget Service",
version: "1.0.0",
})
@info({
contact: {
Expand Down
3 changes: 3 additions & 0 deletions packages/json-schema/src/json-schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ export class JsonSchemaEmitter extends TypeEmitter<Record<string, any>, JSONSche
}
}
async writeOutput(sourceFiles: SourceFile<Record<string, any>>[]): Promise<void> {
if (this.emitter.getOptions().noEmit) {
return;
}
this.#reportDuplicateIds();
const toEmit: EmittedSourceFile[] = [];

Expand Down
1 change: 1 addition & 0 deletions packages/json-schema/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function getHostForCadlFile(contents: string, decorators?: Record<s
}
host.addTypeSpecFile("main.cadl", contents);
await host.compile("main.cadl", {
noEmit: false,
outputDir: "cadl-output",
});
return host;
Expand Down
7 changes: 6 additions & 1 deletion packages/playground-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"build": "npm run build-samples && tsc -p . && vite build 2>&1",
"preview": "npm run build && vite preview",
"start": "vite",
"test": "vitest run",
"test:watch": "vitest -w",
"watch": "vite",
"test:e2e": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e ",
"test:e2e:headed": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e --headed",
Expand Down Expand Up @@ -74,12 +76,15 @@
"@types/swagger-ui-react": "^4.18.3",
"@typespec/eslint-config-typespec": "workspace:~",
"@vitejs/plugin-react": "~4.2.1",
"@vitest/coverage-v8": "^1.2.2",
"@vitest/ui": "^1.2.2",
"c8": "^9.1.0",
"cross-env": "~7.0.3",
"eslint": "^8.56.0",
"rimraf": "~5.0.5",
"rollup-plugin-visualizer": "~5.12.0",
"typescript": "~5.3.3",
"vite": "^5.1.0"
"vite": "^5.1.0",
"vitest": "^1.2.2"
}
}
1 change: 0 additions & 1 deletion packages/playground-website/samples/http.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "@typespec/http";
using TypeSpec.Http;
@service({
title: "Widget Service",
version: "1.0.0",
})
namespace DemoService;

Expand Down
16 changes: 16 additions & 0 deletions packages/playground-website/test/validate-samples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NodeHost, compile, resolvePath } from "@typespec/compiler";
import { expectDiagnosticEmpty, findTestPackageRoot } from "@typespec/compiler/testing";
import { it } from "vitest";
import { TypeSpecPlaygroundConfig } from "../src/index.js";

const samples = TypeSpecPlaygroundConfig.samples;
const packageRoot = await findTestPackageRoot(import.meta.url);
for (const [name, sample] of Object.entries(samples)) {
it(`compile ${name}`, async () => {
const program = await compile(NodeHost, resolvePath(packageRoot, sample.filename), {
noEmit: true,
emit: [sample.preferredEmitter],
});
expectDiagnosticEmpty(program.diagnostics);
});
}
11 changes: 11 additions & 0 deletions packages/playground-website/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { configDefaults, defineConfig, mergeConfig } from "vitest/config";
import { defaultTypeSpecVitestConfig } from "../../vitest.workspace.js";

export default mergeConfig(
defaultTypeSpecVitestConfig,
defineConfig({
test: {
exclude: [...configDefaults.exclude, "dist-dev/**/*"],
},
})
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@service({
title: "Pet Store Service",
version: "2021-03-25",
})
namespace PetStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@typespec/http";

using TypeSpec.Http;

@service({ title: "Accounting firm", version: "1.0.0" }) namespace MyOrg.Accounting;
@service({ title: "Accounting firm" }) namespace MyOrg.Accounting;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using TypeSpec.Http;

@service({
title: "Accounting firm",
version: "1.0.0",
})
namespace MyOrg.Accounting;

Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit abba29c

Please sign in to comment.