Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Expanding our support for integer formats to a wider variety. (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Aug 5, 2019
1 parent af6ab78 commit bf9c2ae
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
24 changes: 24 additions & 0 deletions example/swagger-files/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/api-explorer/__tests__/Params.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
72 changes: 72 additions & 0 deletions packages/api-explorer/api-explorer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/api-explorer/src/Params.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/api-explorer/src/form-components/SchemaField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit bf9c2ae

Please sign in to comment.