Skip to content

Commit

Permalink
Remove fields marked as removed
Browse files Browse the repository at this point in the history
I'm not sure why they're kept in the documentation
  • Loading branch information
ccouzens committed Jul 16, 2020
1 parent 703db1a commit b63b5ce
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 729 deletions.
112 changes: 97 additions & 15 deletions transformer/src/parsers/doc/etc/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(super) struct Annotation {
pub(super) deprecated: bool,
pub(super) modifiable: Option<Modifiable>,
pub(super) content_type: Option<String>,
pub(super) removed: bool,
}

#[derive(Error, Debug, PartialEq)]
Expand All @@ -33,6 +34,7 @@ impl Annotation {
deprecated: self.deprecated || b.deprecated,
modifiable: self.modifiable.or(b.modifiable),
required: self.required.or(b.required),
removed: self.removed || b.removed,
}
}
}
Expand Down Expand Up @@ -95,14 +97,30 @@ impl TryFrom<&Vec<xmltree::XMLNode>> for Annotation {
name,
attributes,
..
}) if namespace == XML_SCHEMA_NS
&& name == "documentation"
&& attributes.get("source").map(String::as_str) == Some("deprecated") =>
{
true
}) => {
namespace == XML_SCHEMA_NS
&& name == "documentation"
&& attributes.get("source").map(String::as_str) == Some("deprecated")
}
_ => false,
});
let removed = children.iter().any(|child| match child {
xmltree::XMLNode::Element(xmltree::Element {
namespace: Some(namespace),
name,
attributes,
..
}) => {
(namespace == XML_SCHEMA_NS
&& name == "documentation"
&& attributes.get("source").map(String::as_str) == Some("removed-in"))
|| (namespace == "http://www.vmware.com/vcloud/meta"
&& name == "version"
&& attributes.contains_key("removed-in"))
}
_ => false,
});

let modifiable = children
.iter()
.filter_map(|child| match child {
Expand Down Expand Up @@ -166,6 +184,7 @@ impl TryFrom<&Vec<xmltree::XMLNode>> for Annotation {
deprecated,
modifiable,
content_type,
removed,
})
}
}
Expand Down Expand Up @@ -227,7 +246,8 @@ fn test_parse_annotation() {
required: None,
deprecated: false,
modifiable: None,
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -251,7 +271,8 @@ fn test_parse_annotation_required() {
required: Some(true),
deprecated: false,
modifiable: None,
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -277,7 +298,8 @@ fn test_parse_annotation_not_required() {
required: Some(false),
deprecated: false,
modifiable: None,
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -300,7 +322,8 @@ fn test_parse_annotation_deprecated() {
required: None,
deprecated: true,
modifiable: None,
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -325,7 +348,8 @@ fn test_parse_annotation_modifiable_create() {
required: None,
deprecated: false,
modifiable: Some(Modifiable::Create),
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -348,7 +372,8 @@ fn test_parse_annotation_modifiable_update() {
required: None,
deprecated: false,
modifiable: Some(Modifiable::Update),
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -371,7 +396,8 @@ fn test_parse_annotation_modifiable_always() {
required: None,
deprecated: false,
modifiable: Some(Modifiable::Always),
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -394,7 +420,8 @@ fn test_parse_annotation_modifiable_none() {
required: None,
deprecated: false,
modifiable: Some(Modifiable::None),
content_type: None
content_type: None,
removed: false
})
);
}
Expand All @@ -421,7 +448,8 @@ fn test_parse_content_type() {
required: None,
deprecated: false,
modifiable: None,
content_type: Some("application/vnd.ccouzens.test".to_owned())
content_type: Some("application/vnd.ccouzens.test".to_owned()),
removed: false
})
);
}
Expand All @@ -447,7 +475,61 @@ fn test_parse_annotation_inside_app_info() {
required: None,
deprecated: false,
modifiable: None,
content_type: None
content_type: None,
removed: false
})
);
}

#[test]
fn test_annotation_indicating_removal() {
let xml: &[u8] = br#"
<xs:annotation xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:meta="http://www.vmware.com/vcloud/meta">
<xs:appinfo><meta:version removed-in="API_VERSION_POST9_1_UPDATE"/></xs:appinfo>
<xs:documentation source="modifiable">always</xs:documentation>
<xs:documentation xml:lang="en">
This field has been removed
</xs:documentation>
<xs:documentation source="required">false</xs:documentation>
<xs:documentation source="deprecated">6.0</xs:documentation>
<xs:documentation source="removed-in">API_VERSION_POST9_1_UPDATE</xs:documentation>
</xs:annotation>"#;
let tree = xmltree::Element::parse(xml).unwrap();
assert_eq!(
Annotation::try_from(&xmltree::XMLNode::Element(tree)),
Ok(Annotation {
description: Some("This field has been removed".to_owned()),
required: Some(false),
deprecated: true,
modifiable: Some(Modifiable::Always),
content_type: None,
removed: true
})
);
}

#[test]
fn test_alternative_removal_syntax() {
let xml: &[u8] = br#"
<xs:annotation xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:meta="http://www.vmware.com/vcloud/meta">
<xs:appinfo><meta:version removed-in="API_VERSION_POST9_1_UPDATE"/></xs:appinfo>
<xs:documentation source="modifiable">always</xs:documentation>
<xs:documentation xml:lang="en">
This field has been removed
</xs:documentation>
<xs:documentation source="required">false</xs:documentation>
<xs:documentation source="deprecated">6.0</xs:documentation>
</xs:annotation>"#;
let tree = xmltree::Element::parse(xml).unwrap();
assert_eq!(
Annotation::try_from(&xmltree::XMLNode::Element(tree)),
Ok(Annotation {
description: Some("This field has been removed".to_owned()),
required: Some(false),
deprecated: true,
modifiable: Some(Modifiable::Always),
content_type: None,
removed: true
})
);
}
5 changes: 5 additions & 0 deletions transformer/src/parsers/doc/etc/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum FieldParseError {
MissingType,
#[error("not a sequence element node")]
NotFieldNode,
#[error("this field is marked as removed")]
Removed,
}

