tsp project
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.sqlite3
|
||||
__pycache__
|
||||
.venv
|
||||
tsp-output
|
||||
|
||||
1
tsp/.gitignore
vendored
Normal file
1
tsp/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
7477
tsp/package-lock.json
generated
Normal file
7477
tsp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
tsp/package.json
Normal file
28
tsp/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@foo/cms",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "multiview [npm run compile -- --watch] [npm run serve]",
|
||||
"compile": "tsp compile src",
|
||||
"serve": "counterfact ./openapi.json server --prefix api/"
|
||||
},
|
||||
"exports": {
|
||||
"./crud": "./src/crud.tsp"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typespec/compiler": "latest",
|
||||
"@typespec/http": "latest",
|
||||
"@typespec/openapi3": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typespec/compiler": "latest",
|
||||
"@typespec/http": "latest",
|
||||
"@typespec/openapi3": "latest",
|
||||
"@typespec/http-server-csharp": "latest",
|
||||
"@typespec/http-server-js": "latest",
|
||||
"counterfact": "^1.2.0",
|
||||
"multiview": "^3.0.1",
|
||||
"@pojagi/typespec-drf": "../../typespec-drf"
|
||||
}
|
||||
}
|
||||
12
tsp/src/api.tsp
Normal file
12
tsp/src/api.tsp
Normal file
@@ -0,0 +1,12 @@
|
||||
import "@typespec/http";
|
||||
|
||||
import "./api/v1.tsp";
|
||||
|
||||
using TypeSpec.Http;
|
||||
|
||||
@doc("A content management service.")
|
||||
@service({
|
||||
title: "Foo Content Management Service",
|
||||
})
|
||||
@route("/api")
|
||||
namespace Api;
|
||||
10
tsp/src/api/v1.tsp
Normal file
10
tsp/src/api/v1.tsp
Normal file
@@ -0,0 +1,10 @@
|
||||
import "@typespec/http";
|
||||
|
||||
import "./v1/config.tsp";
|
||||
import "./v1/journal.tsp";
|
||||
|
||||
using TypeSpec.Http;
|
||||
|
||||
@doc("The first version of the Api.")
|
||||
@route("/v1")
|
||||
namespace Api.V1;
|
||||
17
tsp/src/api/v1/config.tsp
Normal file
17
tsp/src/api/v1/config.tsp
Normal file
@@ -0,0 +1,17 @@
|
||||
import "@typespec/http";
|
||||
|
||||
import "@foo/cms/crud";
|
||||
|
||||
using TypeSpec.Http;
|
||||
|
||||
namespace Api.V1.Config;
|
||||
|
||||
model Setting {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
@route("/settings")
|
||||
@tag("config")
|
||||
@summary("A collection of application settings.")
|
||||
interface Settings extends Entity<Setting> {}
|
||||
23
tsp/src/api/v1/journal.tsp
Normal file
23
tsp/src/api/v1/journal.tsp
Normal file
@@ -0,0 +1,23 @@
|
||||
import "@typespec/http";
|
||||
|
||||
import "@foo/cms/crud";
|
||||
|
||||
using TypeSpec.Http;
|
||||
|
||||
namespace Api.V1.Journal;
|
||||
|
||||
model EntryBody {
|
||||
date: utcDateTime;
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
model Entry extends EntryBody {
|
||||
@minValue(1)
|
||||
id: uint32;
|
||||
}
|
||||
|
||||
@route("/entries")
|
||||
@tag("config")
|
||||
@summary("A collection of journal entries.")
|
||||
interface Entries extends Entity<Entry, Body = EntryBody, Id = uint32> {}
|
||||
27
tsp/src/crud.tsp
Normal file
27
tsp/src/crud.tsp
Normal file
@@ -0,0 +1,27 @@
|
||||
import "@typespec/http";
|
||||
|
||||
using TypeSpec.Http;
|
||||
|
||||
|
||||
@error
|
||||
model ProblemDetails {
|
||||
type: string;
|
||||
title: string;
|
||||
status: int32;
|
||||
detail: string;
|
||||
}
|
||||
|
||||
model NotFound {
|
||||
@statusCode _: 404;
|
||||
}
|
||||
|
||||
interface Entity<T, Body = T, Id = string> {
|
||||
@get list(): T[] | ProblemDetails;
|
||||
@get read(@path id: Id): T | NotFound | ProblemDetails;
|
||||
@post create(@body body: Body): {
|
||||
@statusCode _: 201;
|
||||
...T;
|
||||
} | ProblemDetails;
|
||||
@patch update(@path id: Id, ...Body): T | NotFound | ProblemDetails;
|
||||
@delete delete(@path id: string): T | NotFound | ProblemDetails;
|
||||
}
|
||||
1
tsp/src/main.tsp
Normal file
1
tsp/src/main.tsp
Normal file
@@ -0,0 +1 @@
|
||||
import "./api.tsp";
|
||||
11
tsp/tspconfig.yaml
Normal file
11
tsp/tspconfig.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
emit:
|
||||
# - "@typespec/openapi3"
|
||||
# - "@typespec/http-server-csharp"
|
||||
# - "@typespec/http-server-js"
|
||||
- "@pojagi/typespec-drf"
|
||||
options:
|
||||
# "@typespec/openapi3":
|
||||
# # emitter-output-dir: "{project-root}"
|
||||
# file-type: yaml
|
||||
# "@typespec/http-server-js":
|
||||
# express: true
|
||||
Reference in New Issue
Block a user