Skip to content

Commit 08c7bde

Browse files
eruniondimitropoulosfilfreireDavis Martinirajtaghlidi
authored
feat: upgrading us to upstream (#108)
* Total Overhaul (but with all the same fixtures!) (#248) see Kong#248 and the commits therein for more context. Essentially: - the original client fixtures were unchanged, which hopefully means the - all source code is now in strict mode TypeScript - tests are now all in jest - the file structure was reorganized so that everything for a particular client is in one place - the CLI is updated and now using yargs - all dependencies were updated and some (i.e. `format.utils`) were able to be removed entirely - more work left to do (including CI with GitHub Actions, for example), but this is a start * fix: case where if `postData.params` is missing some targets crash (#258) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: compatibility issues on node 14 with `Object.hasOwn()` (#252) * fix: typo in the httpie `style` option not being correctly applied (#254) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: axios targets not sending `x-www-form-urlencoded` properly (#255) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * feat: addition of a PHP target for Guzzle (#253) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * Add Github Build Workflow (#250) (#251) * Add Github Build Workflow (#250) * Edit job name * Replace install with ci on GH workflow * Add matrix with major node versions (14, 16, 18) * Disable fail-fast * Remove node v14 from build GH action * feat: native upload support in python `requests` snippets (#259) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: `multipart/form-data` header issues with node/js fetch targets (#257) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: headers not being properly applied to R httr snippets (#263) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * Fix build workflow dispatch rules (#265) * Chore: Remove travis links (#266) * Remove travis links * Update README.md Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: issue where query strings in R wouldn't be properly concatenated (#269) * fix: issue where query strings in R wouldn't be properly concatenated * adds (and respects) indent options to httr, plus double looping fix now, indent is respected, and also avoiding running Object.keys twice per run since we can just run it once with .entries Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * add header namesspace to prevent header errors (#247) * add header namesspace to prevent header errors * update fixtures Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: stop implicitly coercing warning in Swift snippet generator (#195) * swift/nsurlsession adds `as Any` to print for error * adds OVERWRITE_EVERYTHING to ease fixture snapshot resetting * updates fixtures Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: clj-http handling of literal null JSON bodies (#283) Co-authored-by: Sergey Zakharchenko <szakharchenko@digital-loggers.com> * fix: prevent crash in Swift/Objc with checking length of input body post params (#192) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: cUrl target should encode x-www-form-urlencoded post data params (#198) Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> * fix: linting issues * fix: reverting package-lock changes * chore: removing unused fixtures * fix: removing unnecessary typing Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> Co-authored-by: Filipe Freire <livrofubia@gmail.com> Co-authored-by: Davis Martin <davis.martin@procore.com> Co-authored-by: iraj taghlidi <785830+irajtaghlidi@users.noreply.github.com> Co-authored-by: Sergey Zakharchenko <szakharchenko@digital-loggers.com> Co-authored-by: Julien Giovaresco <dev@giovaresco.fr>
1 parent df6d56d commit 08c7bde

File tree

79 files changed

+249
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+249
-158
lines changed

src/fixtures/runCustomFixtures.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { HTTPSnippetOptions, Request } from '..';
44
import type { ClientId, TargetId } from '../targets/targets';
55

6+
import { writeFileSync } from 'fs';
67
import { readFile } from 'fs/promises';
78
import path from 'path';
89

@@ -24,15 +25,18 @@ export interface CustomFixture {
2425
export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture) => {
2526
describe(`custom fixtures for ${targetId}:${clientId}`, () => {
2627
tests.forEach(({ it: title, expected: fixtureFile, options, input: request }) => {
28+
const opts: HTTPSnippetOptions = {};
29+
if (options.harIsAlreadyEncoded) {
30+
opts.harIsAlreadyEncoded = options.harIsAlreadyEncoded;
31+
}
32+
33+
const result = new HTTPSnippet(request, opts).convert(targetId, clientId, options);
34+
const filePath = path.join(__dirname, '..', 'targets', targetId, clientId, 'fixtures', fixtureFile);
35+
if (process.env.OVERWRITE_EVERYTHING) {
36+
writeFileSync(filePath, String(result));
37+
}
38+
2739
it(title, async () => {
28-
const opts: HTTPSnippetOptions = {};
29-
// eslint-disable-next-line jest/no-if
30-
if (options.harIsAlreadyEncoded) {
31-
opts.harIsAlreadyEncoded = options.harIsAlreadyEncoded;
32-
}
33-
34-
const result = new HTTPSnippet(request, opts).convert(targetId, clientId, options);
35-
const filePath = path.join(__dirname, '..', 'targets', targetId, clientId, 'fixtures', fixtureFile);
3640
const buffer = await readFile(filePath);
3741
const fixture = String(buffer);
3842

src/helpers/code-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class CodeBuilder {
3232
*/
3333
constructor({ indent, join }: CodeBuilderOptions = {}) {
3434
this.indentationCharacter = indent || DEFAULT_INDENTATION_CHARACTER;
35-
this.lineJoin = join || DEFAULT_LINE_JOIN;
35+
this.lineJoin = join ?? DEFAULT_LINE_JOIN;
3636
}
3737

3838
/**

src/targets/clojure/clj_http/client.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
import type { Client } from '../../targets';
12-
import type { Param } from 'har-format';
1312
import { CodeBuilder } from '../../../helpers/code-builder';
1413
import { getHeader, getHeaderName } from '../../../helpers/headers';
1514

@@ -33,17 +32,32 @@ class File {
3332
toString = () => `(clojure.java.io/file "${this.path}")`;
3433
}
3534

36-
const jsType = (x?: any) => (typeof x !== 'undefined' ? x.constructor.name.toLowerCase() : null);
35+
const jsType = (input?: any) => {
36+
if (input === undefined) {
37+
return null;
38+
}
39+
40+
if (input === null) {
41+
return 'null';
42+
}
3743

38-
const objEmpty = (x?: any) => (jsType(x) === 'object' ? Object.keys(x).length === 0 : false);
44+
return input.constructor.name.toLowerCase();
45+
};
46+
47+
const objEmpty = (input?: any) => {
48+
if (jsType(input) === 'object') {
49+
return Object.keys(input).length === 0;
50+
}
51+
return false;
52+
};
3953

40-
const filterEmpty = (m: Record<string, any>) => {
41-
Object.keys(m)
42-
.filter(x => objEmpty(m[x]))
54+
const filterEmpty = (input: Record<string, any>) => {
55+
Object.keys(input)
56+
.filter(x => objEmpty(input[x]))
4357
.forEach(x => {
44-
delete m[x];
58+
delete input[x];
4559
});
46-
return m;
60+
return input;
4761
};
4862

4963
const padBlock = (padSize: number, input: string) => {
@@ -146,7 +160,7 @@ export const clj_http: Client = {
146160

147161
case 'multipart/form-data': {
148162
if (postData.params) {
149-
params.multipart = postData.params.map((param: Param) => {
163+
params.multipart = postData.params.map(param => {
150164
if (param.fileName && !param.value) {
151165
return {
152166
name: param.name,
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<MISSING>
1+
(require '[clj-http.client :as client])
2+
3+
(client/post "https://httpbin.org/anything" {:content-type :json
4+
:form-params {:foo nil}})

src/targets/csharp/httpclient/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Request } from '../../..';
22
import type { Client } from '../../targets';
3-
import type { Param } from 'har-format';
43
import { CodeBuilder } from '../../../helpers/code-builder';
54
import { getHeader } from '../../../helpers/headers';
65

@@ -49,6 +48,7 @@ export const httpclient: Client = {
4948

5049
const { push, join } = new CodeBuilder({ indent: opts.indent });
5150

51+
push('using System.Net.Http.Headers;');
5252
let clienthandler = '';
5353
const cookies = Boolean(allHeaders.cookie);
5454
const decompressionMethods = getDecompressionMethods(allHeaders);
@@ -113,7 +113,7 @@ export const httpclient: Client = {
113113
case 'application/x-www-form-urlencoded':
114114
push('Content = new FormUrlEncodedContent(new Dictionary<string, string>', 1);
115115
push('{', 1);
116-
postData.params?.forEach((param: Param) => {
116+
postData.params?.forEach(param => {
117117
push(`{ "${param.name}", "${param.value}" },`, 2);
118118
});
119119
push('}),', 1);
@@ -122,7 +122,7 @@ export const httpclient: Client = {
122122
case 'multipart/form-data':
123123
push('Content = new MultipartFormDataContent', 1);
124124
push('{', 1);
125-
postData.params?.forEach((param: Param) => {
125+
postData.params?.forEach(param => {
126126
push(`new StringContent(${JSON.stringify(param.value || '')})`, 2);
127127
push('{', 2);
128128
push('Headers =', 3);

src/targets/csharp/httpclient/fixtures/application-form-encoded.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net.Http.Headers;
12
var client = new HttpClient();
23
var request = new HttpRequestMessage
34
{

src/targets/csharp/httpclient/fixtures/application-json.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net.Http.Headers;
12
var client = new HttpClient();
23
var request = new HttpRequestMessage
34
{

src/targets/csharp/httpclient/fixtures/cookies.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net.Http.Headers;
12
var clientHandler = new HttpClientHandler
23
{
34
UseCookies = false,

src/targets/csharp/httpclient/fixtures/custom-method.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net.Http.Headers;
12
var client = new HttpClient();
23
var request = new HttpRequestMessage
34
{

src/targets/csharp/httpclient/fixtures/full.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net.Http.Headers;
12
var clientHandler = new HttpClientHandler
23
{
34
UseCookies = false,

0 commit comments

Comments
 (0)