From bf9c2ae62c25ab81560185cf16d42c4d2391b4aa Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Mon, 5 Aug 2019 10:43:55 -0700 Subject: [PATCH] Expanding our support for integer formats to a wider variety. (#245) --- example/swagger-files/types.json | 24 +++++++ .../api-explorer/__tests__/Params.test.jsx | 6 ++ packages/api-explorer/api-explorer.css | 72 +++++++++++++++++++ packages/api-explorer/package-lock.json | 2 +- packages/api-explorer/src/Params.jsx | 8 ++- .../src/form-components/SchemaField.jsx | 5 +- 6 files changed, 114 insertions(+), 3 deletions(-) diff --git a/example/swagger-files/types.json b/example/swagger-files/types.json index a0bad92b4..2c60afa69 100644 --- a/example/swagger-files/types.json +++ b/example/swagger-files/types.json @@ -84,14 +84,38 @@ "type": "integer", "format": "int64" }, + "integer (format: int8)": { + "type": "integer", + "format": "int8" + }, + "integer (format: uint8)": { + "type": "integer", + "format": "uint8" + }, + "integer (format: int16)": { + "type": "integer", + "format": "int16" + }, + "integer (format: uint16)": { + "type": "integer", + "format": "uint16" + }, "integer (format: int32)": { "type": "integer", "format": "int32" }, + "integer (format: uint32)": { + "type": "integer", + "format": "uint32" + }, "integer (format: int64)": { "type": "integer", "format": "int64" }, + "integer (format: uint64)": { + "type": "integer", + "format": "uint64" + }, "integer without `format`": { "type": "integer" }, diff --git a/packages/api-explorer/__tests__/Params.test.jsx b/packages/api-explorer/__tests__/Params.test.jsx index d08c7e625..7c72c27de 100644 --- a/packages/api-explorer/__tests__/Params.test.jsx +++ b/packages/api-explorer/__tests__/Params.test.jsx @@ -186,8 +186,14 @@ function testNumberClass(schema) { }); } +testNumberClass({ type: 'integer', format: 'int8' }); +testNumberClass({ type: 'integer', format: 'uint8' }); +testNumberClass({ type: 'integer', format: 'int16' }); +testNumberClass({ type: 'integer', format: 'uint16' }); testNumberClass({ type: 'integer', format: 'int32' }); +testNumberClass({ type: 'integer', format: 'uint32' }); testNumberClass({ type: 'integer', format: 'int64' }); +testNumberClass({ type: 'integer', format: 'uint64' }); testNumberClass({ type: 'number', format: 'float' }); testNumberClass({ type: 'number', format: 'double' }); diff --git a/packages/api-explorer/api-explorer.css b/packages/api-explorer/api-explorer.css index 69108a3cb..65c0b861c 100644 --- a/packages/api-explorer/api-explorer.css +++ b/packages/api-explorer/api-explorer.css @@ -347,6 +347,54 @@ fieldset[id^='root_array of objects_'] > legend::after { padding: 3px 6px; } +.field.field-integer.field-int8 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: int8'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + +.field.field-integer.field-uint8 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: uint8'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + +.field.field-integer.field-int16 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: int16'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + +.field.field-integer.field-uint16 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: uint16'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + .field.field-integer.field-int32 label::after { color: rgba(0, 0, 0, 0.6); content: 'integer: int32'; @@ -359,6 +407,18 @@ fieldset[id^='root_array of objects_'] > legend::after { padding: 3px 6px; } +.field.field-integer.field-uint32 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: uint32'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + .field.field-integer.field-int64 label::after { color: rgba(0, 0, 0, 0.6); content: 'integer: int64'; @@ -371,6 +431,18 @@ fieldset[id^='root_array of objects_'] > legend::after { padding: 3px 6px; } +.field.field-integer.field-uint64 label::after { + color: rgba(0, 0, 0, 0.6); + content: 'integer: uint64'; + background: #f2f2f2; + border-radius: 3px; + font-family: 'Proxima Nova', sans-serif; + font-size: 11px; + font-weight: lighter; + margin-left: 10px; + padding: 3px 6px; +} + .field.field-number.field-float label::after { color: rgba(0, 0, 0, 0.6); content: 'number: float'; diff --git a/packages/api-explorer/package-lock.json b/packages/api-explorer/package-lock.json index 81e2d4de8..e8411ed61 100644 --- a/packages/api-explorer/package-lock.json +++ b/packages/api-explorer/package-lock.json @@ -1,6 +1,6 @@ { "name": "@readme/api-explorer", - "version": "4.4.4", + "version": "4.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/api-explorer/src/Params.jsx b/packages/api-explorer/src/Params.jsx index 727c1bb2d..e0d0909d3 100644 --- a/packages/api-explorer/src/Params.jsx +++ b/packages/api-explorer/src/Params.jsx @@ -49,8 +49,14 @@ function Params({ idPrefix={operation.operationId} schema={schema.schema} widgets={{ - int64: UpDownWidget, + int8: UpDownWidget, + uint8: UpDownWidget, + int16: UpDownWidget, + uint16: UpDownWidget, int32: UpDownWidget, + uint32: UpDownWidget, + int64: UpDownWidget, + uint64: UpDownWidget, double: UpDownWidget, float: UpDownWidget, binary: FileWidget, diff --git a/packages/api-explorer/src/form-components/SchemaField.jsx b/packages/api-explorer/src/form-components/SchemaField.jsx index da1d48201..16cfc4f34 100644 --- a/packages/api-explorer/src/form-components/SchemaField.jsx +++ b/packages/api-explorer/src/form-components/SchemaField.jsx @@ -26,7 +26,10 @@ function getCustomType(schema) { if (schema.format === 'binary') return 'file'; } - if (isNumType(schema, 'integer', /int32|int64/) || isNumType(schema, 'number', /float|double/)) { + if ( + isNumType(schema, 'integer', /int8|int16|int32|int64/) || + isNumType(schema, 'number', /float|double/) + ) { return schema.format; }