| 1 |
# Azure Blob Storage for Golang |
| 2 |
|
| 3 |
> see https://aka.ms/autorest |
| 4 |
|
| 5 |
### Generation |
| 6 |
```bash |
| 7 |
cd swagger |
| 8 |
autorest README.md [email protected]/[email protected] |
| 9 |
gofmt -w Go_BlobStorage/* |
| 10 |
``` |
| 11 |
|
| 12 |
### Settings |
| 13 |
``` yaml |
| 14 |
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.BlobStorage/preview/2020-10-02/blob.json |
| 15 |
go: true |
| 16 |
output-folder: Go_BlobStorage |
| 17 |
namespace: azblob |
| 18 |
go-export-clients: false |
| 19 |
enable-xml: true |
| 20 |
file-prefix: zz_generated_ |
| 21 |
``` |
| 22 |
|
| 23 |
### Remove ContainerName and BlobName from parameter list since they are not needed |
| 24 |
```yaml |
| 25 |
directive: |
| 26 |
- from: swagger-document |
| 27 |
where: $["x-ms-paths"] |
| 28 |
transform: > |
| 29 |
for (const property in $) |
| 30 |
{ |
| 31 |
if (property.includes('/{containerName}/{blob}')) |
| 32 |
{ |
| 33 |
$[property]["parameters"] = $[property]["parameters"].filter(function(param) { return (typeof param['$ref'] === "undefined") || (false == param['$ref'].endsWith("#/parameters/ContainerName") && false == param['$ref'].endsWith("#/parameters/Blob"))}); |
| 34 |
} |
| 35 |
else if (property.includes('/{containerName}')) |
| 36 |
{ |
| 37 |
$[property]["parameters"] = $[property]["parameters"].filter(function(param) { return (typeof param['$ref'] === "undefined") || (false == param['$ref'].endsWith("#/parameters/ContainerName"))}); |
| 38 |
} |
| 39 |
} |
| 40 |
``` |
| 41 |
|
| 42 |
### Set blob metadata to the right type |
| 43 |
|
| 44 |
```yaml |
| 45 |
directive: |
| 46 |
- from: swagger-document |
| 47 |
where: $.definitions |
| 48 |
transform: > |
| 49 |
$["BlobMetadata"] = { |
| 50 |
"type": "object", |
| 51 |
"xml": { |
| 52 |
"name": "Metadata" |
| 53 |
}, |
| 54 |
"additionalProperties": { |
| 55 |
"type": "string" |
| 56 |
} |
| 57 |
} |
| 58 |
``` |
| 59 |
|
| 60 |
### Generate immutability policy correctly |
| 61 |
|
| 62 |
```yaml |
| 63 |
directive: |
| 64 |
- from: swagger-document |
| 65 |
where: $.parameters.ImmutabilityPolicyMode |
| 66 |
transform: > |
| 67 |
$.enum = [ |
| 68 |
"mutable", |
| 69 |
"unlocked", |
| 70 |
"locked" |
| 71 |
] |
| 72 |
``` |
| 73 |
|
| 74 |
```yaml |
| 75 |
directive: |
| 76 |
- from: swagger-document |
| 77 |
where: $["x-ms-paths"].*.*.responses.*.headers["x-ms-immutability-policy-mode"] |
| 78 |
transform: > |
| 79 |
$.enum = [ |
| 80 |
"mutable", |
| 81 |
"unlocked", |
| 82 |
"locked" |
| 83 |
] |
| 84 |
``` |
| 85 |
|
| 86 |
```yaml |
| 87 |
directive: |
| 88 |
- from: swagger-document |
| 89 |
where: $.definitions.BlobPropertiesInternal.properties.ImmutabilityPolicyMode |
| 90 |
transform: > |
| 91 |
$.enum = [ |
| 92 |
"mutable", |
| 93 |
"unlocked", |
| 94 |
"locked" |
| 95 |
] |
| 96 |
``` |
| 97 |
|
| 98 |
### Add permissions to ListBlobsInclude |
| 99 |
|
| 100 |
This *does* work, it's just not documented, or in the swagger unfortunately. Some directives jank it in. |
| 101 |
|
| 102 |
These directives may need to be removed eventually, once these items are included. |
| 103 |
|
| 104 |
For some reason, permissions gets added 3x, so a check for includes is added. |
| 105 |
|
| 106 |
```yaml |
| 107 |
directive: |
| 108 |
- from: swagger-document |
| 109 |
where: $.parameters.ListBlobsInclude |
| 110 |
transform: > |
| 111 |
if (!$.items.enum.includes("permissions")) |
| 112 |
$.items.enum.push("permissions") |
| 113 |
``` |
| 114 |
|
| 115 |
```yaml |
| 116 |
directive: |
| 117 |
- from: swagger-document |
| 118 |
where: $.definitions.BlobPropertiesInternal |
| 119 |
transform: > |
| 120 |
$.properties["Owner"] = { |
| 121 |
"type": "string" |
| 122 |
}; |
| 123 |
$.properties["Group"] = { |
| 124 |
"type": "string" |
| 125 |
}; |
| 126 |
$.properties["Permissions"] = { |
| 127 |
"type": "string" |
| 128 |
}; |
| 129 |
$.properties["Acl"] = { |
| 130 |
"type": "string" |
| 131 |
}; |
| 132 |
``` |
| 133 |
|
| 134 |
### ETags |
| 135 |
|
| 136 |
#### Headers |
| 137 |
```yaml |
| 138 |
directive: |
| 139 |
- from: swagger-document |
| 140 |
where: $["x-ms-paths"].*.*.responses.*.headers["ETag"] |
| 141 |
transform: > |
| 142 |
$.format = "etag" |
| 143 |
``` |
| 144 |
|
| 145 |
#### Properties |
| 146 |
```yaml |
| 147 |
directive: |
| 148 |
- from: swagger-document |
| 149 |
where: $.definitions.BlobPropertiesInternal.properties.Etag |
| 150 |
transform: > |
| 151 |
$.format = "etag" |
| 152 |
``` |
| 153 |
|
| 154 |
```yaml |
| 155 |
directive: |
| 156 |
- from: swagger-document |
| 157 |
where: $.definitions.ContainerProperties.properties.Etag |
| 158 |
transform: > |
| 159 |
$.format = "etag" |
| 160 |
``` |
| 161 |
|
| 162 |
#### \[Source\]If*Match |
| 163 |
```yaml |
| 164 |
directive: |
| 165 |
- from: swagger-document |
| 166 |
where: $.parameters.IfMatch |
| 167 |
transform: > |
| 168 |
$.format = "etag" |
| 169 |
``` |
| 170 |
|
| 171 |
```yaml |
| 172 |
directive: |
| 173 |
- from: swagger-document |
| 174 |
where: $.parameters.IfNoneMatch |
| 175 |
transform: > |
| 176 |
$.format = "etag" |
| 177 |
``` |
| 178 |
|
| 179 |
```yaml |
| 180 |
directive: |
| 181 |
- from: swagger-document |
| 182 |
where: $.parameters.SourceIfMatch |
| 183 |
transform: > |
| 184 |
$.format = "etag" |
| 185 |
``` |
| 186 |
|
| 187 |
```yaml |
| 188 |
directive: |
| 189 |
- from: swagger-document |
| 190 |
where: $.parameters.SourceIfNoneMatch |
| 191 |
transform: > |
| 192 |
$.format = "etag" |
| 193 |
``` |
| 194 |
|
| 195 |
### Remove BlobName & ContainerName parameters |
| 196 |
|
| 197 |
```yaml |
| 198 |
directive: |
| 199 |
- from: swagger-document |
| 200 |
where: $["x-ms-paths"].* |
| 201 |
transform: > |
| 202 |
$.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/ContainerName" || x["$ref"] == "#/parameters/Blob")) |
| 203 |
``` |
| 204 |
|
| 205 |
### Remove Marker & MaxResults from GetPageRange & GetPageRangeDiff |
| 206 |
|
| 207 |
```yaml |
| 208 |
directive: |
| 209 |
- from: swagger-document |
| 210 |
where: $["x-ms-paths"]["/{containerName}/{blob}?comp=pagelist"]["get"] |
| 211 |
transform: > |
| 212 |
$.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/Marker" || x["$ref"] == "#/parameters/MaxResults")) |
| 213 |
``` |
| 214 |
|
| 215 |
```yaml |
| 216 |
directive: |
| 217 |
- from: swagger-document |
| 218 |
where: $["x-ms-paths"]["/{containerName}/{blob}?comp=pagelist&diff"]["get"] |
| 219 |
transform: > |
| 220 |
$.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/Marker" || x["$ref"] == "#/parameters/MaxResults")) |
| 221 |
``` |
| 222 |
|
| 223 |
### TODO: Get rid of StorageError since we define it |
| 224 |
### TODO: rfc3339Format = "2006-01-02T15:04:05Z" //This was wrong in the generated code |