Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate playground samples and fix docs to deprecated version #2977

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions packages/playground-website/@typespec/json-schema/Address.yaml
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: Address.yaml
type: object
properties:
street:
type: string
city:
type: string
country:
type: string
required:
- street
- city
- country
description: Respresent an address
21 changes: 21 additions & 0 deletions packages/playground-website/@typespec/json-schema/Car.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: Car.yaml
type: object
properties:
kind:
anyOf:
- type: string
const: ev
- type: string
const: ice
description: Kind of car
brand:
type: string
description: Brand of the car
model:
type: string
description: Model of the car
required:
- kind
- brand
- model
34 changes: 34 additions & 0 deletions packages/playground-website/@typespec/json-schema/Person.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: Person.yaml
type: object
properties:
firstName:
type: string
description: The person's first name.
lastName:
type: string
description: The person's last name.
age:
type: integer
minimum: 0
maximum: 2147483647
description: Age in years which must be equal to or greater than zero.
address:
$ref: Address.yaml
description: Person address
nickNames:
type: array
items:
type: string
uniqueItems: true
description: List of nick names
cars:
type: array
items:
$ref: Car.yaml
description: List of cars person owns
required:
- firstName
- lastName
- age
- address
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.

Loading