-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/hck 4778 hackolade assignment examples are always genera (#68)
* field-level-config: change property type for example to dynamic field * field-level-config: split example property config by version * FE: add change type of parameter example value according to schema type * adapter: add adapter to re-validate sample values * FE: move correct type method to type helper * Revert "adapter: add adapter to re-validate sample values" This reverts commit c041231. * FE: move method into separate file * FE: fix import circular dependency
- Loading branch information
1 parent
e02d369
commit 24419be
Showing
4 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
forward_engineering/helpers/componentsHelpers/exampleDataHelper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function parseExample(data) { | ||
try { | ||
return JSON.parse(data); | ||
} catch (err) { | ||
return data; | ||
} | ||
} | ||
|
||
function parseExampleValueByDataType(value, type) { | ||
const parsedValue = parseExample(value); | ||
|
||
switch (type) { | ||
case 'string': | ||
if (typeof parsedValue === 'string') { | ||
return parsedValue; | ||
} | ||
break; | ||
case 'number': | ||
case 'integer': | ||
if (!isNaN(parsedValue)) { | ||
return parsedValue; | ||
} | ||
break; | ||
case 'array': | ||
if (Array.isArray(parsedValue)) { | ||
return parsedValue; | ||
} | ||
break; | ||
case 'object': | ||
if (typeof parsedValue === 'object' && parsedValue !== null) { | ||
return parsedValue; | ||
} | ||
break; | ||
case 'boolean': | ||
if (typeof parsedValue === 'boolean') { | ||
return parsedValue; | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
module.exports = { | ||
parseExampleValueByDataType | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters