Repository: vazco/uniforms
Pull request #604 (2019-10-02 12:39:35)

Fixed JSON schema type conflict.
[As @ziedmahdi noticed](https://github.com/vazco/uniforms/issues/345#issuecomment-535979999), using `uniforms: { type: 'password' }` in JSON schema had no effect.

codecov[bot]: # [Codecov](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=h1) Report
> Merging [#604](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=desc) into [master](https://codecov.io/gh/vazco/uniforms/commit/f10d6f023fed0257da0c5097ae5a96004693da1a?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/vazco/uniforms/pull/604/graphs/tree.svg?width=650&token=PEY7QrNpKu&height=150&src=pr)](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #604      +/-   ##
==========================================
+ Coverage   99.86%   99.86%   +<.01%     
==========================================
  Files         163      163              
  Lines        1533     1534       +1     
  Branches       12       12              
==========================================
+ Hits         1531     1532       +1     
  Partials        2        2
```


| [Impacted Files](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...niforms-bridge-json-schema/src/JSONSchemaBridge.js](https://codecov.io/gh/vazco/uniforms/pull/604/diff?src=pr&el=tree#diff-cGFja2FnZXMvdW5pZm9ybXMtYnJpZGdlLWpzb24tc2NoZW1hL3NyYy9KU09OU2NoZW1hQnJpZGdlLmpz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=footer). Last update [f10d6f0...a542b47](https://codecov.io/gh/vazco/uniforms/pull/604?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.js b/packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.js
index caa5b13f..dd578c0a 100644
--- a/packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.js
+++ b/packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.js
@@ -225,13 +225,14 @@ export default class JSONSchemaBridge extends Bridge {
 
   getProps(name, props = {}) {
     const { uniforms, ...field } = this.getField(name);
-    const { enum: enum_, isRequired, title, type, ...ready } = omit(
+    const { enum: enum_, isRequired, title, ...ready } = omit(
       { ...field, ...uniforms, ...this._compiledSchema[name] },
-      ['default', 'format']
+      ['default', 'format', 'type']
     );
 
     if (enum_) ready.allowedValues = enum_;
-    if (type === 'number') ready.decimal = true;
+    if (field.type === 'number') ready.decimal = true;
+    if (uniforms && uniforms.type !== undefined) ready.type = uniforms.type;
     if (ready.required === undefined) ready.required = isRequired;
     ready.label = extractValue(
       ready.label,


Test patch:
diff --git a/packages/uniforms-bridge-json-schema/__tests__/JSONSchemaBridge.js b/packages/uniforms-bridge-json-schema/__tests__/JSONSchemaBridge.js
index a6fb81cc..eb770f7f 100644
--- a/packages/uniforms-bridge-json-schema/__tests__/JSONSchemaBridge.js
+++ b/packages/uniforms-bridge-json-schema/__tests__/JSONSchemaBridge.js
@@ -108,7 +108,9 @@ describe('JSONSchemaBridge', () => {
             }
           }
         }
-      }
+      },
+      password: { type: 'string', uniforms: { type: 'password' } },
+      passwordNumeric: { type: 'number', uniforms: { type: 'password' } }
     },
     required: ['dateOfBirth']
   };
@@ -530,6 +532,21 @@ describe('JSONSchemaBridge', () => {
       expect(bridge.getProps('salary', props).allowedValues[1]).toBe('avarage');
     });
 
+    it('works with type', () => {
+      expect(bridge.getProps('password')).toEqual({
+        label: 'Password',
+        required: false,
+        type: 'password'
+      });
+
+      expect(bridge.getProps('passwordNumeric')).toEqual({
+        label: 'Password numeric',
+        required: false,
+        decimal: true,
+        type: 'password'
+      });
+    });
+
     it('works with other props', () => {
       expect(bridge.getProps('personalData.firstName', { x: 1, y: 1 })).toEqual(
         {
@@ -555,7 +572,9 @@ describe('JSONSchemaBridge', () => {
         'personalData',
         'salary',
         'shippingAddress',
-        'complexNames'
+        'complexNames',
+        'password',
+        'passwordNumeric'
       ]);
     });