@typespec/http-client-js 0.4.0-dev.0 → 0.4.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
  2. package/dist/src/components/client-context/client-context-factory.js +104 -37
  3. package/dist/src/components/client-context/client-context-factory.js.map +1 -1
  4. package/dist/src/components/client-operation.js +5 -7
  5. package/dist/src/components/client-operation.js.map +1 -1
  6. package/dist/src/components/client.d.ts.map +1 -1
  7. package/dist/src/components/client.js +5 -3
  8. package/dist/src/components/client.js.map +1 -1
  9. package/dist/src/components/external-packages/ts-http-runtime.d.ts +8 -3
  10. package/dist/src/components/external-packages/ts-http-runtime.d.ts.map +1 -1
  11. package/dist/src/components/external-packages/ts-http-runtime.js +2 -2
  12. package/dist/src/components/external-packages/ts-http-runtime.js.map +1 -1
  13. package/dist/src/components/http-request-options.d.ts +1 -1
  14. package/dist/src/components/http-request-options.d.ts.map +1 -1
  15. package/dist/src/components/http-request-options.js +2 -1
  16. package/dist/src/components/http-request-options.js.map +1 -1
  17. package/dist/src/components/http-request-parameters-expression.d.ts +2 -1
  18. package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
  19. package/dist/src/components/http-request-parameters-expression.js +125 -18
  20. package/dist/src/components/http-request-parameters-expression.js.map +1 -1
  21. package/dist/src/components/http-request.js +1 -0
  22. package/dist/src/components/http-request.js.map +1 -1
  23. package/dist/src/components/operation-parameters.d.ts +1 -1
  24. package/dist/src/components/operation-parameters.d.ts.map +1 -1
  25. package/dist/src/components/operation-parameters.js +7 -5
  26. package/dist/src/components/operation-parameters.js.map +1 -1
  27. package/dist/src/components/static-helpers/bytes-encoding.js +14 -16
  28. package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -1
  29. package/dist/src/components/static-helpers/multipart-helpers.js +12 -10
  30. package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -1
  31. package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
  32. package/dist/src/components/static-helpers/rest-error.js +15 -10
  33. package/dist/src/components/static-helpers/rest-error.js.map +1 -1
  34. package/dist/src/components/testing/client-options.d.ts +1 -1
  35. package/dist/src/components/testing/client-options.d.ts.map +1 -1
  36. package/dist/src/components/transforms/json/json-array-transform.d.ts +1 -1
  37. package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
  38. package/dist/src/components/transforms/json/json-array-transform.js +6 -7
  39. package/dist/src/components/transforms/json/json-array-transform.js.map +1 -1
  40. package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
  41. package/dist/src/components/transforms/json/json-model-property-transform.js +15 -2
  42. package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -1
  43. package/dist/src/components/transforms/json/json-model-transform.js +8 -8
  44. package/dist/src/components/transforms/json/json-model-transform.js.map +1 -1
  45. package/dist/src/components/transforms/json/json-record-transform.d.ts +1 -1
  46. package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
  47. package/dist/src/components/transforms/json/json-record-transform.js +6 -7
  48. package/dist/src/components/transforms/json/json-record-transform.js.map +1 -1
  49. package/dist/src/components/transforms/json/json-transform-discriminator.js +6 -7
  50. package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -1
  51. package/dist/src/components/transforms/json/union-transform.js +6 -7
  52. package/dist/src/components/transforms/json/union-transform.js.map +1 -1
  53. package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
  54. package/dist/src/components/transforms/operation-transform-declaration.js +2 -3
  55. package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -1
  56. package/dist/src/utils/parameters.d.ts +1 -1
  57. package/dist/src/utils/parameters.d.ts.map +1 -1
  58. package/dist/src/utils/parameters.js +29 -14
  59. package/dist/src/utils/parameters.js.map +1 -1
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/package.json +5 -5
  62. package/src/components/client-context/client-context-factory.tsx +86 -37
  63. package/src/components/client-operation.tsx +3 -3
  64. package/src/components/client.tsx +6 -9
  65. package/src/components/external-packages/ts-http-runtime.ts +9 -4
  66. package/src/components/http-request-options.tsx +6 -1
  67. package/src/components/http-request-parameters-expression.tsx +142 -18
  68. package/src/components/http-request.tsx +1 -0
  69. package/src/components/operation-parameters.tsx +9 -8
  70. package/src/components/static-helpers/bytes-encoding.tsx +5 -5
  71. package/src/components/static-helpers/multipart-helpers.tsx +7 -7
  72. package/src/components/static-helpers/rest-error.tsx +6 -3
  73. package/src/components/transforms/json/json-array-transform.tsx +3 -3
  74. package/src/components/transforms/json/json-model-property-transform.tsx +13 -1
  75. package/src/components/transforms/json/json-model-transform.tsx +3 -3
  76. package/src/components/transforms/json/json-record-transform.tsx +3 -3
  77. package/src/components/transforms/json/json-transform-discriminator.tsx +3 -3
  78. package/src/components/transforms/json/union-transform.tsx +3 -3
  79. package/src/components/transforms/operation-transform-declaration.tsx +2 -1
  80. package/src/utils/parameters.tsx +43 -28
  81. package/test/e2e/http/authentication/oauth2/main.test.ts +6 -16
  82. package/test/e2e/http/authentication/union/main.test.ts +2 -5
  83. package/test/scenarios/auth/basic_auth.md +11 -7
  84. package/test/scenarios/auth/bearer.md +11 -7
  85. package/test/scenarios/auth/client_parameters.md +19 -6
  86. package/test/scenarios/auth/client_structure.md +1 -1
  87. package/test/scenarios/auth/key_credential.md +11 -6
  88. package/test/scenarios/auth/oauth2.md +91 -0
  89. package/test/scenarios/auth/sub_client_override.md +11 -7
  90. package/test/scenarios/encoding/header_bytes.md +1 -1
  91. package/test/scenarios/encoding/header_date.md +1 -1
  92. package/test/scenarios/encoding/query_date.md +1 -1
  93. package/test/scenarios/http-operations/query-parameter.md +1 -1
  94. package/test/scenarios/operation-parameters/body_root_anonymous.md +1 -1
  95. package/test/scenarios/operation-parameters/with_body_property.md +1 -1
  96. package/test/scenarios/operation-parameters/with_body_root.md +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-js",