impl TryFrom<(&xmltree::XMLNode, &str)> for Field {
Expand Down Expand Up @@ -83,6 +85,9 @@ impl TryFrom<(&xmltree::XMLNode, &str)> for Field {
_ => Occurrences::One,
};
let annotation = children.iter().flat_map(Annotation::try_from).next();
if annotation.as_ref().map(|a| a.removed) == Some(true) {
return Err(FieldParseError::Removed);
}
Ok(Field {
annotation,
name,
Expand Down
56 changes: 56 additions & 0 deletions transformer/src/parsers/doc/etc/object_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl TryFrom<(&xmltree::XMLNode, &str)> for ObjectType {
description: None,
modifiable: None,
required: Some(true),
removed: false,
}),
name: "value".into(),
occurrences: Occurrences::One,
Expand Down Expand Up @@ -425,3 +426,58 @@ fn parse_annotation_inside_complex_content_test() {
})
);
}

#[test]
fn removed_field_test() {
let xml: &[u8] = br#"
<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:meta="http://www.vmware.com/vcloud/meta" abstract="true" name="BaseType">
<xs:annotation>
<xs:documentation source="since">0.9</xs:documentation>
<xs:documentation xml:lang="en">
A base abstract type for all the types.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="FieldA" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:appinfo><meta:version added-in="1.0" removed-in="5.1"/></xs:appinfo>
<xs:documentation source="modifiable">always</xs:documentation>
<xs:documentation xml:lang="en">
A field that has been removed
</xs:documentation>
<xs:documentation source="required">false</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FieldB" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation source="modifiable">always</xs:documentation>
<xs:documentation xml:lang="en">
A field that has not been removed
</xs:documentation>
<xs:documentation source="required">false</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
"#;
let tree = xmltree::Element::parse(xml).unwrap();
let c = Type::try_from((&xmltree::XMLNode::Element(tree), "test")).unwrap();
let value = openapiv3::Schema::from(&c);
assert_eq!(
serde_json::to_value(value).unwrap(),
json!({
"title": "test_BaseType",
"description": "A base abstract type for all the types.",
"type": "object",
"properties": {
"fieldB": {
"description": "A field that has not been removed",
"type": "string"
}
},
"additionalProperties": false
})
);
}
32 changes: 0 additions & 32 deletions website/27.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -19972,15 +19972,6 @@
}
]
},
"storageCapacity": {
"readOnly": true,
"description": "Read\\-only indicator of datastore capacity.",
"allOf": [
{
"$ref": "#/components/schemas/vcloud_ProviderVdcCapacityType"
}
]
},
"availableNetworks": {
"readOnly": true,
"description": "Read\\-only list of available networks.",
Expand Down Expand Up @@ -28872,9 +28863,6 @@
"description": "An arbitrary key name. Length cannot exceed 256 UTF\\-8 characters.",
"type": "string"
},
"value": {
"type": "string"
},
"typedValue": {
"description": "One of: \n MetadataStringValue \n MetadataNumberValue \n MetadataBooleanValue \n MetadataDateTimeValue",
"allOf": [
Expand Down Expand Up @@ -29024,9 +29012,6 @@
}
]
},
"value": {
"type": "string"
},
"typedValue": {
"allOf": [
{
Expand Down Expand Up @@ -31743,15 +31728,6 @@
"description": "Compatibility mode. Default is false. If set to true, will allow users to write firewall rules in the old 1.5 format. The new format does not require to use direction in firewall rules. Also, for firewall rules to allow NAT traffic the filter is applied on the original IP addresses. Once set to true cannot be reverted back to false.",
"type": "boolean"
},
"ipScope": {
"deprecated": true,
"description": "Includes IP level configuration items such as gateway, dns, subnet, IP address pool to be used for allocation. Note that the pool of IP addresses needs to fall within the subnet/mask of the IpScope.",
"allOf": [
{
"$ref": "#/components/schemas/vcloud_IpScopeType"
}
]
},
"ipScopes": {
"description": "A list of IP scopes for the network.",
"allOf": [
Expand Down Expand Up @@ -40328,14 +40304,6 @@
"description": "The allocation model used by this vDC. One of: \n**AllocationVApp** (Pay as you go. Resources are committed to a vDC only when vApps are created in it. When you use this allocation model, any Limit values you specify for Memory and CPU are ignored on create and returned as 0 on retrieve.) \n**AllocationPool** (Only a percentage of the resources you allocate are committed to the organization vDC.) \n**ReservationPool** (All the resources you allocate are committed as a pool to the organization vDC. vApps in vDCs that support this allocation model can specify values for resource and limit.)",
"type": "string"
},
"storageCapacity": {
"description": "The storage capacity allocated to this vDC.",
"allOf": [
{
"$ref": "#/components/schemas/vcloud_CapacityWithUsageType"
}
]
},
"computeCapacity": {
"description": "The compute capacity allocated to this vDC.",
"allOf": [
Expand Down
Loading

0 comments on commit b63b5ce

Please sign in to comment.