Skip to content

draft, add smoke-http-specs for smoke tests #6981

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/draft_smoke-http-specs-2025-3-15-10-51-5.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the goal of this probject to have the samples we talked about a while ago that every emitter could share?

Copy link
Contributor Author

@weidongxu-microsoft weidongxu-microsoft May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to include the samples from typespec-e2e.

We've agreed that they should not be spector case. The issue chose to call them smoke test.

I haven't figured out with Allen on what is the best approach is, for matching a generated client and a generated (+handwritten) server for e2e test.

But here I first want to see if I can at least pack the tsp files, so each client can get the lib, generate the code from them, compile/lint the code, as a simpler verification.

Let me know your opinon.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/smoke-http-specs"
---

Add smoke-http-specs for smoke test
16 changes: 16 additions & 0 deletions packages/smoke-http-specs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Smoke Http Specs

This package contains all the scenarios that should be supported by a client & service generator.

## Development

1. [FOLLOW THE MONOREPO INSTRUCTION](https://github.com/microsoft/typespec) to get the environment setup.
2. Scenarios should be in `./specs` folder

#### Update version for release

```bash
pnpm change version --only "@typespec/smoke-http-specs"
```

Push the changes in branch named after the pattern `publish/xyz`. Once merged, the package will be auto-released.
33 changes: 33 additions & 0 deletions packages/smoke-http-specs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@typespec/smoke-http-specs",
"version": "0.1.0-alpha.0",
"description": "Spec scenarios for smoke tests",
"main": "dist/index.js",
"type": "module",
"scripts": {
"watch": "tsc -p ./tsconfig.build.json --watch",
"build": "tsc -p ./tsconfig.build.json",
"clean": "rimraf dist/ temp/",
"ci": "prettier specs --write",
"test": "echo \"Error: no test specified\""
},
"engines": {
"node": ">=20.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/typespec.git"
},
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/typespec/issues"
},
"homepage": "https://github.com/microsoft/typespec#readme",
"peerDependencies": {
"@typespec/compiler": "workspace:^",
"@typespec/http": "workspace:^",
"@typespec/rest": "workspace:^",
"@typespec/versioning": "workspace:^"
}
}
96 changes: 96 additions & 0 deletions packages/smoke-http-specs/specs/petstore/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import "@typespec/rest";
import "@typespec/openapi";

@service(#{ title: "Pet Store Service" })
namespace PetStore;

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Rest.Resource;

@error
model PetStoreError {
code: int32;
message: string;
}

@resource("pets")
model Pet {
@key("petId")
id: int32;

name: string;
tag?: string;

@minValue(0)
@maxValue(20)
age: int32;

ownerId: int64;
}

@resource("toys")
@parentResource(Pet)
model Toy {
@key("toyId")
id: int64;

petId: int64;
name: string;
}

@resource("owners")
model Owner {
@key("ownerId")
id: int64;

name: string;
age: int32;
}

@resource("checkups")
model Checkup {
@key("checkupId")
id: int32;

vetName: string;
notes: string;
}

@segment("insurance")
model Insurance {
provider: string;
premium: int32;
deductible: int32;
}

interface Pets extends ResourceOperations<Pet, PetStoreError> {}

interface PetCheckups
extends ExtensionResourceCreateOrUpdate<Checkup, Pet, PetStoreError>,
ExtensionResourceList<Checkup, Pet, PetStoreError> {}

interface PetInsurance extends SingletonResourceOperations<Insurance, Pet, PetStoreError> {}

interface Toys extends ResourceRead<Toy, PetStoreError> {
@autoRoute
@listsResource(Toy)
list(
...ParentKeysOf<Toy>,
@query nameFilter: string,
): CollectionWithNextLink<Toy> | PetStoreError;
}

interface ToyInsurance extends SingletonResourceOperations<Insurance, Toy, PetStoreError> {}

interface Checkups
extends ResourceCreateOrUpdate<Checkup, PetStoreError>,
ResourceList<Checkup, PetStoreError> {}

interface Owners extends ResourceOperations<Owner, PetStoreError> {}

interface OwnerCheckups
extends ExtensionResourceCreateOrUpdate<Checkup, Owner, PetStoreError>,
ExtensionResourceList<Checkup, Owner, PetStoreError> {}

interface OwnerInsurance extends SingletonResourceOperations<Insurance, Owner, PetStoreError> {}
Loading
Loading