airtasker/spot

How to run apidoc.ts by ts-node ? TypeError: decorator is not a function

yaocccc opened this issue · 6 comments

Describe the bug

// APIDOCS.ts
import { api, body, endpoint, request, response } from "@airtasker/spot";

@api({ name: "my-api" })
class Api {}

@endpoint({ method: "POST", path: "/users" })
class CreateUser {
    @request
    request(@body _: {}) {}

    @response({ status: 201 })
    successfulResponse( @body _: {}) {}
}

node always res me

TypeError: decorator is not a function
    at /home/chenyc/test/app.ts:9:37
    at __decorate (/home/chenyc/test/app.ts:5:110)
    at /home/chenyc/test/app.ts:12:3
    at Object.<anonymous> (/home/chenyc/test/app.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Module.m._compile (/home/chenyc/.nvm/versions/node/v12.20.1/lib/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Object.require.extensions.<computed> [as .ts] (/home/chenyc/.nvm/versions/node/v12.20.1/lib/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)

Hi @yaocccc, what's the command you're running?

@lfportal ts-node xxx/xxx.ts

I hope apidoc decorator can maintain in project code
so I write decorator in my project code

Hi @yaocccc, what's the command you're running?

ts-node xxx/xxx.ts
or
tsc --downlevelIteration --skipLibCheck --module commonjs --target es5 --outDir build
&
node build/xxx.js

TypeError: decorator is not a function

I try something for fix it, discover it because spot.request & res & body ...

not a decorator factory

@yaocccc the intended use of the decorators for Spot is as a DSL. They do not produce any running code. Spot exposes a CLI for various commands that operate on these files. For example spot generate would be used like:

yarn spot generate --contract APIDOCS.ts --generator=openapi3 --language=yaml --out=.

to generate an equivalent OpenAPI 3 contract in yaml format.

If you would like to use the output as part of your toolchain in memory, you can instead follow the example here: https://github.com/airtasker/spot#in-memory-usage

Thanks,It worked.

I will try to find more ways to organize my project framework.