(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, fields: Map<string, Map<string, GoExtractedField>>, unionInfos: Map<string, GoDiscriminatedUnionInfo>, groupExperimental = false, isWrapper = false, groupDeprecated = false)
| 4125 | } |
| 4126 | |
| 4127 | function emitMethod(lines: string[], receiver: string, name: string, method: RpcMethod, isSession: boolean, resolveType: (name: string) => string, fields: Map<string, Map<string, GoExtractedField>>, unionInfos: Map<string, GoDiscriminatedUnionInfo>, groupExperimental = false, isWrapper = false, groupDeprecated = false): void { |
| 4128 | const methodName = toPascalCase(name); |
| 4129 | const resultSchema = getMethodResultSchema(method); |
| 4130 | const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined; |
| 4131 | const resultType = nullableInner |
| 4132 | ? resolveType(goNullableResultTypeName(method, nullableInner)) |
| 4133 | : resolveType(goResultTypeName(method)); |
| 4134 | const resultUnion = unionInfos.get(resultType); |
| 4135 | const returnType = resultUnion ? resultType : `*${resultType}`; |
| 4136 | |
| 4137 | const effectiveParams = getMethodParamsSchema(method); |
| 4138 | const paramProps = effectiveParams?.properties || {}; |
| 4139 | const requiredParams = new Set(effectiveParams?.required || []); |
| 4140 | const nonSessionParams = Object.keys(paramProps) |
| 4141 | .filter((k) => k !== "sessionId") |
| 4142 | .sort((left, right) => compareGoFieldNames(toGoFieldName(left), toGoFieldName(right))); |
| 4143 | const hasParams = isSession ? nonSessionParams.length > 0 : hasSchemaPayload(effectiveParams); |
| 4144 | const paramsType = hasParams ? resolveType(goParamsTypeName(method)) : ""; |
| 4145 | const hasRequiredNonSessionParams = nonSessionParams.some((name) => requiredParams.has(name)); |
| 4146 | const paramsAreOptional = hasParams && !!method.params && !!getNullableInner(method.params) && !hasRequiredNonSessionParams; |
| 4147 | |
| 4148 | // For wrapper-level methods, access fields through a.common; for service type aliases, use a directly |
| 4149 | const clientRef = isWrapper ? "a.common.client" : "a.client"; |
| 4150 | const sessionIDRef = isWrapper ? "a.common.sessionID" : "a.sessionID"; |
| 4151 | |
| 4152 | pushGoRpcMethodComment( |
| 4153 | lines, |
| 4154 | methodName, |
| 4155 | method, |
| 4156 | resultSchema, |
| 4157 | hasParams ? goRpcParamsDescription(method, effectiveParams) : undefined |
| 4158 | ); |
| 4159 | if (method.deprecated && !groupDeprecated) { |
| 4160 | pushGoComment(lines, `Deprecated: ${methodName} is deprecated and will be removed in a future version.`); |
| 4161 | } |
| 4162 | if (method.stability === "experimental" && !groupExperimental) { |
| 4163 | pushGoExperimentalMethodComment(lines, methodName); |
| 4164 | } |
| 4165 | if (method.visibility === "internal") { |
| 4166 | pushGoComment(lines, `Internal: ${methodName} is part of the SDK's internal handshake/plumbing; external callers should not use it.`); |
| 4167 | } |
| 4168 | const sig = hasParams |
| 4169 | ? `func (a *${receiver}) ${methodName}(ctx context.Context, params ${paramsAreOptional ? "..." : ""}*${paramsType}) (${returnType}, error)` |
| 4170 | : `func (a *${receiver}) ${methodName}(ctx context.Context) (${returnType}, error)`; |
| 4171 | |
| 4172 | lines.push(sig + ` {`); |
| 4173 | const paramsRef = paramsAreOptional ? "requestParams" : "params"; |
| 4174 | if (paramsAreOptional) { |
| 4175 | lines.push(`\tvar requestParams *${paramsType}`); |
| 4176 | lines.push(`\tif len(params) > 0 {`); |
| 4177 | lines.push(`\t\trequestParams = params[0]`); |
| 4178 | lines.push(`\t}`); |
| 4179 | } |
| 4180 | |
| 4181 | if (isSession) { |
| 4182 | lines.push(`\treq := map[string]any{"sessionId": ${sessionIDRef}}`); |
| 4183 | if (hasParams) { |
| 4184 | lines.push(`\tif ${paramsRef} != nil {`); |
no test coverage detected
searching dependent graphs…