Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@request
request(@body body: CreateCompanyRequestBody) {}
@response({ status: 201 })
successResponse(
@headers
headers: {
Location: String;
},
@body body: CompanyBody
) {}
@defaultResponse
defaultResponse(@body body: DefaultErrorBody) {}
@test(
{
request: {
body: {
private: true
}
},
response: {
status: 400
}
},
{ allowInvalidRequest: true }
)
defaultResponseTest() {}
}
interface CreateCompanyRequestBody {
@api({ name: "company-api" })
class CompanyApi {}
@draft
@endpoint({
method: "POST",
path: "/companies"
})
class CreateCompany {
@request
request(@body body: CreateCompanyRequestBody) {}
@response({ status: 201 })
successResponse(@body body: CompanyBody) {}
@test({
request: {
body: {
name: "My Company",
private: true
}
},
response: {
status: 201
}
})
successResponseTest() {}
}
interface CreateCompanyRequestBody {
name: String;
private: boolean;
method: "GET",
path: "/companies/:companyId"
})
class GetCompany {
@request
request(
@pathParams
pathParams: {
companyId: String;
}
) {}
@response({ status: 200 })
successResponse(@body body: CompanyBody) {}
@test({
states: [{ name: "a company exists", params: { id: "abc" } }],
request: {
pathParams: {
companyId: "abc"
}
},
response: {
status: 200
}
})
successResponseTest() {}
}
interface CompanyBody {
name: String;
employeeCount: Integer;
path: "/companies"
})
class CreateCompany {
@request
request(@body body: CreateCompanyRequestBody) {}
@response({ status: 201 })
successResponse(
@headers
headers: {
Location: String;
},
@body body: CompanyBody
) {}
@test({
request: {
body: {
name: "My Company",
private: true
}
},
response: {
status: 201
}
})
successResponseTest() {}
}
interface CreateCompanyRequestBody {
name: String;
private: boolean;
@request
request(@body body: CreateCompanyRequestBody) {}
@response({ status: 201 })
successResponse(
@headers
headers: {
Location: String;
},
@body body: CompanyBody
) {}
@response({ status: 400 })
badRequestResponse(@body body: ErrorBody) {}
@test({
request: {
body: {
name: "My Company",
private: true
}
},
response: {
status: 201
}
})
successResponseTest() {}
@test(
{
request: {
body: {
badRequestResponse(@body body: ErrorBody) {}
@test({
request: {
body: {
name: "My Company",
private: true
}
},
response: {
status: 201
}
})
successResponseTest() {}
@test(
{
request: {
body: {
name: 5
}
},
response: {
status: 400
}
},
{ allowInvalidRequest: true }
)
badRequestTest() {}
}
interface CreateCompanyRequestBody {
method: "GET",
path: "/companies"
})
class GetCompanies {
@request
request(
@queryParams
queryParam: {
profile?: { name: String };
}
) {}
@response({ status: 200 })
successResponse(@body body: CompanyBody[]) {}
@test({
request: {
queryParams: {
profile: {
name: "testname"
}
}
},
response: {
status: 200
}
})
successResponseTest() {}
}
interface CompanyBody {
name: String;
path: "/companies/:companyId/users/:userId"
})
class GetUser {
@request
request(
@pathParams
pathParams: {
companyId: String;
userId: String;
}
) {}
@response({ status: 200 })
successResponse(@body body: UserBody) {}
@test({
states: [
{ name: "a company exists", params: { id: "abc" } },
{ name: "a user exists", params: { id: "def", companyId: "abc" } }
],
request: {
pathParams: {
companyId: "abc",
userId: "def"
}
},
response: {
status: 200
}
})
successResponseTest() {}
}
headers: {
/** Location header */
Location: String;
},
/** User response body */
@body body: UserBody
) {}
/** Bad request response */
@response({ status: 404 })
badRequestResponse(
/** Error response body */
@body body: ErrorBody
) {}
@test({
states: [{ name: "userExists", params: { id: 101 } }],
request: {
headers: {
"x-auth-token": "sometoken"
},
pathParams: {
companyId: "company",
userId: "user"
}
},
response: { status: 201 }
})
successResponseTest() {}
}
) {}
/** Bad request response */
@response({ status: 400 })
badRequestResponse(
/** Error response body */
@body body: ErrorBody
) {}
@defaultResponse
unexpectedResponse(
/** Error response body */
@body body: ErrorBody
) {}
@test({
request: {
pathParams: {
companyId: "abc"
},
headers: {
"x-auth-token": "hellotoken"
},
body: {
data: {
firstName: "John",
lastName: "Snow",
age: 15,
email: "johnsnow@spot.com",
address: "some address"
}
}