azure-storage-blob-go/swagger
Ze Qian Zhang a5410061cf Merge remote-tracking branch 'origin/master' into dev 2022-04-26 00:15:48 -07:00
..
README.md Implement copy source authorization (#317) 2022-04-25 15:11:09 -07:00
blob.json Update service version to 2020-08-04 and add markdown directives (#288) 2021-07-13 12:05:45 -07:00

README.md

Azure Blob Storage for Golang

see https://aka.ms/autorest

Generation

cd swagger
autorest README.md --use=@microsoft.azure/autorest.go@v3.0.63
gofmt -w Go_BlobStorage/*

Settings

input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/storage/data-plane/Microsoft.BlobStorage/preview/2020-10-02/blob.json
go: true
output-folder: Go_BlobStorage
namespace: azblob
go-export-clients: false
enable-xml: true
file-prefix: zz_generated_

Remove ContainerName and BlobName from parameter list since they are not needed

directive:
- from: swagger-document
  where: $["x-ms-paths"]
  transform: >
    for (const property in $)
    {
        if (property.includes('/{containerName}/{blob}'))
        {
            $[property]["parameters"] = $[property]["parameters"].filter(function(param) { return (typeof param['$ref'] === "undefined") || (false == param['$ref'].endsWith("#/parameters/ContainerName") && false == param['$ref'].endsWith("#/parameters/Blob"))});
        } 
        else if (property.includes('/{containerName}'))
        {
            $[property]["parameters"] = $[property]["parameters"].filter(function(param) { return (typeof param['$ref'] === "undefined") || (false == param['$ref'].endsWith("#/parameters/ContainerName"))});
        }
    }    

Set blob metadata to the right type

directive:
  - from: swagger-document
    where: $.definitions
    transform: >
      $["BlobMetadata"] = {
        "type": "object",
        "xml": {
          "name": "Metadata"
        },
        "additionalProperties": {
          "type": "string"
        }
      }      

Generate immutability policy correctly

directive:
  - from: swagger-document
    where: $.parameters.ImmutabilityPolicyMode
    transform: >
      $.enum = [
        "mutable",
        "unlocked",
        "locked"
      ]      
directive:
 - from: swagger-document
   where: $["x-ms-paths"].*.*.responses.*.headers["x-ms-immutability-policy-mode"]
   transform: >
     $.enum = [
        "mutable",
        "unlocked",
        "locked"
      ]     
directive:
  - from: swagger-document
    where: $.definitions.BlobPropertiesInternal.properties.ImmutabilityPolicyMode
    transform: >
      $.enum = [
        "mutable",
        "unlocked",
        "locked"
      ]      

Add permissions to ListBlobsInclude

This does work, it's just not documented, or in the swagger unfortunately. Some directives jank it in.

These directives may need to be removed eventually, once these items are included.

For some reason, permissions gets added 3x, so a check for includes is added.

directive:
  - from: swagger-document
    where: $.parameters.ListBlobsInclude
    transform: >
      if (!$.items.enum.includes("permissions"))
        $.items.enum.push("permissions")      
directive:
  - from: swagger-document
    where: $.definitions.BlobPropertiesInternal
    transform: >
      $.properties["Owner"] = {
        "type": "string"
      };
      $.properties["Group"] = {
        "type": "string"
      };
      $.properties["Permissions"] = {
        "type": "string"
      };
      $.properties["Acl"] = {
        "type": "string"
      };      

ETags

Headers

directive:
  - from: swagger-document
    where: $["x-ms-paths"].*.*.responses.*.headers["ETag"]
    transform: >
      $.format = "etag"      

Properties

directive:
  - from: swagger-document
    where: $.definitions.BlobPropertiesInternal.properties.Etag
    transform: >
      $.format = "etag"      
directive:
  - from: swagger-document
    where: $.definitions.ContainerProperties.properties.Etag
    transform: >
      $.format = "etag"      

[Source]If*Match

directive:
  - from: swagger-document
    where: $.parameters.IfMatch
    transform: >
      $.format = "etag"      
directive:
  - from: swagger-document
    where: $.parameters.IfNoneMatch
    transform: >
      $.format = "etag"      
directive:
  - from: swagger-document
    where: $.parameters.SourceIfMatch
    transform: >
      $.format = "etag"      
directive:
  - from: swagger-document
    where: $.parameters.SourceIfNoneMatch
    transform: >
      $.format = "etag"      

Remove BlobName & ContainerName parameters

directive:
  - from: swagger-document
    where: $["x-ms-paths"].*
    transform: >
      $.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/ContainerName" || x["$ref"] == "#/parameters/Blob"))      

Remove Marker & MaxResults from GetPageRange & GetPageRangeDiff

directive:
  - from: swagger-document
    where: $["x-ms-paths"]["/{containerName}/{blob}?comp=pagelist"]["get"]
    transform: >
      $.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/Marker" || x["$ref"] == "#/parameters/MaxResults"))      
directive:
  - from: swagger-document
    where: $["x-ms-paths"]["/{containerName}/{blob}?comp=pagelist&diff"]["get"]
    transform: >
      $.parameters = $.parameters.filter(x => x["$ref"] == undefined || !(x["$ref"] == "#/parameters/Marker" || x["$ref"] == "#/parameters/MaxResults"))      

TODO: Get rid of StorageError since we define it

TODO: rfc3339Format = "2006-01-02T15:04:05Z" //This was wrong in the generated code