Skip to content

Commit

Permalink
Update Redis swagger test and add support for Pattern properties (#1191)
Browse files Browse the repository at this point in the history
* Add AzureResourceSchema Microsoft.Resources test

* Add AzureResourceSchema Microsoft.Scheduler test

* Add AzureResourceSchema Microsoft.Logic test and remove 'Possible values' from descriptions

* Add AzureResourceSchema MachineLearning test. Add minimum and maximum to JsonSchema. Fix SequenceType bug

* Add AzureResourceSchema PowerBIEmbedded test

* Add Redis generated schema

* Add Microsoft.Search test

* Add TrafficManager schema

* Fix analysis errors

* Add Microsoft.Logic.json expected test file

* Update Microsoft.MachineLearning 2016-05-01-preview tests

* Add discriminator support to AzureResourceSchema generator

* Add discriminator property to generated schema definitions

* Fix the AzureResourceSchema generator by moving child resources property to be inside the first level properties property

* Update Redis swagger test and add support for Pattern properties
  • Loading branch information
Dan Schulte authored and tbombach committed Jun 27, 2016
1 parent 5cc6367 commit 44645a6
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,27 @@
"description": "The number of shards to be created on a Premium Cluster Cache."
},
"subnetId": {
"type": "string",
"oneOf": [
{
"type": "string",
"pattern": "^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]*/subnets/[^/]*$"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "The full resource ID of a subnet in a virtual network to deploy the redis cache in. Example format: /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.{Network|ClassicNetwork}/VirtualNetworks/vnet1/subnets/subnet1"
},
"staticIP": {
"type": "string",
"oneOf": [
{
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "Required when deploying a redis cache inside an existing Azure Virtual Network."
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,125 @@
}
}
}
},
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/patchSchedules/default": {
"put": {
"tags": [
"Redis"
],
"operationId": "PatchSchedules_CreateOrUpdate",
"description": "Create or replace the patching schedule for redis cache.",
"parameters": [
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the resource group."
},
{
"name": "name",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the redis cache."
},
{
"name": "parameters",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RedisPatchSchedulesRequest"
},
"description": "Parameters to set patch schedules for redis cache."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/RedisPatchSchedulesResponse"
}
}
}
},
"delete": {
"tags": [
"Redis"
],
"operationId": "PatchSchedules_Delete",
"description": "Deletes the patching schedule for redis cache.",
"parameters": [
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the resource group."
},
{
"name": "name",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the redis cache."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
}
],
"responses": {
"200": {
"description": ""
}
}
},
"get": {
"tags": [
"Redis"
],
"operationId": "PatchSchedules_Get",
"description": "Gets the patching schedule for redis cache.",
"parameters": [
{
"name": "resourceGroupName",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the resource group."
},
{
"name": "name",
"in": "path",
"required": true,
"type": "string",
"description": "The name of the redis cache."
},
{
"$ref": "#/parameters/ApiVersionParameter"
},
{
"$ref": "#/parameters/SubscriptionIdParameter"
}
],
"responses": {
"200": {
"description": "Response of Get patch schedules.",
"schema": {
"$ref": "#/definitions/RedisPatchSchedulesResponse"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -531,10 +650,12 @@
},
"subnetId": {
"type": "string",
"pattern": "^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]*/subnets/[^/]*$",
"description": "The full resource ID of a subnet in a virtual network to deploy the redis cache in. Example format: /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.{Network|ClassicNetwork}/VirtualNetworks/vnet1/subnets/subnet1"
},
"staticIP": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$",
"description": "Required when deploying a redis cache inside an existing Azure Virtual Network."
}
},
Expand Down Expand Up @@ -794,6 +915,98 @@
"files"
],
"description": "Parameters for redis import operation."
},
"ScheduleEntry": {
"properties": {
"dayOfWeek": {
"type": "string",
"description": "Day of week when cache can be patched.",
"enum": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
],
"x-ms-enum": {
"name": "DayOfWeek",
"modelAsString": true
}
},
"startHourUtc": {
"type": "integer",
"format": "int32",
"description": "Start hour after which cache patching can start."
},
"maintenanceWindow": {
"type": "string",
"format": "duration",
"description": "ISO8601 timespan specifying how much time cache patching can take. "
}
},
"required": [
"dayOfWeek",
"startHourUtc"
]
},
"ScheduleEntries": {
"properties": {
"scheduleEntries": {
"type": "array",
"items": {
"$ref": "#/definitions/ScheduleEntry"
},
"description": "List of patch schedules for redis cache."
}
},
"required": [
"scheduleEntries"
],
"description": "List of patch schedules for redis cache."
},
"RedisPatchSchedulesRequest": {
"properties": {
"properties": {
"x-ms-client-flatten": true,
"$ref": "#/definitions/ScheduleEntries",
"description": "List of patch schedules for redis cache."
}
},
"required": [
"properties"
],
"description": "Parameters to set patch schedules for redis cache."
},
"RedisPatchSchedulesResponse": {
"properties": {
"id": {
"readOnly": true,
"type": "string",
"description": "Resource Id"
},
"name": {
"readOnly": true,
"type": "string",
"description": "Resource name"
},
"type": {
"readOnly": true,
"type": "string",
"description": "Resource type"
},
"location": {
"type": "string",
"description": "Resource location"
},
"properties": {
"x-ms-client-flatten": true,
"$ref": "#/definitions/ScheduleEntries",
"description": "List of patch schedules for redis cache."
}
},
"description": "Response to put/get patch schedules for redis cache."
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public string ResourceType
/// </summary>
public double? Maximum { get; set; }

/// <summary>
/// The regular expression pattern that a string value matching this schema must match.
/// </summary>
public string Pattern { get; set; }

/// <summary>
/// The schema that matches additional properties that have not been specified in the
/// Properties dictionary.
Expand Down Expand Up @@ -301,6 +306,7 @@ public JsonSchema Clone()
result.AdditionalProperties = Clone(AdditionalProperties);
result.Minimum = Minimum;
result.Maximum = Maximum;
result.Pattern = Pattern;
result.enumList = Clone(Enum);
result.properties = Clone(Properties);
result.requiredList = Clone(Required);
Expand Down Expand Up @@ -380,7 +386,8 @@ public override bool Equals(object obj)
Equals(Required, rhs.Required) &&
Equals(Description, rhs.Description) &&
Equals(Minimum, rhs.Minimum) &&
Equals(Maximum, rhs.Maximum);
Equals(Maximum, rhs.Maximum) &&
Equals(Pattern, rhs.Pattern);
}

