Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions forward_engineering/helpers/typeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function getTypeProps(data, key, isParentActivated) {
maxItems: data.maxItems,
uniqueItems: data.uniqueItems || undefined,
nullable: data.nullable,
discriminator: data.discriminator,
readOnly: data.readOnly,
example: parseExample(data.sample) || getArrayItemsExample(items),
xml: getXml(data.xml)
Expand All @@ -46,6 +45,7 @@ function getTypeProps(data, key, isParentActivated) {
return Object.assign({}, arrayProps, arrayChoices, extensions);
}
case 'object': {
const discriminator = getDiscriminator(data.discriminator);
const objectProps = {
type,
title: data.title || undefined,
Expand All @@ -56,7 +56,7 @@ function getTypeProps(data, key, isParentActivated) {
maxProperties: data.maxProperties,
additionalProperties: getAdditionalProperties(data),
nullable: data.nullable,
discriminator: data.discriminator,
...(discriminator ? { discriminator } : {}),
readOnly: data.readOnly,
example: parseExample(data.sample),
xml: getXml(data.xml)
Expand Down Expand Up @@ -239,6 +239,22 @@ function getArrayItemsExample(items) {
}
}

function getDiscriminator(discriminator) {
if (!discriminator || !discriminator.propertyName) {
return null;
}
const mapping = (!discriminator.mapping || discriminator.mapping.length === 0) ? null : discriminator.mapping.reduce((acc, mappingItem) => {
acc[mappingItem.discriminatorValue] = mappingItem.discriminatorSchema;
return acc;
}, {});

return {
propertyName: discriminator.propertyName,
...(mapping && { mapping })

};
}

module.exports = {
getType,
getRef,
Expand Down
62 changes: 27 additions & 35 deletions properties_pane/field_level/fieldLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,6 @@ making sure that you maintain a proper JSON format.
"propertyType": "checkbox",
"enableForReference": true
},
{
"propertyName": "discriminator",
"propertyKeyword": "discriminator",
"propertyType": "text",
"sampleGen": "&containerName|&entityName|&random|<value>",
"enableForReference": true
},
{
"propertyName": "readOnly",
"propertyKeyword": "readOnly",
Expand Down Expand Up @@ -607,13 +600,6 @@ making sure that you maintain a proper JSON format.
"propertyType": "checkbox",
"enableForReference": true
},
{
"propertyName": "discriminator",
"propertyKeyword": "discriminator",
"propertyType": "text",
"sampleGen": "&containerName|&entityName|&random|<value>",
"enableForReference": true
},
{
"propertyName": "readOnly",
"propertyKeyword": "readOnly",
Expand Down Expand Up @@ -887,13 +873,6 @@ making sure that you maintain a proper JSON format.
"propertyType": "checkbox",
"enableForReference": true
},
{
"propertyName": "discriminator",
"propertyKeyword": "discriminator",
"propertyType": "text",
"sampleGen": "&containerName|&entityName|&random|<value>",
"enableForReference": true
},
{
"propertyName": "readOnly",
"propertyKeyword": "readOnly",
Expand Down Expand Up @@ -1273,17 +1252,6 @@ making sure that you maintain a proper JSON format.
"value": "schema"
}
},
{
"propertyName": "discriminator",
"propertyKeyword": "discriminator",
"propertyType": "text",
"sampleGen": "&containerName|&entityName|&random|<value>",
"enableForReference": true,
"dependency": {
"key": "subtype",
"value": "schema"
}
},
{
"propertyName": "readOnly",
"propertyKeyword": "readOnly",
Expand Down Expand Up @@ -1592,10 +1560,34 @@ making sure that you maintain a proper JSON format.
}
},
{
"propertyName": "discriminator",
"propertyName": "Discriminator",
"propertyKeyword": "discriminator",
"propertyType": "text",
"sampleGen": "&containerName|&entityName|&random|<value>",
"propertyType": "block",
"structure": [
{
"propertyName": "Property name",
"propertyKeyword": "propertyName",
"propertyTooltip": "",
"propertyType": "text"
},
{
"propertyName": "Mapping",
"propertyType": "group",
"propertyKeyword": "mapping",
"structure": [
{
"propertyName": "Discriminator value",
"propertyKeyword": "discriminatorValue",
"propertyType": "text"
},
{
"propertyName": "Schema name or reference",
"propertyKeyword": "discriminatorSchema",
"propertyType": "text"
}
]
}
],
"dependency": {
"key": "subtype",
"value": "schema"
Expand Down
14 changes: 14 additions & 0 deletions reverse_engineering/helpers/dataHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ const handleSchemaProperty = (property, data) => {
return handleSchemaXml(data);
case '$ref':
return resolveReference(data);
case 'discriminator':
return handleDiscriminator(data);
default:
if (commonHelper.CHOICES.find(choice => data[choice])) {
return handleSchemaProps(data);
Expand Down Expand Up @@ -920,6 +922,18 @@ const validateOpenAPISchema = (schema) => {
return isCorrectVersion;
};

const handleDiscriminator = (discriminator) => {
if (discriminator) {
const { propertyName, mapping } = discriminator;
const preparedMapping = mapping ? Object.keys(mapping).reduce((acc, key) => {
acc.push({ discriminatorValue: key, discriminatorSchema: mapping[key] });
return acc;
}, []) : [];
return { propertyName, mapping: preparedMapping };
}
return {};
};

module.exports = {
getModelData,
getComponents,
Expand Down