3
- "version": "0.4.0-dev.0",
3
+ "version": "0.4.0-dev.2",
4
4
  "type": "module",
5
5
  "homepage": "https://typespec.io",
6
6
  "readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
@@ -31,8 +31,8 @@
31
31
  "@typespec/rest": "^0.68.0 || >=0.69.0-dev <0.69.0"
32
32
  },
33
33
  "dependencies": {
34
- "@alloy-js/core": "^0.6.0",
35
- "@alloy-js/typescript": "^0.6.0",
34
+ "@alloy-js/core": "^0.10.0",
35
+ "@alloy-js/typescript": "^0.10.0",
36
36
  "@typespec/emitter-framework": "^0.4.0 || >=0.5.0-dev <0.5.0",
37
37
  "@typespec/http-client": "^0.4.0 || >=0.5.0-dev <0.5.0",
38
38
  "prettier": "~3.5.3"
@@ -45,8 +45,8 @@
45
45
  "@types/yargs": "~17.0.33",
46
46
  "@typespec/http": "^1.0.0-rc.0",
47
47
  "@typespec/http-specs": "^0.1.0-alpha.17 || >=0.1.0-alpha.18-dev <0.1.0-alpha.18",
48
- "@typespec/spector": "^0.1.0-alpha.10 || >=0.1.0-alpha.11-dev <0.1.0-alpha.11",
49
- "@typespec/ts-http-runtime": "0.1.0",
48
+ "@typespec/spector": "^0.1.0-alpha.11 || >=0.1.0-alpha.12-dev <0.1.0-alpha.12",
49
+ "@typespec/ts-http-runtime": "0.2.1",
50
50
  "@typespec/versioning": "^0.68.0 || >=0.69.0-dev <0.69.0",
51
51
  "@vitest/ui": "^3.0.9",
52
52
  "change-case": "~5.4.4",
@@ -2,6 +2,7 @@ import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { $ } from "@typespec/compiler/experimental/typekit";
4
4
  import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
5
+ import { HttpAuth, type OAuth2Flow } from "@typespec/http";
5
6
  import * as cl from "@typespec/http-client";
6
7
  import { reportDiagnostic } from "../../lib.js";
7
8
  import { buildClientParameters } from "../../utils/parameters.jsx";
@@ -37,7 +38,7 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
37
38
  );
38
39
 
39
40
  let credentialsRef: string | undefined;
40
- if (clientConstructor.parameters.properties.has("credential")) {
41
+ if (parameters.some((p) => p.name === "credential")) {
41
42
  credentialsRef = "credential";
42
43
  }
43
44
 
@@ -75,66 +76,114 @@ interface ClientFactoryArgumentsProps {
75
76
  function ClientFactoryArguments(props: ClientFactoryArgumentsProps) {
76
77
  const params = [<>{props.endpointRef},</>];
77
78
 
78
- if (props.credentialsRef) {
79
- params.push(<>{props.credentialsRef},</>);
80
- }
81
-
82
79
  return [
83
80
  ...params,
84
- <ClientOptionsExpression>
85
- <CredentialOptions client={props.client} />
86
- </ClientOptionsExpression>,
81
+ props.credentialsRef ? (
82
+ <ClientOptionsExpression>
83
+ {props.credentialsRef}
84
+ <AuthSchemeOptions client={props.client} />
85
+ </ClientOptionsExpression>
86
+ ) : (
87
+ <ClientOptionsExpression />
88
+ ),
87
89
  ];
88
90
  }
89
91
 
90
- interface CredentialOptionsProps {
92
+ interface AuthSchemeOptionsProps {
91
93
  client: cl.Client;
92
94
  }
93
95
 
94
- function CredentialOptions(props: CredentialOptionsProps) {
95
- const clientCredential = $.client.getAuth(props.client);
96
-
97
- if (clientCredential.schemes.length === 0) {
98
- return null;
99
- }
100
-
101
- if (clientCredential.schemes.length !== 1) {
102
- reportDiagnostic($.program, {
103
- code: "multiple-auth-schemes-not-yet-supported",
104
- target: props.client.type,
105
- });
106
- }
107
-
108
- const scheme = clientCredential.schemes[0];
96
+ interface AuthSchemeProps {
97
+ scheme: HttpAuth;
98
+ client: cl.Client;
99
+ }
109
100
 
110
- switch (scheme.type) {
101
+ function AuthScheme(props: AuthSchemeProps) {
102
+ switch (props.scheme.type) {
111
103
  case "http":
112
- // Todo: handle scopes?
113
104
  return (
114
- <ts.ObjectProperty name="credentials">
115
- <ts.ObjectExpression>
116
- <ts.ObjectProperty name="apiKeyHeaderName" jsValue={"Authorization"} />
117
- </ts.ObjectExpression>
118
- </ts.ObjectProperty>
105
+ <ts.ObjectExpression>
106
+ <ay.List comma>
107
+ <ts.ObjectProperty name="kind" jsValue="http" />
108
+ <ts.ObjectProperty name="scheme" jsValue={props.scheme.scheme.toLowerCase()} />
109
+ </ay.List>
110
+ </ts.ObjectExpression>
119
111
  );
120
112
  case "apiKey":
121
- if (scheme.in !== "header") {
113
+ if (props.scheme.in !== "header") {
122
114
  reportDiagnostic($.program, { code: "non-model-parts", target: props.client.service });
123
115
  return null;
124
116
  }
125
117
 
126
118
  return (
127
- <ts.ObjectProperty name="credentials">
128
- <ts.ObjectExpression>
129
- <ts.ObjectProperty name="apiKeyHeaderName" jsValue={scheme.name} />
130
- </ts.ObjectExpression>
131
- </ts.ObjectProperty>
119
+ <ts.ObjectExpression>
120
+ <ay.List comma>
121
+ <ts.ObjectProperty name="kind" jsValue="apiKey" />
122
+ <ts.ObjectProperty name="apiKeyLocation" jsValue={props.scheme.in} />
123
+ <ts.ObjectProperty name="name" jsValue={props.scheme.name} />
124
+ </ay.List>
125
+ </ts.ObjectExpression>
126
+ );
127
+ case "oauth2":
128
+ return (
129
+ <ts.ObjectExpression>
130
+ <ay.List comma>
131
+ <ts.ObjectProperty name="kind" jsValue="oauth2" />
132
+ <ts.ObjectProperty name="flows">
133
+ [
134
+ <ay.For each={props.scheme.flows} comma line>
135
+ {(flow) => <OAuth2Flow flow={flow} />}
136
+ </ay.For>
137
+ ]
138
+ </ts.ObjectProperty>
139
+ </ay.List>
140
+ </ts.ObjectExpression>
132
141
  );
133
142
  default:
134
143
  return null;
135
144
  }
136
145
  }
137
146
 
147
+ interface OAuth2FlowProps {
148
+ flow: OAuth2Flow;
149
+ }
150
+
151
+ function OAuth2Flow(props: OAuth2FlowProps) {
152
+ // rename type to kind and clean up the scopes
153
+ const { type, ...rewrittenFlow } = {
154
+ kind: props.flow.type,
155
+ ...props.flow,
156
+ // scopes are sometimes duplicated so converting to set and back to dedupe
157
+ scopes: [...new Set(props.flow.scopes.map((s) => s.value))],
158
+ };
159
+
160
+ return <ts.ObjectExpression jsValue={rewrittenFlow} />;
161
+ }
162
+
163
+ function AuthSchemeOptions(props: AuthSchemeOptionsProps) {
164
+ const clientCredential = $.client.getAuth(props.client);
165
+
166
+ if (clientCredential.schemes.length === 0) {
167
+ return null;
168
+ }
169
+
170
+ // Filtering out custom http schemes for "http/custom" spector scenario
171
+ // TODO: Should typekit allow for arbitrary strings on scheme with http auth type?
172
+ const supportedSchemes = clientCredential.schemes.filter(
173
+ (s) => s.type !== "http" || ["Basic", "Bearer"].includes(s.scheme),
174
+ );
175
+
176
+ return (
177
+ <ts.ObjectProperty name="authSchemes">
178
+ [
179
+ <ay.For each={supportedSchemes} comma line>
180
+ {(scheme) => <AuthScheme scheme={scheme} client={props.client} />}
181
+ </ay.For>
182
+ ]
183
+ </ts.ObjectProperty>
184
+ );
185
+ }
186
+
138
187
  interface ClientOptionsExpressionProps {
139
188
  children?: ay.Children;
140
189
  }
@@ -40,10 +40,10 @@ export function ClientOperation(props: ClientOperationProps) {
40
40
  const returnType = $.httpOperation.getReturnType(props.clientOperation.httpOperation);
41
41
  const responseRefkey = ay.refkey(props.clientOperation, "http-response");
42
42
  const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
43
- const signatureParams: Record<string, ts.ParameterDescriptor | ay.Children> = {
44
- client: { type: clientContextInterfaceRef, refkey: ay.refkey(client, "client") },
43
+ const signatureParams: ts.ParameterDescriptor[] = [
44
+ { name: "client", type: clientContextInterfaceRef, refkey: ay.refkey(client, "client") },
45
45
  ...getOperationParameters(props.clientOperation.httpOperation),
46
- };
46
+ ];
47
47
  return (
48
48
  <>
49
49
  <OperationOptionsDeclaration operation={props.clientOperation.httpOperation} />
@@ -68,7 +68,7 @@ export function ClientClass(props: ClientClassProps) {
68
68
  <ay.For each={operations} hardline semicolon>
69
69
  {(op) => {
70
70
  const parameters = getOperationParameters(op.httpOperation);
71
- const args = Object.keys(parameters).map((p) => p);
71
+ const args = parameters.flatMap((p) => p.refkey);
72
72
 
73
73
  return (
74
74
  <ClassMethod
@@ -148,14 +148,11 @@ function ClientConstructor(props: ClientConstructorProps) {
148
148
  );
149
149
  }
150
150
 
151
- function calculateSubClientArgs(
152
- subClient: cl.Client,
153
- parentParams: Record<string, ts.ParameterDescriptor>,
154
- ) {
155
- const subClientParams = buildClientParameters(subClient);
156
- return Object.entries(parentParams)
157
- .filter(([name]) => Object.keys(subClientParams).includes(name))
158
- .map(([_, p]) => p.refkey);
151
+ function calculateSubClientArgs(subClient: cl.Client, parentParams: ts.ParameterDescriptor[]) {
152
+ const subClientParams = buildClientParameters(subClient).map((p) => p.name);
153
+ return parentParams
154
+ .filter(({ name }) => subClientParams.includes(name))
155
+ .flatMap((p) => (p.refkey ? p.refkey : []));
159
156
  }
160
157
 
161
158
  export interface NewClientExpressionProps {
@@ -2,16 +2,21 @@ import { createPackage } from "@alloy-js/typescript";
2
2
 
3
3
  export const httpRuntimeTemplateLib = createPackage({
4
4
  name: "@typespec/ts-http-runtime",
5
- version: "0.1.0",
5
+ version: "0.2.1",
6
6
  descriptor: {
7
7
  ".": {
8
8
  named: [
9
9
  "Client",
10
10
  "ClientOptions",
11
11
  "getClient",
12
- "KeyCredential",
13
- "TokenCredential",
14
- "isKeyCredential",
12
+ "ApiKeyCredential",
13
+ "BasicCredential",
14
+ "BearerTokenCredential",
15
+ "OAuth2TokenCredential",
16
+ "AuthorizationCodeFlow",
17
+ "ClientCredentialsFlow",
18
+ "ImplicitFlow",
19
+ "PasswordFlow",
15
20
  "PathUncheckedResponse",
16
21
  "PipelineRequest",
17
22
  "HttpResponse",
@@ -41,7 +41,12 @@ HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
41
41
  return (
42
42
  <EncodingProvider defaults={{ bytes: "base64", datetime: "rfc7231" }}>
43
43
  <ts.ObjectProperty name="headers">
44
- <HttpRequestParametersExpression parameters={headers} optionsParameter={optionsParam} />,
44
+ <HttpRequestParametersExpression
45
+ parameters={headers}
46
+ optionsParameter={optionsParam}
47
+ httpOperation={httpOperation}
48
+ />
49
+ ,
45
50
  </ts.ObjectProperty>
46
51
  </EncodingProvider>
47
52
  );
@@ -1,10 +1,11 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { useTransformNamePolicy } from "@typespec/emitter-framework";
4
- import { HttpProperty } from "@typespec/http";
5
- import { getDefaultValue } from "../utils/parameters.jsx";
4
+ import { HttpOperation, HttpProperty } from "@typespec/http";
5
+ import { getDefaultValue, hasDefaultValue } from "../utils/parameters.jsx";
6
6
  import { JsonTransform } from "./transforms/json/json-transform.jsx";
7
7
  export interface HttpRequestParametersExpressionProps {
8
+ httpOperation: HttpOperation;
8
9
  optionsParameter: ay.Children;
9
10
  parameters?: HttpProperty[];
10
11
  children?: ay.Children;
@@ -28,33 +29,40 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
28
29
  const members = (
29
30
  <ay.For each={props.parameters} line comma>
30
31
  {(httpProperty) => {
31
- const parameter = httpProperty.property;
32
-
33
32
  const defaultValue = getDefaultValue(httpProperty);
34
- const paramItemRef: ay.Children = transformNamer.getApplicationName(parameter);
35
-
36
- const paramRef = ay.code`${optionsParamRef}?.${paramItemRef}`;
33
+ const propertyExpression = buildMemberChainExpression(
34
+ props.httpOperation,
35
+ httpProperty,
36
+ optionsParamRef,
37
+ );
38
+ const transportParamName = transformNamer.getTransportName(httpProperty.property);
37
39
 
38
40
  if (defaultValue) {
39
- const defaultAssignment = defaultValue ? ` ?? ${defaultValue}` : "";
40
- const headerValue = (
41
+ const paramValue = (
41
42
  <>
42
- {paramRef}
43
- {defaultAssignment}
43
+ {propertyExpression.fullExpression}
44
+ {` ?? ${defaultValue}`}
44
45
  </>
45
46
  );
46
- const name = transformNamer.getTransportName(parameter);
47
- const paramAssignment = <ts.ObjectProperty name={`"${name}"`} value={headerValue} />;
48
- return paramAssignment;
47
+ return (
48
+ <ay.NamePolicyContext.Provider value={{ getName: (n) => n }}>
49
+ <ts.ObjectProperty name={transportParamName} value={paramValue} />
50
+ </ay.NamePolicyContext.Provider>
51
+ );
49
52
  }
50
53
 
51
- const itemRef: ay.Children = parameter.optional ? ay.code`${optionsParamRef}?` : null;
52
- if (parameter.optional) {
54
+ if (propertyExpression.isNullish) {
53
55
  return ay.code`
54
- ...(${paramRef} && {${(<JsonTransform itemRef={itemRef} type={parameter} target="transport" />)}})
56
+ ...(${propertyExpression.fullExpression} && {${(<JsonTransform itemRef={propertyExpression.leadingExpression} type={httpProperty.property} target="transport" />)}})
55
57
  `;
56
58
  } else {
57
- return <JsonTransform itemRef={itemRef} type={parameter} target="transport" />;
59
+ return (
60
+ <JsonTransform
61
+ itemRef={propertyExpression.leadingExpression}
62
+ type={httpProperty.property}
63
+ target="transport"
64
+ />
65
+ );
58
66
  }
59
67
  }}
60
68
  </ay.For>
@@ -64,3 +72,119 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr
64
72
 
65
73
  return <ts.ObjectExpression>{parameters}</ts.ObjectExpression>;
66
74
  }
75
+
76
+ interface MemberChainExpression {
77
+ propertyName: string;
78
+ isNullish: boolean;
79
+ fullExpression: ay.Children;
80
+ leadingExpression?: ay.Children;
81
+ }
82
+
83
+ /**
84
+ * Builds the member chain expression for potentially nested HTTP parameters.
85
+ * This logic will be simplified and made more robust once a couple of changes land in Alloy.
86
+ * - Support refkeys on interface members
87
+ * - Support for conditional chaining on ts.MemberChainExpression
88
+ * - Eventually we'll have an API like:
89
+ * @example
90
+ * ```tsx
91
+ * <InstancePropertyExpression
92
+ * instance={refkey(parameter)}
93
+ * staticMember={refkey(property)}
94
+ * />
95
+ * ```
96
+ * @param httpOperation - The HttpOperation containing parameters.
97
+ * @param httpProperty - The current HttpProperty to build an access path for.
98
+ * @param optionsParamRef - Reference to the user's main options parameter.
99
+ * @returns The full nested expression, leading expression, nullish flag, and final property name.
100
+ */
101
+ function buildMemberChainExpression(
102
+ httpOperation: HttpOperation,
103
+ httpProperty: HttpProperty,
104
+ optionsParamRef?: ay.Children,
105
+ ): MemberChainExpression {
106
+ const segments: ay.Children[] = [];
107
+ let isNullish = httpProperty.property.optional === true;
108
+ const namePolicy = ay.useNamePolicy();
109
+ const propertyApplicationName = namePolicy.getName(httpProperty.property.name, "property");
110
+
111
+ // If the property is at the top level, return early
112
+ if (httpProperty.path.length === 1) {
113
+ if (httpProperty.property.optional || hasDefaultValue(httpProperty)) {
114
+ return {
115
+ propertyName: propertyApplicationName,
116
+ isNullish,
117
+ fullExpression: ay.code`${optionsParamRef}?.${propertyApplicationName}`,
118
+ leadingExpression: ay.code`${optionsParamRef}`,
119
+ };
120
+ }
121
+ return {
122
+ propertyName: propertyApplicationName,
123
+ isNullish,
124
+ fullExpression: propertyApplicationName,
125
+ };
126
+ }
127
+
128
+ // Build access segments for nested properties.
129
+ let currentPath = httpProperty.path.slice(0, -1);
130
+ while (currentPath.length > 0) {
131
+ const parentProperty = findHttpPropertyByPath(httpOperation, currentPath);
132
+ if (!parentProperty) {
133
+ break;
134
+ }
135
+
136
+ // Use optional chaining if the parent is optional.
137
+ const joiner = parentProperty.property.optional ? "?." : ".";
138
+ if (parentProperty.property.optional) {
139
+ isNullish = true;
140
+ }
141
+
142
+ const parentName = namePolicy.getName(parentProperty.property.name, "property");
143
+
144
+ // Unshift the joiner first
145
+ segments.unshift(joiner);
146
+
147
+ // Use direct property access if possible.
148
+ if (isValidIdentifier(parentName)) {
149
+ segments.unshift(ay.code`${parentName}`);
150
+ } else {
151
+ // For non-valid identifiers, use bracket notation.
152
+ segments.unshift(`[${JSON.stringify(parentName)}]`);
153
+ }
154
+
155
+ // Remove the last element to move one level up.
156
+ currentPath = currentPath.slice(0, -1);
157
+ }
158
+
159
+ const fullExpression = (
160
+ <>
161
+ <ay.List children={segments} />
162
+ {propertyApplicationName}
163
+ </>
164
+ );
165
+ const leadingExpression = <ay.List children={segments.slice(0, -1)} />;
166
+
167
+ return {
168
+ propertyName: propertyApplicationName,
169
+ isNullish,
170
+ fullExpression,
171
+ leadingExpression,
172
+ };
173
+ }
174
+
175
+ function isValidIdentifier(name: string): boolean {
176
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
177
+ }
178
+
179
+ function findHttpPropertyByPath(
180
+ httpOperation: HttpOperation,
181
+ path: (string | number)[],
182
+ ): HttpProperty | undefined {
183
+ for (const property of httpOperation.parameters.properties) {
184
+ // Check if the property path matches the given path
185
+ if (JSON.stringify(property.path) === JSON.stringify(path)) {
186
+ return property;
187
+ }
188
+ }
189
+ return undefined;
190
+ }
@@ -57,6 +57,7 @@ HttpRequest.Url = function HttpUrlDeclaration(props: HttpUrlProps) {
57
57
  {uriTemplateLib.parse}({JSON.stringify(urlTemplate)}).expand(
58
58
  {
59
59
  <HttpRequestParametersExpression
60
+ httpOperation={httpOperation}
60
61
  optionsParameter={optionsParameter!}
61
62
  parameters={urlParameters}
62
63
  />
@@ -14,30 +14,31 @@ export function getOperationOptionsParameterRefkey(operation: HttpOperation) {
14
14
  return ay.refkey(operation, "operation-options-parameter");
15
15
  }
16
16
 
17
- export function getOperationParameters(
18
- operation: HttpOperation,
19
- ): Record<string, ts.ParameterDescriptor | ay.Children> {
17
+ export function getOperationParameters(operation: HttpOperation): ts.ParameterDescriptor[] {
20
18
  const transformNamer = useTransformNamePolicy();
21
19
  const requiredParameters = operation.parameters.properties
22
20
  .filter((p) => !p.property.optional && !hasDefaultValue(p))
23
21
  .filter((p) => p.path.length === 1);
24
22
 
25
- const parameters: Record<string, ts.ParameterDescriptor | ay.Children> = {};
23
+ const parameters: ts.ParameterDescriptor[] = [];
26
24
 
27
25
  for (const parameter of requiredParameters) {
26
+ const name = transformNamer.getApplicationName(parameter.property);
28
27
  const parameterDescriptor: ts.ParameterDescriptor = {
28
+ name,
29
29
  refkey: ay.refkey(parameter.property, "operation-parameter"),
30
30
  type: <ef.TypeExpression type={parameter.property.type} />,
31
31
  };
32
- const name = transformNamer.getApplicationName(parameter.property);
33
- parameters[name] = parameterDescriptor;
32
+
33
+ parameters.push(parameterDescriptor);
34
34
  }
35
35
 
36
- parameters["options"] = {
36
+ parameters.push({
37
+ name: "options",
37
38
  refkey: getOperationOptionsParameterRefkey(operation),
38
39
  type: getOperationOptionsTypeRefkey(operation),
39
40
  optional: true,
40
- };
41
+ });
41
42
 
42
43
  return parameters;
43
44
  }
@@ -14,10 +14,10 @@ export function EncodeUint8Array(): ay.Children {
14
14
  export
15
15
  refkey={refkey}
16
16
  name="encodeUint8Array"
17
- parameters={{
18
- value: { type: "Uint8Array | undefined | null", refkey: valueRef },
19
- encoding: { type: "BufferEncoding", refkey: encodingRef },
20
- }}
17
+ parameters={[
18
+ { name: "value", type: "Uint8Array | undefined | null", refkey: valueRef },
19
+ { name: "encoding", type: "BufferEncoding", refkey: encodingRef },
20
+ ]}
21
21
  returnType="string | undefined"
22
22
  >
23
23
  {ay.code`
@@ -40,7 +40,7 @@ export function DecodeBase64(): ay.Children {
40
40
  <ts.FunctionDeclaration
41
41
  export
42
42
  name="decodeBase64"
43
- parameters={{ value: { type: "string", refkey: valueRef } }}
43
+ parameters={[{ name: "value", type: "string", refkey: valueRef }]}
44
44
  returnType="Uint8Array | undefined"
45
45
  refkey={refkey}
46
46
  >
@@ -66,15 +66,15 @@ export function MultipartHelpers(props: MultipartHelpersProps) {
66
66
  );
67
67
  }
68
68
 
69
- function getCreateFilePartParameters() {
70
- return {
71
- partName: "string",
72
- fileInput: "any",
73
- defaultContentType: {
69
+ function getCreateFilePartParameters(): ts.ParameterDescriptor[] {
70
+ return [
71
+ { name: "partName", type: "string" },
72
+ { name: "fileInput", type: "any" },
73
+ {
74
+ name: "defaultContentType",
74
75
  optional: true,
75
- key: "defaultContentType",
76
76
  refkey: ay.refkey(),
77
77
  type: "string",
78
78
  },
79
- };
79
+ ];
80
80
  }
@@ -47,7 +47,10 @@ export function RestError() {
47
47
  <ay.List hardline>
48
48
  <ts.ClassMethod
49
49
  name="constructor"
50
- parameters={{ message: "string", response: httpRuntimeTemplateLib.HttpResponse }}
50
+ parameters={[
51
+ { name: "message", type: "string" },
52
+ { name: "response", type: httpRuntimeTemplateLib.HttpResponse },
53
+ ]}
51
54
  returnType={null}
52
55
  refkey={constructorRefkey}
53
56
  >
@@ -68,7 +71,7 @@ export function RestError() {
68
71
  <ts.ClassMethod
69
72
  static
70
73
  name="fromHttpResponse"
71
- parameters={{ response: httpRuntimeTemplateLib.HttpResponse }}
74
+ parameters={[{ name: "response", type: httpRuntimeTemplateLib.HttpResponse }]}
72
75
  returnType={getRestErrorRefkey()}
73
76
  refkey={fromHttpResponseRefkey}
74
77
  >
@@ -85,7 +88,7 @@ export function RestError() {
85
88
  <ts.FunctionDeclaration
86
89
  export
87
90
  name="createRestError"
88
- parameters={{ response: httpRuntimeTemplateLib.HttpResponse }}
91
+ parameters={[{ name: "response", type: httpRuntimeTemplateLib.HttpResponse }]}
89
92
  returnType={getRestErrorRefkey()}
90
93
  refkey={getCreateRestErrorRefkey()}
91
94
  >
@@ -66,9 +66,9 @@ export function JsonArrayTransformDeclaration(props: JsonArrayTransformDeclarati
66
66
  const inputType = props.target === "transport" ? <>{itemType} | null</> : "any";
67
67
  const inputRef = ay.refkey();
68
68
 
69
- const parameters: Record<string, ts.ParameterDescriptor> = {
70
- items_: { type: inputType, refkey: inputRef, optional: true },
71
- };
69
+ const parameters: ts.ParameterDescriptor[] = [
70
+ { name: "items_", type: inputType, refkey: inputRef, optional: true },
71
+ ];
72
72
 
73
73
  const declarationRefkey = getJsonArrayTransformRefkey(props.type, props.target);
74
74
  return (
@@ -35,5 +35,17 @@ export function JsonModelPropertyTransform(props: JsonModelPropertyTransformProp
35
35
  );
36
36
  }
37
37
 
38
- return <ts.ObjectProperty name={JSON.stringify(targetName)} value={propertyValue} />;
38
+ if (props.target === "transport") {
39
+ return (
40
+ <ay.NamePolicyContext.Provider value={{ getName: (n) => n }}>
41
+ <ts.ObjectProperty name={targetName} value={propertyValue} />
42
+ </ay.NamePolicyContext.Provider>
43
+ );
44
+ }
45
+
46
+ return (
47
+ <>
48
+ <ts.ObjectProperty name={JSON.stringify(targetName)} value={propertyValue} />
49
+ </>
50
+ );
39
51
  }
@@ -79,10 +79,10 @@ export function JsonModelTransformDeclaration(
79
79
  const inputType = props.target === "transport" ? <>{ay.refkey(props.type)} | null</> : "any";
80
80
  const inputRef = ay.refkey();
81
81
 
82
- const parameters: Record<string, ts.ParameterDescriptor> = {
82
+ const parameters: ts.ParameterDescriptor[] = [
83
83
  // Make the input optional to make the transform more robust and check against null and undefined
84
- input_: { type: inputType, refkey: inputRef, optional: true },
85
- };
84
+ { name: "input_", type: inputType, refkey: inputRef, optional: true },
85
+ ];
86
86
 
87
87
  const spread = $.model.getSpreadType(props.type);
88
88
  const hasAdditionalProperties = spread && $.model.is(spread) && $.record.is(spread);
@@ -67,9 +67,9 @@ export function JsonRecordTransformDeclaration(props: JsonRecordTransformDeclara
67
67
  const inputType = props.target === "transport" ? <>{itemType} | null</> : "any";
68
68
  const inputRef = ay.refkey();
69
69
 
70
- const parameters: Record<string, ts.ParameterDescriptor> = {
71
- items_: { type: inputType, refkey: inputRef, optional: true },
72
- };
70
+ const parameters: ts.ParameterDescriptor[] = [
71
+ { name: "items_", type: inputType, refkey: inputRef, optional: true },
72
+ ];
73
73
 
74
74
  const declarationRefkey = getJsonRecordTransformRefkey(props.type, props.target);
75
75
  return (