Skip to content

Commit 6e0b86c

Browse files
fix: [CDS-36798]: Revert Handle addition of constant values for projectidentifiers… (#34267)
* [CDS-38827]: Revert Handle additon of constant values for projectidentifiers and orgIdentifiers when oneOf is present This reverts commit 4899e52. * [CDS-38827]: Changes to fix test cases This reverts commit 698659c.
1 parent 53735a1 commit 6e0b86c

File tree

3 files changed

+100
-167
lines changed

3 files changed

+100
-167
lines changed

860-orchestration-steps/src/main/java/io/harness/plancreator/pipeline/PipelineInfoConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.harness.pms.yaml.ParameterField;
2222
import io.harness.pms.yaml.YamlNode;
2323
import io.harness.template.yaml.TemplateLinkConfig;
24-
import io.harness.validation.OneOfSet;
2524
import io.harness.validator.NGRegexValidatorConstants;
2625
import io.harness.yaml.YamlSchemaTypes;
2726
import io.harness.yaml.core.VariableExpression;
@@ -56,11 +55,6 @@
5655
@JsonIgnoreProperties(ignoreUnknown = true)
5756
@FieldDefaults(level = AccessLevel.PRIVATE)
5857
@TypeAlias("pipelineInfoConfig")
59-
@OneOfSet(
60-
fields =
61-
{"flowControl, properties, notificationRules, allowStageExecutions, timeout, stages, variables, delegateSelectors",
62-
"template"},
63-
requiredFieldNames = {"stages", "template"})
6458
public class PipelineInfoConfig {
6559
@JsonProperty(YamlNode.UUID_FIELD_NAME)
6660
@Getter(onMethod_ = { @ApiModelProperty(hidden = true) })

860-orchestration-steps/src/test/resources/schema/Pipelines/all.json

Lines changed: 80 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,138 +1727,98 @@
17271727
"$schema": "http://json-schema.org/draft-07/schema#"
17281728
},
17291729
"PipelineInfoConfig": {
1730-
"$schema": "http://json-schema.org/draft-07/schema#",
1731-
"oneOf": [
1732-
{
1733-
"type": "object",
1734-
"required": [
1735-
"identifier",
1736-
"name",
1737-
"stages"
1738-
],
1739-
"properties": {
1740-
"allowStageExecutions": {
1741-
"type": "boolean"
1742-
},
1743-
"delegateSelectors": {
1744-
"oneOf": [
1745-
{
1746-
"type": "array",
1747-
"items": {
1748-
"type": "string"
1749-
}
1750-
},
1751-
{
1752-
"type": "string",
1753-
"pattern": "^<\\+input>(\\.(allowedValues|regex)\\(.+?\\))*$",
1754-
"minLength": 1
1755-
}
1756-
]
1757-
},
1758-
"description": {
1759-
"type": "string"
1760-
},
1761-
"flowControl": {
1762-
"$ref": "#/definitions/FlowControlConfig"
1763-
},
1764-
"identifier": {
1765-
"type": "string",
1766-
"pattern": "^[a-zA-Z_][0-9a-zA-Z_$]{0,63}$"
1767-
},
1768-
"name": {
1769-
"type": "string",
1770-
"pattern": "^[a-zA-Z_][-0-9a-zA-Z_\\s]{0,63}$"
1771-
},
1772-
"notificationRules": {
1773-
"type": "array",
1774-
"items": {
1775-
"$ref": "#/definitions/NotificationRules"
1776-
}
1777-
},
1778-
"orgIdentifier": {
1779-
"type": "string"
1780-
},
1781-
"projectIdentifier": {
1782-
"type": "string"
1783-
},
1784-
"properties": {
1785-
"$ref": "#/definitions/NGProperties"
1786-
},
1787-
"stages": {
1730+
"type": "object",
1731+
"required": [
1732+
"identifier",
1733+
"name"
1734+
],
1735+
"properties": {
1736+
"allowStageExecutions": {
1737+
"type": "boolean"
1738+
},
1739+
"delegateSelectors": {
1740+
"oneOf": [
1741+
{
17881742
"type": "array",
17891743
"items": {
1790-
"$ref": "#/definitions/StageElementWrapperConfig"
1791-
},
1792-
"maxItems": 2147483647,
1793-
"minItems": 1
1794-
},
1795-
"tags": {
1796-
"type": "object",
1797-
"additionalProperties": {
17981744
"type": "string"
17991745
}
18001746
},
1801-
"timeout": {
1747+
{
18021748
"type": "string",
1803-
"pattern": "^(([1-9])+\\d+[s])|(((([1-9])+\\d*[mhwd])+([\\s]?\\d+[smhwd])*)|(<\\+input>.*)|(.*<\\+.*>.*))$"
1804-
},
1805-
"variables": {
1806-
"type": "array",
1807-
"items": {
1808-
"oneOf": [
1809-
{
1810-
"$ref": "#/definitions/NumberNGVariable"
1811-
},
1812-
{
1813-
"$ref": "#/definitions/SecretNGVariable"
1814-
},
1815-
{
1816-
"$ref": "#/definitions/StringNGVariable"
1817-
}
1818-
]
1819-
}
1749+
"pattern": "^<\\+input>(\\.(allowedValues|regex)\\(.+?\\))*$",
1750+
"minLength": 1
18201751
}
1752+
]
1753+
},
1754+
"description": {
1755+
"type": "string"
1756+
},
1757+
"flowControl": {
1758+
"$ref": "#/definitions/FlowControlConfig"
1759+
},
1760+
"identifier": {
1761+
"type": "string",
1762+
"pattern": "^[a-zA-Z_][0-9a-zA-Z_$]{0,63}$"
1763+
},
1764+
"name": {
1765+
"type": "string",
1766+
"pattern": "^[a-zA-Z_][-0-9a-zA-Z_\\s]{0,63}$"
1767+
},
1768+
"notificationRules": {
1769+
"type": "array",
1770+
"items": {
1771+
"$ref": "#/definitions/NotificationRules"
1772+
}
1773+
},
1774+
"orgIdentifier": {
1775+
"type": "string"
1776+
},
1777+
"projectIdentifier": {
1778+
"type": "string"
1779+
},
1780+
"properties": {
1781+
"$ref": "#/definitions/NGProperties"
1782+
},
1783+
"stages": {
1784+
"type": "array",
1785+
"items": {
1786+
"$ref": "#/definitions/StageElementWrapperConfig"
18211787
},
1822-
"additionalProperties": false
1788+
"maxItems": 2147483647,
1789+
"minItems": 1
18231790
},
1824-
{
1791+
"tags": {
18251792
"type": "object",
1826-
"required": [
1827-
"identifier",
1828-
"name",
1829-
"template"
1830-
],
1831-
"properties": {
1832-
"description": {
1833-
"type": "string"
1834-
},
1835-
"identifier": {
1836-
"type": "string",
1837-
"pattern": "^[a-zA-Z_][0-9a-zA-Z_$]{0,63}$"
1838-
},
1839-
"name": {
1840-
"type": "string",
1841-
"pattern": "^[a-zA-Z_][-0-9a-zA-Z_\\s]{0,63}$"
1842-
},
1843-
"orgIdentifier": {
1844-
"type": "string"
1845-
},
1846-
"projectIdentifier": {
1847-
"type": "string"
1848-
},
1849-
"tags": {
1850-
"type": "object",
1851-
"additionalProperties": {
1852-
"type": "string"
1793+
"additionalProperties": {
1794+
"type": "string"
1795+
}
1796+
},
1797+
"template": {
1798+
"$ref": "#/definitions/TemplateLinkConfig"
1799+
},
1800+
"timeout": {
1801+
"type": "string",
1802+
"pattern": "^(([1-9])+\\d+[s])|(((([1-9])+\\d*[mhwd])+([\\s]?\\d+[smhwd])*)|(<\\+input>.*)|(.*<\\+.*>.*))$"
1803+
},
1804+
"variables": {
1805+
"type": "array",
1806+
"items": {
1807+
"oneOf": [
1808+
{
1809+
"$ref": "#/definitions/NumberNGVariable"
1810+
},
1811+
{
1812+
"$ref": "#/definitions/SecretNGVariable"
1813+
},
1814+
{
1815+
"$ref": "#/definitions/StringNGVariable"
18531816
}
1854-
},
1855-
"template": {
1856-
"$ref": "#/definitions/TemplateLinkConfig"
1857-
}
1858-
},
1859-
"additionalProperties": false
1817+
]
1818+
}
18601819
}
1861-
]
1820+
},
1821+
"$schema": "http://json-schema.org/draft-07/schema#"
18621822
},
18631823
"PmsEmailChannel": {
18641824
"allOf": [

960-yaml-sdk/src/main/java/io/harness/yaml/schema/YamlSchemaProvider.java

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static io.harness.data.structure.EmptyPredicate.isNotEmpty;
1414
import static io.harness.yaml.schema.beans.SchemaConstants.CONST_NODE;
1515
import static io.harness.yaml.schema.beans.SchemaConstants.DEFINITIONS_NODE;
16-
import static io.harness.yaml.schema.beans.SchemaConstants.ONE_OF_NODE;
1716
import static io.harness.yaml.schema.beans.SchemaConstants.PROPERTIES_NODE;
1817
import static io.harness.yaml.schema.beans.SchemaConstants.REF_NODE;
1918
import static io.harness.yaml.schema.beans.SchemaConstants.REQUIRED_NODE;
@@ -26,7 +25,6 @@
2625
import io.harness.yaml.schema.beans.YamlSchemaWithDetails;
2726

2827
import com.fasterxml.jackson.databind.JsonNode;
29-
import com.fasterxml.jackson.databind.node.ArrayNode;
3028
import com.fasterxml.jackson.databind.node.ObjectNode;
3129
import com.fasterxml.jackson.databind.node.ValueNode;
3230
import com.google.common.annotations.VisibleForTesting;
@@ -71,20 +69,27 @@ public ObjectNode getYamlSchemaUtil(
7169
ObjectNode secondLevelNode = getSecondLevelNode(schema);
7270
ObjectNode secondLevelNodeProperties = getSecondLevelNodeProperties(secondLevelNode);
7371

74-
if (secondLevelNodeProperties == null) {
75-
ArrayNode oneOfNodes = (ArrayNode) secondLevelNode.get(ONE_OF_NODE);
76-
if (oneOfNodes != null) {
77-
for (JsonNode oneOfNode : oneOfNodes) {
78-
if (oneOfNode.has(PROPERTIES_NODE)) {
79-
secondLevelNodeProperties = getSecondLevelNodeProperties(oneOfNode);
80-
addingScopeToSchema((ObjectNode) oneOfNode, secondLevelNodeProperties, orgIdentifier, projectIdentifier,
81-
scope, schemaDetailsForEntityType);
82-
}
83-
}
72+
if (scope == Scope.ACCOUNT && schemaDetailsForEntityType.isAvailableAtAccountLevel()) {
73+
JsonNodeUtils.deletePropertiesInJsonNode(secondLevelNodeProperties, PROJECT_KEY, ORG_KEY);
74+
} else if (scope == Scope.ORG && schemaDetailsForEntityType.isAvailableAtOrgLevel()) {
75+
JsonNodeUtils.deletePropertiesInJsonNode(secondLevelNodeProperties, PROJECT_KEY);
76+
if (isNotEmpty(orgIdentifier)) {
77+
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNodeProperties.get(ORG_KEY), CONST_NODE, orgIdentifier);
78+
}
79+
if (secondLevelNodeProperties.has(ORG_KEY)) {
80+
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNode, REQUIRED_NODE, ORG_KEY);
81+
}
82+
} else if (scope == Scope.PROJECT && schemaDetailsForEntityType.isAvailableAtProjectLevel()) {
83+
if (isNotEmpty(orgIdentifier)) {
84+
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNodeProperties.get(ORG_KEY), CONST_NODE, orgIdentifier);
85+
}
86+
if (isNotEmpty(projectIdentifier)) {
87+
JsonNodeUtils.upsertPropertyInObjectNode(
88+
secondLevelNodeProperties.get(PROJECT_KEY), CONST_NODE, projectIdentifier);
89+
}
90+
if (secondLevelNodeProperties.has(ORG_KEY) && secondLevelNodeProperties.has(PROJECT_KEY)) {
91+
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNode, REQUIRED_NODE, ORG_KEY, PROJECT_KEY);
8492
}
85-
} else {
86-
addingScopeToSchema(secondLevelNode, secondLevelNodeProperties, orgIdentifier, projectIdentifier, scope,
87-
schemaDetailsForEntityType);
8893
}
8994
} catch (Exception e) {
9095
log.info("Exception in adding scope to schema. {}", e);
@@ -94,32 +99,6 @@ public ObjectNode getYamlSchemaUtil(
9499
return schema;
95100
}
96101

97-
private void addingScopeToSchema(ObjectNode secondLevelNode, ObjectNode secondLevelNodeProperties,
98-
String orgIdentifier, String projectIdentifier, Scope scope, YamlSchemaWithDetails schemaDetailsForEntityType) {
99-
if (scope == Scope.ACCOUNT && schemaDetailsForEntityType.isAvailableAtAccountLevel()) {
100-
JsonNodeUtils.deletePropertiesInJsonNode(secondLevelNodeProperties, PROJECT_KEY, ORG_KEY);
101-
} else if (scope == Scope.ORG && schemaDetailsForEntityType.isAvailableAtOrgLevel()) {
102-
JsonNodeUtils.deletePropertiesInJsonNode(secondLevelNodeProperties, PROJECT_KEY);
103-
if (isNotEmpty(orgIdentifier)) {
104-
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNodeProperties.get(ORG_KEY), CONST_NODE, orgIdentifier);
105-
}
106-
if (secondLevelNodeProperties.has(ORG_KEY)) {
107-
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNode, REQUIRED_NODE, ORG_KEY);
108-
}
109-
} else if (scope == Scope.PROJECT && schemaDetailsForEntityType.isAvailableAtProjectLevel()) {
110-
if (isNotEmpty(orgIdentifier)) {
111-
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNodeProperties.get(ORG_KEY), CONST_NODE, orgIdentifier);
112-
}
113-
if (isNotEmpty(projectIdentifier)) {
114-
JsonNodeUtils.upsertPropertyInObjectNode(
115-
secondLevelNodeProperties.get(PROJECT_KEY), CONST_NODE, projectIdentifier);
116-
}
117-
if (secondLevelNodeProperties.has(ORG_KEY) && secondLevelNodeProperties.has(PROJECT_KEY)) {
118-
JsonNodeUtils.upsertPropertyInObjectNode(secondLevelNode, REQUIRED_NODE, ORG_KEY, PROJECT_KEY);
119-
}
120-
}
121-
}
122-
123102
@VisibleForTesting
124103
ObjectNode getSecondLevelNodeProperties(JsonNode secondLevelNode) {
125104
return (ObjectNode) secondLevelNode.get(PROPERTIES_NODE);

0 commit comments

Comments
 (0)