| 260 | } |
| 261 | |
| 262 | class JavaCodeGen implements APIRequestCodegen { |
| 263 | generatePlaywrightRequestCall(request: har.Request, body: string | undefined): string { |
| 264 | const url = new URL(request.url); |
| 265 | const params = [`"${url.origin}${url.pathname}"`]; |
| 266 | |
| 267 | const options: string[] = []; |
| 268 | |
| 269 | let method = request.method.toLowerCase(); |
| 270 | if (!['delete', 'get', 'head', 'post', 'put', 'patch'].includes(method)) { |
| 271 | options.push(`setMethod("${method}")`); |
| 272 | method = 'fetch'; |
| 273 | } |
| 274 | |
| 275 | for (const [key, value] of url.searchParams) |
| 276 | options.push(`setQueryParam(${this.stringLiteral(key)}, ${this.stringLiteral(value)})`); |
| 277 | if (body) |
| 278 | options.push(`setData(${this.stringLiteral(body)})`); |
| 279 | for (const header of request.headers) |
| 280 | options.push(`setHeader(${this.stringLiteral(header.name)}, ${this.stringLiteral(header.value)})`); |
| 281 | |
| 282 | if (options.length > 0) |
| 283 | params.push(`RequestOptions.create()\n .${options.join('\n .')}\n`); |
| 284 | return `request.${method}(${params.join(', ')});`; |
| 285 | } |
| 286 | |
| 287 | private stringLiteral(v: string): string { |
| 288 | return JSON.stringify(v); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | export function getAPIRequestCodeGen(language: Language): APIRequestCodegen { |
| 293 | if (language === 'javascript') |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…