return result;
Expand All @@ -399,7 +406,8 @@ public override int GetHashCode()
GetHashCode(Required) ^
GetHashCode(Description) ^
GetHashCode(Minimum) ^
GetHashCode(Maximum);
GetHashCode(Maximum) ^
GetHashCode(Pattern);
}

private static int GetHashCode(object value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ private static JsonSchema ParsePrimaryType(Property property, PrimaryType primar
result.Maximum = Double.Parse(entry.Value, CultureInfo.CurrentCulture);
break;

case Constraint.Pattern:
Debug.Assert(result.JsonType == "string", "Expected to only find a Pattern constraint on a string property.");
result.Pattern = entry.Value;
break;

default:
Debug.Fail("Unrecognized property Constraint: " + entry.Key);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private static void WriteDefinitionMap(JsonWriter writer, string definitionMapNa
(definition.Enum != null &&
definition.Enum.Count() > 0 &&
definitionName != "type" &&
definitionName != "apiVersion")) &&
definitionName != "apiVersion") ||
(definition.Pattern != null)) &&
(definition.JsonType != "array" ||
(definitionName != "resources"));

Expand Down Expand Up @@ -148,6 +149,7 @@ private static void WriteDefinition(JsonWriter writer, JsonSchema definition)
WriteProperty(writer, "type", definition.JsonType);
WriteProperty(writer, "minimum", definition.Minimum);
WriteProperty(writer, "maximum", definition.Maximum);
WriteProperty(writer, "pattern", definition.Pattern);
WriteStringArray(writer, "enum", definition.Enum);
WriteDefinitionArray(writer, "oneOf", definition.OneOf);
WriteProperty(writer, "format", definition.Format);
Expand Down

0 comments on commit 44645a6

Please sign in to comment.