Skip to content

Commit

Permalink
importer-msgraph-metadata: add a ContentType option to operations wit…
Browse files Browse the repository at this point in the history
…h binary request payloads (e.g. file uploads)
  • Loading branch information
manicminer committed Sep 20, 2024
1 parent 91a4b7c commit 1e7f8e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ func (p pipelineForService) parseResources(resourceIds parser.ResourceIds, model
continue
}

// Binary payloads are handled by the SDK
if content.Schema.Value != nil && content.Schema.Value.Format == "binary" {
// Set the request type to Binary. When translating to Data API SDK types, we will also work in a
// ContentType option to be set by the caller.
requestType = pointer.To(parser.DataTypeBinary)
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ func (p pipelineForService) translateServiceToDataApiSdkTypes() (*sdkModels.Serv
resourceIdName = &operation.ResourceId.Name
}

options := map[string]sdkModels.SDKOperationOption{
// All operations can specify the odata.metadata Accept parameter
"Metadata": {
Type: sdkModels.SDKOperationOptionTypeData,
ODataFieldName: pointer.To("Metadata"),
ObjectDefinition: sdkModels.SDKOperationOptionObjectDefinition{
ReferenceName: pointer.To("odata.Metadata"),
Type: sdkModels.ReferenceSDKOperationOptionObjectDefinitionType,
},
},

// All operations can accept a custom RetryFunc
"RetryFunc": {
Type: sdkModels.SDKOperationOptionTypeRetryFunc,
},
}

var requestObject *sdkModels.SDKObjectDefinition

if operation.RequestModelName != nil {
Expand Down Expand Up @@ -86,25 +103,21 @@ func (p pipelineForService) translateServiceToDataApiSdkTypes() (*sdkModels.Serv
}
} else if operation.RequestType != nil {
requestObject = &sdkModels.SDKObjectDefinition{
// This is a regular type, i.e. not a model or typed constant
Type: operation.RequestType.DataApiSdkObjectDefinitionType(),
}
}

options := map[string]sdkModels.SDKOperationOption{
"Metadata": {
ODataFieldName: pointer.To("Metadata"),
ObjectDefinition: sdkModels.SDKOperationOptionObjectDefinition{
ReferenceName: pointer.To("odata.Metadata"),
Type: sdkModels.ReferenceSDKOperationOptionObjectDefinitionType,
},
},
"RetryFunc": {
RetryFunc: true,
},
if *operation.RequestType == parser.DataTypeBinary {
// Add a ContentType option so the caller can specify the media type for the request body
options["ContentType"] = sdkModels.SDKOperationOption{
Type: sdkModels.SDKOperationOptionTypeContentType,
}
}
}

if operation.RequestHeaders != nil {
for _, header := range *operation.RequestHeaders {
// Some operations support the ConsistencyLevel header, this is structured via the odata package
if strings.EqualFold(header.Name, "ConsistencyLevel") {
options[normalize.CleanName(header.Name)] = sdkModels.SDKOperationOption{
ODataFieldName: &header.Name,
Expand Down Expand Up @@ -192,7 +205,7 @@ func (p pipelineForService) translateServiceToDataApiSdkTypes() (*sdkModels.Serv
}

case "Skip", "Top":
// Don't set here, we handle this implicitly in the SDK for list operations
// Don't set here, we handle this implicitly for list operations

default:
objectDefinition, err := param.DataApiSdkObjectDefinition()
Expand All @@ -214,6 +227,7 @@ func (p pipelineForService) translateServiceToDataApiSdkTypes() (*sdkModels.Serv
}
}

// Allow the caller to control paging for list operations
if operation.Type == parser.OperationTypeList {
options["Top"] = sdkModels.SDKOperationOption{
ODataFieldName: pointer.To("Top"),
Expand Down

0 comments on commit 1e7f8e7

Please sign in to comment.