Skip to content

Commit 6be50c9

Browse files
authored
Merge pull request #20 from advanced-rest-client/fix/W-17655986/Exchange-asset-is-not-able-to-pass-ValueOnly-False-in-the-request
Fix/W-17655986/exchange asset is not able to pass value only false in the request
2 parents 9c25364 + 2a3399c commit 6be50c9

File tree

5 files changed

+77
-19
lines changed

5 files changed

+77
-19
lines changed

.github/workflows/deployment.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ on:
1313
- main
1414
jobs:
1515
test_linux:
16-
name: ubuntu
17-
runs-on: ubuntu-latest
16+
name: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-20.04]
21+
runs-on: ${{ matrix.os }}
1822
steps:
1923
- uses: actions/checkout@v2
2024
- uses: actions/setup-node@v1
@@ -53,7 +57,7 @@ jobs:
5357
tag:
5458
name: "Publishing release"
5559
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
56-
needs:
60+
needs:
5761
- test_linux
5862
- test_win
5963
runs-on: ubuntu-latest

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-url",
33
"description": "A library containing helper classes and UIs to support URL editing in AMF powered URL editor.",
4-
"version": "0.1.18",
4+
"version": "0.1.20",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiUrlEditorElement.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
326326
await this.updateComplete;
327327
this.validate();
328328
}
329-
329+
330330
/**
331331
* Creates a map of serialized values from a model.
332332
* It is a replacement for `iron-form` serialize function which
@@ -349,11 +349,12 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
349349
});
350350
return result;
351351
}
352-
352+
353353
/**
354354
* Extracts value from the model item.
355-
* If the item is required it is always returned (even if it is empty string).
355+
* If the item is required it is always returned (even if it is an empty string).
356356
* If value is not required and not present then it returns `undefined`.
357+
* Ensures boolean values are correctly preserved.
357358
*
358359
* @param {AmfFormItem} item Model item
359360
* @return {string} Model value
@@ -362,8 +363,14 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
362363
if (item.schema && item.enabled === false) {
363364
return undefined;
364365
}
365-
const { schema={} } = item;
366+
367+
const { schema = {} } = item;
366368
let { value } = item;
369+
370+
if (schema.isBool) {
371+
return value === false ? "false" : "true";
372+
}
373+
367374
if (!value && schema.required) {
368375
if (value !== 0 && value !== false && value !== null) {
369376
value = '';
@@ -373,6 +380,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
373380
value = undefined;
374381
}
375382
}
383+
376384
return value;
377385
}
378386

@@ -421,7 +429,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
421429
}
422430
return new RegExp(`{${name}}`);
423431
}
424-
432+
425433
/**
426434
* Applies query parameters to the URL.
427435
* Query parameters that are not required by the API spec and don't have value
@@ -489,7 +497,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
489497
}
490498

491499
/**
492-
* @param {ParamsObject[]} object The list of objects to encode as x-www-form-urlencoded string.
500+
* @param {ParamsObject[]} object The list of objects to encode as x-www-form-urlencoded string.
493501
* Each entry should have `name` and `value` properties.
494502
* @returns {string}
495503
*/
@@ -502,7 +510,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
502510
});
503511
return pieces.join('&');
504512
}
505-
513+
506514
/**
507515
* @param {string|number} value A key or value to encode as x-www-form-urlencoded.
508516
* @param {boolean} replacePlus When set it replaces `%20` with `+`.
@@ -572,7 +580,7 @@ export class ApiUrlEditorElement extends EventsTargetMixin(ValidatableMixin(LitE
572580
obj[name] = parts[1];
573581
}
574582
}
575-
583+
576584
/**
577585
* Applies values from the `values` array to the uri parameters which names are in the `names` array.
578586
* Both lists are ordered list of parameters.

test/ApiUrlEditorElement.test.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ import { UrlEventTypes } from '../index.js';
77

88
describe('ApiUrlEditorElement', () => {
99
/**
10-
* @return {Promise<ApiUrlEditorElement>}
10+
* @return {Promise<ApiUrlEditorElement>}
1111
*/
1212
async function basicFixture() {
1313
return (fixture(html`<api-url-editor></api-url-editor>`));
1414
}
1515

1616
/**
17-
* @return {Promise<ApiUrlEditorElement>}
17+
* @return {Promise<ApiUrlEditorElement>}
1818
*/
1919
async function requiredFixture() {
2020
return (fixture(html`<api-url-editor required></api-url-editor>`));
2121
}
2222

2323
/**
24-
* @return {Promise<ApiUrlEditorElement>}
24+
* @return {Promise<ApiUrlEditorElement>}
2525
*/
2626
async function eventsFixture() {
2727
return (fixture(html`<api-url-editor baseUri="https://domain.com" endpointPath="/{path}"></api-url-editor>`));
2828
}
2929

3030
/**
31-
* @return {Promise<ApiUrlEditorElement>}
31+
* @return {Promise<ApiUrlEditorElement>}
3232
*/
3333
async function valueFixture() {
3434
return (fixture(html`<api-url-editor value="https://domain.com/api/path"></api-url-editor>`));
3535
}
3636

3737
/**
38-
* @return {Promise<ApiUrlEditorElement>}
38+
* @return {Promise<ApiUrlEditorElement>}
3939
*/
4040
async function invalidFixture() {
4141
return (fixture(html`<api-url-editor value="https://domain.com/{path}" invalid></api-url-editor>`));
@@ -110,6 +110,50 @@ describe('ApiUrlEditorElement', () => {
110110
});
111111
});
112112

113+
describe('Boolean values in query parameters', () => {
114+
let element = /** @type ApiUrlEditorElement */ (null);
115+
let queryModel;
116+
const TEST_PATH = '/path/{var}';
117+
118+
beforeEach(async () => {
119+
element = await basicFixture();
120+
element.baseUri = BASE_URI;
121+
element.endpointPath = TEST_PATH;
122+
queryModel = [
123+
{
124+
value: false,
125+
name: 'test1',
126+
schema: {
127+
required: true,
128+
inputType: 'boolean',
129+
isBool: true
130+
}
131+
},
132+
{
133+
value: true,
134+
name: 'test2',
135+
schema: {
136+
required: true,
137+
inputType: 'boolean',
138+
isBool: true
139+
}
140+
}
141+
];
142+
});
143+
144+
it('includes boolean false as a query parameter in the URL', () => {
145+
element.queryModel = queryModel;
146+
const match = element.value.match(/test1=false/g);
147+
assert.equal(match.length, 1, 'Boolean false should be included in the URL as "test1=false"');
148+
});
149+
150+
it('includes boolean true as a query parameter in the URL', () => {
151+
element.queryModel = queryModel;
152+
const match = element.value.match(/&test2=true/g);
153+
assert.equal(match.length, 1, 'Boolean true should be included in the URL as "&test2=true"');
154+
});
155+
});
156+
113157
describe('Dispatches events', () => {
114158
let element = /** @type ApiUrlEditorElement */ (null);
115159
let queryModel;
@@ -902,4 +946,6 @@ describe('ApiUrlEditorElement', () => {
902946
assert.equal(url, '/flights/');
903947
});
904948
});
949+
950+
905951
});

0 commit comments

Comments
 (0)