Skip to content

Commit 21eb0b8

Browse files
authored
Merge branch 'postmanlabs:develop' into fix/golang-ioutils
2 parents f9bc785 + c9c7244 commit 21eb0b8

File tree

60 files changed

+837
-1343
lines changed

Some content is hidden

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

60 files changed

+837
-1343
lines changed

CHANGELOG.md

+22-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22

33
## [Unreleased]
44

5-
## [v1.10.1] - 2024-05-06
5+
## [v1.12.0] - 2024-07-22
6+
7+
### Chore
68

7-
## [v1.10.0] - 2024-05-02
9+
- Updated postman-collection sdk to version 4.4.0 in missing codegens.
10+
11+
### Fixed
12+
13+
- Fix typo in Content-Header for audio/midi files in codegens.
14+
- Added support for NTLM auth support in cURL codegen.
15+
16+
## [v1.11.0] - 2024-07-10
17+
18+
### Chore
19+
20+
- Updated postman-collection to v4.4.0.
21+
22+
## [v1.10.1] - 2024-05-06
823

924
### Fixed
1025

@@ -155,11 +170,13 @@ v1.0.0 (May 29, 2020)
155170
- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest
156171
- Fix snippet generation for powershell and jquery, where form data params had no type field
157172

158-
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.1...HEAD
173+
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.12.0...HEAD
174+
175+
[v1.12.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.11.0...v1.12.0
159176

160-
[v1.10.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.0...v1.10.1
177+
[v1.11.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.1...v1.11.0
161178

162-
[v1.10.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.9.0...v1.10.0
179+
[v1.10.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.0...v1.9.0
163180

164181
[v1.9.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.8.0...v1.9.0
165182

codegens/csharp-httpclient/test/unit/convert.test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var expect = require('chai').expect,
2-
sdk = require('postman-collection'),
2+
{ Request } = require('postman-collection/lib/collection/request'),
33
convert = require('../../lib/index').convert,
44
mainCollection = require('./fixtures/testcollection/collection.json'),
55
testCollection = require('./fixtures/testcollection/collectionForEdge.json'),
@@ -13,7 +13,7 @@ describe('csharp httpclient function', function () {
1313

1414
describe('csharp-httpclient convert function', function () {
1515
it('should return expected snippet', function () {
16-
var request = new sdk.Request(mainCollection.item[10].request),
16+
var request = new Request(mainCollection.item[10].request),
1717
options = {
1818
indentCount: 1,
1919
indentType: 'Tab'
@@ -30,7 +30,7 @@ describe('csharp httpclient function', function () {
3030
});
3131

3232
describe('convert function', function () {
33-
var request = new sdk.Request(testCollection.item[0].request),
33+
var request = new Request(testCollection.item[0].request),
3434
snippetArray,
3535
options = {
3636
includeBoilerplate: true,
@@ -89,7 +89,7 @@ describe('csharp httpclient function', function () {
8989
});
9090

9191
it('should create custom HttpMethod when method is non-standard', function () {
92-
var request = new sdk.Request({
92+
var request = new Request({
9393
'method': 'NOTNORMAL',
9494
'header': [],
9595
'url': {
@@ -116,7 +116,7 @@ describe('csharp httpclient function', function () {
116116
});
117117

118118
it('should add fake body when content type header added to empty body', function () {
119-
var request = new sdk.Request({
119+
var request = new Request({
120120
'method': 'DELETE',
121121
'body': {},
122122
'header': [
@@ -137,7 +137,7 @@ describe('csharp httpclient function', function () {
137137
});
138138

139139
// it('should only include one System.IO using with multiple files', function () {
140-
// var request = new sdk.Request({
140+
// var request = new Request({
141141
// 'method': 'POST',
142142
// 'header': [],
143143
// 'body': {
@@ -171,7 +171,7 @@ describe('csharp httpclient function', function () {
171171
// });
172172

173173
it('should include multiple form content when file has multiple sources', function () {
174-
var request = new sdk.Request({
174+
var request = new Request({
175175
'method': 'POST',
176176
'header': [],
177177
'body': {
@@ -201,7 +201,7 @@ describe('csharp httpclient function', function () {
201201
});
202202

203203
it('should include graphql body in the snippet', function () {
204-
var request = new sdk.Request({
204+
var request = new Request({
205205
'method': 'POST',
206206
'header': [],
207207
'body': {
@@ -236,7 +236,7 @@ describe('csharp httpclient function', function () {
236236
});
237237

238238
it('should add blank graphql variables when invalid', function () {
239-
var request = new sdk.Request({
239+
var request = new Request({
240240
'method': 'POST',
241241
'header': [],
242242
'body': {
@@ -271,7 +271,7 @@ describe('csharp httpclient function', function () {
271271
});
272272

273273
it('should not add multiport form content when disabled', function () {
274-
var request = new sdk.Request(mainCollection.item[15].request);
274+
var request = new Request(mainCollection.item[15].request);
275275
convert(request, {}, function (error, snippet) {
276276
if (error) {
277277
expect.fail(null, null, error);
@@ -288,7 +288,7 @@ describe('csharp httpclient function', function () {
288288
});
289289

290290
it('should run add content as string on raw request', function () {
291-
var request = new sdk.Request(mainCollection.item[12].request);
291+
var request = new Request(mainCollection.item[12].request);
292292
convert(request, {}, function (error, snippet) {
293293
if (error) {
294294
expect.fail(null, null, error);
@@ -303,7 +303,7 @@ describe('csharp httpclient function', function () {
303303
});
304304

305305
it('should add a file on file request', function () {
306-
var request = new sdk.Request({
306+
var request = new Request({
307307
'method': 'POST',
308308
'url': 'https://google.com',
309309
'header': [],
@@ -324,7 +324,7 @@ describe('csharp httpclient function', function () {
324324
});
325325

326326
it('should add all enabled headers to request', function () {
327-
var request = new sdk.Request({
327+
var request = new Request({
328328
'method': 'POST',
329329
'url': 'https://postman-echo.com/post',
330330
'header': [
@@ -360,7 +360,7 @@ describe('csharp httpclient function', function () {
360360
});
361361

362362
it('should skip disabled form url encoded values', function () {
363-
var request = new sdk.Request({
363+
var request = new Request({
364364
'method': 'POST',
365365
'header': [],
366366
'url': 'https://postman-echo.com/post',
@@ -390,7 +390,7 @@ describe('csharp httpclient function', function () {
390390
});
391391

392392
it('should skip collection initialization when no urlencoded values are enabled', function () {
393-
var request = new sdk.Request({
393+
var request = new Request({
394394
'method': 'POST',
395395
'header': [],
396396
'url': 'https://postman-echo.com/post',
@@ -415,7 +415,7 @@ describe('csharp httpclient function', function () {
415415
});
416416

417417
it('should skip creating multipart form data content when all values are disabled', function () {
418-
var request = new sdk.Request({
418+
var request = new Request({
419419
'method': 'POST',
420420
'header': [],
421421
'url': 'https://postman-echo.com/post',

codegens/csharp-restsharp/test/unit/convert.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var expect = require('chai').expect,
2-
sdk = require('postman-collection'),
2+
{ Request } = require('postman-collection/lib/collection/request'),
33
convert = require('../../lib/index').convert,
44
mainCollection = require('./fixtures/testcollection/collection.json'),
55
testCollection = require('./fixtures/testcollection/collectionForEdge.json'),
@@ -13,7 +13,7 @@ describe('csharp restsharp function', function () {
1313

1414
describe('csharp-restsharp convert function', function () {
1515
it('should return expected snippet - Async', function () {
16-
var request = new sdk.Request(mainCollection.item[4].request),
16+
var request = new Request(mainCollection.item[4].request),
1717
options = {
1818
indentCount: 1,
1919
indentType: 'Tab',
@@ -31,7 +31,7 @@ describe('csharp restsharp function', function () {
3131
});
3232

3333
it('should return expected snippet json params', function () {
34-
var request = new sdk.Request(mainCollection.item[5].request),
34+
var request = new Request(mainCollection.item[5].request),
3535
options = {
3636
indentCount: 1,
3737
indentType: 'Tab',
@@ -50,7 +50,7 @@ describe('csharp restsharp function', function () {
5050
});
5151

5252
describe('convert function', function () {
53-
var request = new sdk.Request(testCollection.item[0].request),
53+
var request = new Request(testCollection.item[0].request),
5454
snippetArray,
5555
options = {
5656
includeBoilerplate: true,
@@ -108,7 +108,7 @@ describe('csharp restsharp function', function () {
108108
});
109109

110110
it('should trim header keys and not trim header values', function () {
111-
var request = new sdk.Request({
111+
var request = new Request({
112112
'method': 'GET',
113113
'header': [
114114
{
@@ -136,7 +136,7 @@ describe('csharp restsharp function', function () {
136136
});
137137

138138
it('should generate snippets for no files in form data', function () {
139-
var request = new sdk.Request({
139+
var request = new Request({
140140
'method': 'POST',
141141
'header': [],
142142
'body': {
@@ -188,7 +188,7 @@ describe('csharp restsharp function', function () {
188188
const sampleUA = 'Safari/605.1.15',
189189
expectValue = `UserAgent = "${sampleUA}",`;
190190

191-
var request = new sdk.Request({
191+
var request = new Request({
192192
'method': 'GET',
193193
'header': [
194194
{

codegens/curl/lib/index.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
var sanitize = require('./util').sanitize,
2-
sanitizeOptions = require('./util').sanitizeOptions,
3-
getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject,
4-
addFormParam = require('./util').addFormParam,
5-
form = require('./util').form,
6-
shouldAddHttpMethod = require('./util').shouldAddHttpMethod,
7-
_ = require('./lodash'),
8-
self;
1+
const {
2+
sanitize,
3+
sanitizeOptions,
4+
getUrlStringfromUrlObject,
5+
getNtlmAuthInfo,
6+
addFormParam,
7+
form,
8+
shouldAddHttpMethod
9+
} = require('./util'),
10+
_ = require('./lodash');
11+
12+
var self;
913

1014
self = module.exports = {
1115
convert: function (request, options, callback) {
@@ -16,7 +20,7 @@ self = module.exports = {
1620
options = sanitizeOptions(options, self.getOptions());
1721

1822
var indent, trim, headersData, body, redirect, timeout, multiLine,
19-
format, snippet, silent, url, quoteType;
23+
format, snippet, silent, url, quoteType, ntlmAuth;
2024

2125
redirect = options.followRedirect;
2226
timeout = options.requestTimeoutInSeconds;
@@ -26,9 +30,16 @@ self = module.exports = {
2630
silent = options.silent;
2731
quoteType = options.quoteType === 'single' ? '\'' : '"';
2832
url = getUrlStringfromUrlObject(request.url, quoteType);
33+
ntlmAuth = getNtlmAuthInfo(request.auth, quoteType, format);
2934

30-
snippet = silent ? `curl ${form('-s', format)}` : 'curl';
35+
snippet = 'curl';
3136

37+
if (ntlmAuth) {
38+
snippet += ntlmAuth;
39+
}
40+
if (silent) {
41+
snippet += ` ${form('-s', format)}`;
42+
}
3243
if (redirect) {
3344
snippet += ` ${form('-L', format)}`;
3445
}

codegens/curl/lib/util.js

+43-8
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,49 @@ var self = module.exports = {
144144
},
145145

146146
/**
147-
*
148-
* @param {*} urlObject The request sdk request.url object
149-
* @param {boolean} quoteType The user given quoteType
150-
* @returns {String} The final string after parsing all the parameters of the url including
151-
* protocol, auth, host, port, path, query, hash
152-
* This will be used because the url.toString() method returned the URL with non encoded query string
153-
* and hence a manual call is made to getQueryString() method with encode option set as true.
154-
*/
147+
* Generates args required for NTLM authentication to happen
148+
*
149+
* @param {*} auth - The request sdk request.auth object
150+
* @param {string} quoteType - user provided option to decide whether to use single or double quotes
151+
* @param {string} format - user provided option to decide whether to use long format or not
152+
* @returns {string} - The string to be added if NTLM auth is required
153+
*/
154+
getNtlmAuthInfo: function (auth, quoteType, format) {
155+
const ntlmAuth = auth && auth.ntlm;
156+
157+
if (!auth || auth.type !== 'ntlm' || !ntlmAuth || !ntlmAuth.count || !ntlmAuth.count()) {
158+
return '';
159+
}
160+
161+
const username = ntlmAuth.has('username') && ntlmAuth.get('username'),
162+
password = ntlmAuth.has('password') && ntlmAuth.get('password'),
163+
domain = ntlmAuth.has('domain') && ntlmAuth.get('domain');
164+
165+
if (!username && !password) {
166+
return '';
167+
}
168+
169+
var userArg = format ? '--user ' : '-u ',
170+
ntlmString = ' --ntlm ' + userArg + quoteType;
171+
172+
if (domain) {
173+
ntlmString += self.sanitize(domain, true, quoteType) + '\\';
174+
}
175+
ntlmString += self.sanitize(username, true, quoteType) + ':' + self.sanitize(password, true, quoteType);
176+
ntlmString += quoteType;
177+
178+
return ntlmString;
179+
},
180+
181+
/**
182+
*
183+
* @param {*} urlObject The request sdk request.url object
184+
* @param {boolean} quoteType The user given quoteType
185+
* @returns {String} The final string after parsing all the parameters of the url including
186+
* protocol, auth, host, port, path, query, hash
187+
* This will be used because the url.toString() method returned the URL with non encoded query string
188+
* and hence a manual call is made to getQueryString() method with encode option set as true.
189+
*/
155190
getUrlStringfromUrlObject: function (urlObject, quoteType) {
156191
var url = '';
157192
if (!urlObject) {

0 commit comments

Comments
 (0)