Skip to content

Commit 3098ae0

Browse files
committed
first commit
0 parents  commit 3098ae0

File tree

10 files changed

+1013
-0
lines changed

10 files changed

+1013
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish (latest)
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
id-token: write
9+
10+
jobs:
11+
publish:
12+
if: "!github.event.release.prerelease"
13+
runs-on: ubuntu-latest
14+
environment: npm
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version-file: ".node-version"
21+
registry-url: "https://registry.npmjs.org"
22+
cache: "npm"
23+
- run: npm ci
24+
- run: npm pkg delete scripts devDependencies
25+
- run: npm publish --provenance --tag=latest
26+
env:
27+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules/

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.3.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 mascii
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# typespec-decorator-int64-as-string
2+
3+
A TypeSpec decorator for emitting `string` type from `int64`.
4+
5+
## Installation
6+
7+
```bash
8+
npm i -D typespec-decorator-int64-as-string
9+
# or
10+
yarn add -D typespec-decorator-int64-as-string
11+
# or
12+
pnpm i -D typespec-decorator-int64-as-string
13+
```
14+
15+
## Usage
16+
17+
In your .tsp files, apply the `@int64AsString` decorator as follows:
18+
19+
```typespec
20+
import "typespec-decorator-int64-as-string";
21+
22+
model Foo {
23+
@int64AsString id: int64;
24+
}
25+
26+
model Bar {
27+
id: int64;
28+
}
29+
```
30+
31+
When you emit the above .tsp to OpenAPI using `@typespec/openapi3`, the following schemas will be generated:
32+
33+
```yaml
34+
schemas:
35+
Foo:
36+
type: object
37+
required:
38+
- id
39+
properties:
40+
id:
41+
type: string # Here's the change by the @int64AsString decorator
42+
format: int64
43+
Bar:
44+
type: object
45+
required:
46+
- id
47+
properties:
48+
id:
49+
type: integer
50+
format: int64
51+
```
52+
53+
You can also perform a global import using `tspconfig.yaml`:
54+
55+
```yaml
56+
imports:
57+
- typespec-decorator-int64-as-string
58+
```
59+
60+
## License
61+
62+
MIT

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { $int64AsString } from "./int64AsString.js";

int64AsString.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { $encode } from "@typespec/compiler";
2+
3+
/**
4+
* @param context {import("@typespec/compiler").DecoratorContext}
5+
* @param target {import("@typespec/compiler").ModelProperty}
6+
*/
7+
export function $int64AsString(context, target) {
8+
if ("name" in target.type && target.type.name === "int64") {
9+
$encode(context, target, "int64");
10+
} else {
11+
throw new Error(
12+
"@int64AsString decorator can only be used for int64 properties.",
13+
);
14+
}
15+
}

int64AsString.tsp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "./int64AsString.js";
2+
3+
using TypeSpec.Reflection;
4+
5+
/**
6+
* Emit string type from int64.
7+
* This decorator is equivalent to `@encode("int64", string)`.
8+
*/
9+
extern dec int64AsString(target: ModelProperty);

0 commit comments

Comments
 (0)