airtasker/spot

Allow types and interfaces in defining the request details

mahirk opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
In using the json-schema generators I noticed that it does not convert out the request query, params or header into a JSON Schema. Further discovered that I am unable to describe the header and path params as follows:

    request(
        @headers
        headers: SomeTypeHere,
        @pathParams
        pathParams: SomeOtherTypeHere
    ) {}

instead the request would have to be defined as follows:

    request(
        @headers
        headers: { someString: string; },
        @pathParams
        pathParams: { someOtherString: string; }
    ) {}

In investigating the contract, I also noticed the lack of the above request details in the types object of the contract.

Describe the solution you'd like
Remove getParameterTypeAsTypeLiteralOrThrow(parameter); to permit interfaces to be used. After investigating the AST, I am looking into how the TypeReference can be used to retrieve the PropertySignatures.

The method can be replaced as getParameterPropertySignatures and it can handle either getting the signatures from them TypeLiteral or can use the TypeReference.Symbol to retrieve the Declarations and then the PropertySignatures like getTargetDeclarationFromTypeReference

Sample AST: https://ts-ast-viewer.com/#code/FASwtgDg9gTgLgAgN4IIYRAGgQUwHYAm0Iec2MOAjgK44DOZCFd0edO2ARlAQJ7YRUcABYAFVDFRg62dgGNqMEHF4AJHKgI4Y2YRq0w6CAL4IAZjChgEAcgACqEPFR0A1toD0LKHBsBuYFBSbTNUORwEACUqWgYAZRw5CkQkYAR02wAPAFp0EGy6EABzPBIi7PdeGwAuBAYlPCKA40C5ABsXIwBxHDhomno4OKkINojUjIQ7CgGGNIyZ2LgACnnJ9Ls9TW06NfWtgzpa-qWEpN7MPYBKZBa96fpWdmWUBiFqI4QAJgAGH5MrntmE8cMs7Nw+AgIbxanErDhot42DgAEI8Xg3JAtO7tToIHp9GKDYaQMZfZD3RaDIFEhirdYZTb6HZ7SYHHa1CYMyY2HJ5ArFUqNCo4Kq1eplALckyXSaYu6TB5I56vODvT6-f7GQGTYFQZFg6FQ9Gw+GIkFovjy4B3IA

Location

const headerTypeLiteral = getParameterTypeAsTypeLiteralOrThrow(parameter);
and
const pathParamTypeLiteral = getParameterTypeAsTypeLiteralOrThrow(parameter);

@lfportal I created a PR which should help implement this capability: #1022