diff --git a/example/ex01/generated/ex01_apidir.ts b/example/ex01/generated/ex01_apidir.ts index 49b4080..2ecc821 100644 --- a/example/ex01/generated/ex01_apidir.ts +++ b/example/ex01/generated/ex01_apidir.ts @@ -6,14 +6,14 @@ export const Ex01InvpInfo = { name: "get-any-student", method: "GET", urlpath: "/student/any-one", - resp_type: undefined as unknown as Student, + responseType: undefined as unknown as Student, }, "get-student-from-person": { name: "get-student-from-person", method: "POST", urlpath: "/student/from-person", - req_type: undefined as unknown as Person, - resp_type: undefined as unknown as Student | string, + requestType: undefined as unknown as Person, + responseType: undefined as unknown as Student | string, }, } as const; export type Ex01InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/ex02/generated/ex02_apidir.ts b/example/ex02/generated/ex02_apidir.ts index f153ce7..4611425 100644 --- a/example/ex02/generated/ex02_apidir.ts +++ b/example/ex02/generated/ex02_apidir.ts @@ -6,57 +6,57 @@ export const Ex02InvpInfo = { name: "get-products", method: "POST", urlpath: "/products/get", - req_type: undefined as unknown as ProductQuery, - resp_type: undefined as unknown as Product[], + requestType: undefined as unknown as ProductQuery, + responseType: undefined as unknown as Product[], }, "get-orders": { name: "get-orders", method: "POST", urlpath: "/orders/get", - req_type: undefined as unknown as OrderQuery, - resp_type: undefined as unknown as Order[], + requestType: undefined as unknown as OrderQuery, + responseType: undefined as unknown as Order[], }, "get-product": { name: "get-product", method: "POST", urlpath: "/product/get", - req_type: undefined as unknown as ProductId, - resp_type: undefined as unknown as Product | string, + requestType: undefined as unknown as ProductId, + responseType: undefined as unknown as Product | string, }, "get-order": { name: "get-order", method: "POST", urlpath: "/order/get", - req_type: undefined as unknown as OrderId, - resp_type: undefined as unknown as Order | string, + requestType: undefined as unknown as OrderId, + responseType: undefined as unknown as Order | string, }, "register-product": { name: "register-product", method: "POST", urlpath: "/product/register", - req_type: undefined as unknown as ProductDetails, - resp_type: undefined as unknown as ProductId, + requestType: undefined as unknown as ProductDetails, + responseType: undefined as unknown as ProductId, }, "register-order": { name: "register-order", method: "POST", urlpath: "/order/register", - req_type: undefined as unknown as OrderDetails, - resp_type: undefined as unknown as OrderId | string | string, + requestType: undefined as unknown as OrderDetails, + responseType: undefined as unknown as OrderId | string | string, }, "update-product-details": { name: "update-product-details", method: "POST", urlpath: "/product/details/update", - req_type: undefined as unknown as { _0: ProductId; _1: ProductDetails }, - resp_type: undefined as unknown as OrderId | string, + requestType: undefined as unknown as { _0: ProductId; _1: ProductDetails }, + responseType: undefined as unknown as OrderId | string, }, "update-order-status": { name: "update-order-status", method: "POST", urlpath: "/order/status/update", - req_type: undefined as unknown as { _0: OrderId; _1: "Unpaid" | "Paid" | "Shipped" | "Delivered" | "Canceled" }, - resp_type: undefined as unknown as OrderId | string, + requestType: undefined as unknown as { _0: OrderId; _1: "Unpaid" | "Paid" | "Shipped" | "Delivered" | "Canceled" }, + responseType: undefined as unknown as OrderId | string, }, } as const; export type Ex02InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01.ts index 77a9c47..e367587 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01.ts @@ -7,14 +7,14 @@ export const Sample_apidir_01InvpInfo = { name: "get-any-student", method: "GET", urlpath: "/student/any-one", - resp_type: undefined as unknown as Student, + responseType: undefined as unknown as Student, }, "get-student-from-person": { name: "get-student-from-person", method: "POST", urlpath: "/student/from-person", - req_type: undefined as unknown as Person, - resp_type: undefined as unknown as Student, + requestType: undefined as unknown as Person, + responseType: undefined as unknown as Student, }, } as const; export type Sample_apidir_01InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01_no_mangling.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01_no_mangling.ts index 8563ead..79239ce 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01_no_mangling.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_01_no_mangling.ts @@ -7,14 +7,14 @@ export const Sample_apidir_01_no_manglingInvpInfo = { name: "get-any-student", method: "GET", urlpath: "/student/any-one", - resp_type: undefined as unknown as Student, + responseType: undefined as unknown as Student, }, "get-student-from-person": { name: "get-student-from-person", method: "POST", urlpath: "/student/from-person", - req_type: undefined as unknown as person_no_mangling, - resp_type: undefined as unknown as Student, + requestType: undefined as unknown as person_no_mangling, + responseType: undefined as unknown as Student, }, } as const; export type Sample_apidir_01_no_manglingInvpInfoMap = bindoj.IsApiDirInfoMap< diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_02.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_02.ts index f56ff9d..44c51c7 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_02.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_02.ts @@ -6,21 +6,21 @@ export const Sample_apidir_02InvpInfo = { name: "get-any-int-list", method: "GET", urlpath: "/int-list/any-one", - resp_type: undefined as unknown as IntListObjtuple, + responseType: undefined as unknown as IntListObjtuple, }, "inc-int-list": { name: "inc-int-list", method: "POST", urlpath: "/int-list/inc", - req_type: undefined as unknown as IntListObjtuple, - resp_type: undefined as unknown as IntListObjtuple, + requestType: undefined as unknown as IntListObjtuple, + responseType: undefined as unknown as IntListObjtuple, }, "sum-of-int-list": { name: "sum-of-int-list", method: "POST", urlpath: "/int-list/sum", - req_type: undefined as unknown as IntListObjtuple, - resp_type: undefined as unknown as Int, + requestType: undefined as unknown as IntListObjtuple, + responseType: undefined as unknown as Int, }, } as const; export type Sample_apidir_02InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_03.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_03.ts index c256257..f52fdba 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_03.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_03.ts @@ -6,8 +6,8 @@ export const Sample_apidir_03InvpInfo = { name: "id-of-person", method: "POST", urlpath: "/person/id", - req_type: undefined as unknown as Person, - resp_type: undefined as unknown as Int | String, + requestType: undefined as unknown as Person, + responseType: undefined as unknown as Int | String, }, } as const; export type Sample_apidir_03InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_04.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_04.ts index d125689..97b69aa 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_04.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_04.ts @@ -6,15 +6,15 @@ export const Sample_apidir_04InvpInfo = { name: "name-of-named_json", method: "POST", urlpath: "/named_json/name", - req_type: undefined as unknown as NamedJson, - resp_type: undefined as unknown as String, + requestType: undefined as unknown as NamedJson, + responseType: undefined as unknown as String, }, "json-of-named_json": { name: "json-of-named_json", method: "POST", urlpath: "/named_json/json", - req_type: undefined as unknown as NamedJson, - resp_type: undefined as unknown as any, + requestType: undefined as unknown as NamedJson, + responseType: undefined as unknown as any, }, } as const; export type Sample_apidir_04InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_05.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_05.ts index b8e7be1..7c97792 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_05.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_05.ts @@ -6,15 +6,15 @@ export const Sample_apidir_05InvpInfo = { name: "int-of-string", method: "POST", urlpath: "/option/int-of-string", - req_type: undefined as unknown as String, - resp_type: undefined as unknown as number | null | undefined, + requestType: undefined as unknown as String, + responseType: undefined as unknown as number | null | undefined, }, "option-of-complex": { name: "option-of-complex", method: "POST", urlpath: "/option/of-complex", - req_type: undefined as unknown as ComplexTypesNotuple, - resp_type: undefined as unknown as number | null | undefined, + requestType: undefined as unknown as ComplexTypesNotuple, + responseType: undefined as unknown as number | null | undefined, }, } as const; export type Sample_apidir_05InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_06.ts b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_06.ts index ed2c9a5..83912a4 100644 --- a/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_06.ts +++ b/example/for_dev/apidir_examples/typescript-metainfo/sample_apidir_06.ts @@ -6,15 +6,15 @@ export const Sample_apidir_06InvpInfo = { name: "get-x", method: "POST", urlpath: "/xy-opt/x", - req_type: undefined as unknown as XyOpt, - resp_type: undefined as unknown as number | null | undefined, + requestType: undefined as unknown as XyOpt, + responseType: undefined as unknown as number | null | undefined, }, "get-y": { name: "get-y", method: "POST", urlpath: "/xy-opt/y", - req_type: undefined as unknown as XyOpt, - resp_type: undefined as unknown as number | null | undefined, + requestType: undefined as unknown as XyOpt, + responseType: undefined as unknown as number | null | undefined, }, } as const; export type Sample_apidir_06InvpInfoMap = bindoj.IsApiDirInfoMap; diff --git a/src/lib_apidir_typescript/bindoj_apidir_typescript.ml b/src/lib_apidir_typescript/bindoj_apidir_typescript.ml index 4a744f3..b7afda6 100644 --- a/src/lib_apidir_typescript/bindoj_apidir_typescript.ml +++ b/src/lib_apidir_typescript/bindoj_apidir_typescript.ml @@ -123,7 +123,7 @@ let gen_raw : let endp_urlpath = invp.ip_urlpath |> litstr in let endp_method = litstr @@ match invp.ip_method with | `get -> "GET" | `post -> "POST" in - let resp_type_entry = "resp_type", typescript_resptypes invp' |> type_designator in + let resp_type_entry = "responseType", typescript_resptypes invp' |> type_designator in endp_name, objexpr ([ "name", litstr endp_name; @@ -136,7 +136,7 @@ let gen_raw : ] | `post -> Fn.flip List.append [ - "req_type", typescript_reqtype invp' |> type_designator; + "requestType", typescript_reqtype invp' |> type_designator; resp_type_entry; ] )) diff --git a/with_js/apidir-typescript-tests/tests/lib.ts b/with_js/apidir-typescript-tests/tests/lib.ts index 23d552b..63e28b7 100644 --- a/with_js/apidir-typescript-tests/tests/lib.ts +++ b/with_js/apidir-typescript-tests/tests/lib.ts @@ -11,11 +11,11 @@ export const createMockClient = const res: { [prop: string]: any } = {}; for (const [k, v] of Object.entries(invpInfo)) { if (v.method === "GET") { - res[k] = (): Promise<{body: typeof v.resp_type, status_code: number}> => { + res[k] = (): Promise<{ body: typeof v.responseType; status_code: number }> => { return mockServer.handle_path_json_get(v.urlpath); }; } else { - res[k] = (reqBody: typeof v): Promise<{body: typeof v.resp_type, status_code: number}> => { + res[k] = (reqBody: typeof v): Promise<{ body: typeof v.responseType; status_code: number }> => { return mockServer.handle_path_json_post(v.urlpath, reqBody); }; } diff --git a/with_js/public-packages/runtime/src/apidir-types.ts b/with_js/public-packages/runtime/src/apidir-types.ts index 679cad0..155a4f7 100644 --- a/with_js/public-packages/runtime/src/apidir-types.ts +++ b/with_js/public-packages/runtime/src/apidir-types.ts @@ -1,19 +1,19 @@ -export type ApiDirGetInvpInfo = { +export type ApiDirGetInvpInfo = { name: string; urlpath: string; - resp_type: unknown; + responseType: Req; method: "GET"; }; -export type ApiDirPostInvpInfo = { +export type ApiDirPostInvpInfo = { name: string; urlpath: string; - req_type: unknown; - resp_type: unknown; + requestType: Req; + responseType: Resp; method: "POST"; }; export type ApiDirInfoMap = { - [invp: string]: ApiDirGetInvpInfo | ApiDirPostInvpInfo; + [invp: string]: ApiDirGetInvpInfo | ApiDirPostInvpInfo; }; export type IsApiDirInfoMap = Dir; @@ -23,9 +23,9 @@ export type ApiDirAllInvps = keyof InfoMap; export type ApiDirInvpRequestType< Dir extends ApiDirInfoMap, invp extends keyof Dir -> = Dir[invp] extends ApiDirPostInvpInfo ? Dir[invp]["req_type"] : undefined; +> = Dir[invp] extends ApiDirPostInvpInfo ? Dir[invp]["requestType"] : undefined; -export type ApiDirInvpResponseType = Dir[invp]["resp_type"]; +export type ApiDirInvpResponseType = Dir[invp]["responseType"]; export type ApiDirInvpFunctionType< Dir extends ApiDirInfoMap,