Skip to content

http-specs, add smoke test #7529

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

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add smoke tests
4 changes: 3 additions & 1 deletion packages/http-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"watch": "tsc -p ./tsconfig.build.json --watch",
"build": "tsc -p ./tsconfig.build.json && pnpm validate-scenarios",
"build": "tsc -p ./tsconfig.build.json && pnpm validate-scenarios && pnpm build:smoke",
"clean": "rimraf dist/ temp/",
"test:e2e": "pnpm validate-mock-apis && pnpm validate-client-server",
"validate:all": "pnpm build && pnpm regen-docs && pnpm test:e2e",
Expand All @@ -19,6 +19,7 @@
"validate-mock-apis": "tsp-spector validate-mock-apis ./specs",
"check-scenario-coverage": "tsp-spector check-coverage ./specs",
"validate-client-server": "concurrently \"tsp-spector server start ./specs\" \"pnpm knock\"; tsp-spector server stop",
"build:smoke": "tsp compile smoke/petstore --warn-as-error --no-emit && tsp compile smoke/todoapp --warn-as-error --no-emit",
"client": "pnpm knock",
"knock": "tsp-spector knock ./specs",
"serve": "tsp-spector serve ./specs",
Expand Down Expand Up @@ -48,6 +49,7 @@
"@types/node": "~22.13.11",
"@typespec/openapi": "workspace:^",
"@typespec/openapi3": "workspace:^",
"@typespec/json-schema": "workspace:^",
"concurrently": "^9.1.2",
"rimraf": "~6.0.1",
"typescript": "~5.8.2"
Expand Down
96 changes: 96 additions & 0 deletions packages/http-specs/smoke/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