From fd8aba3468c29e65779db0a0c8f7db3efa2a578c Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 4 Apr 2019 20:20:12 +0300 Subject: [PATCH] strip out the string format that we do not support. --- example/swagger-files/petstore.json | 3 ++- .../src/form-components/SchemaField.jsx | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/example/swagger-files/petstore.json b/example/swagger-files/petstore.json index 450de3126..f63769687 100644 --- a/example/swagger-files/petstore.json +++ b/example/swagger-files/petstore.json @@ -222,7 +222,8 @@ "in": "formData", "description": "Updated name of the pet", "required": false, - "type": "string" + "type": "string", + "format": "some-unknown-format" }, { "name": "status", "in": "formData", diff --git a/packages/api-explorer/src/form-components/SchemaField.jsx b/packages/api-explorer/src/form-components/SchemaField.jsx index 98634bc05..e820a6bbb 100644 --- a/packages/api-explorer/src/form-components/SchemaField.jsx +++ b/packages/api-explorer/src/form-components/SchemaField.jsx @@ -9,6 +9,25 @@ function getDefaultNumFormat(type) { return ''; } +function doesFormatExist(type, format) { + const availableFormats = [ + 'int64', + 'int32', + 'double', + 'float', + 'binary', + 'byte', + 'string', + 'uuid', + 'duration', + 'dateTime', + 'integer', + 'json', + ]; + + return type === 'string' && availableFormats.includes(format); +} + function isNumType(schema, type, format) { schema.format = schema.format || getDefaultNumFormat(schema.type); return schema.type === type && schema.format.match(format); @@ -28,6 +47,8 @@ function getCustomType(schema) { } function SchemaField(props) { + if (!doesFormatExist(props.schema.type, props.schema.format)) props.schema.format = undefined; + if (props.schema.readOnly) { // Maybe use this when it's been merged? // Though that just sets `input[readonly]` which still shows