diff --git a/src/generator/operations.ts b/src/generator/operations.ts index b223778f6..3e4f3778f 100644 --- a/src/generator/operations.ts +++ b/src/generator/operations.ts @@ -258,6 +258,14 @@ function formatHeaderResponseValue(propName: string, header: string, schema: Sch return text; } +function generateMultiRespComment(op: Operation): string { + const returnTypes = new Array(); + for (const response of values(op.responses)) { + returnTypes.push(`*${(response).schema.language.go!.responseType.name}`); + } + return `// Possible return types are ${returnTypes.join(', ')}\n`; +} + function generateOperation(clientName: string, op: Operation, imports: ImportManager): string { if (op.language.go!.paging && op.language.go!.paging.isNextOp) { // don't generate a public API for the methods used to advance pages @@ -270,6 +278,9 @@ function generateOperation(clientName: string, op: Operation, imports: ImportMan if (hasDescription(op.language.go!)) { text += `// ${op.language.go!.name} - ${op.language.go!.description} \n`; } + if (isMultiRespOperation(op)) { + text += generateMultiRespComment(op); + } if (op.language.go!.methodPrefix) { text += `func (client *${clientName}) ${op.language.go!.methodPrefix}${op.language.go!.name}(${params}) (${returns.join(', ')}) {\n`; } else { @@ -642,103 +653,97 @@ function createProtocolResponse(client: string, op: Operation, imports: ImportMa text += '}\n\n'; return text; } - const firstResp = op.responses![0]; - // concat all status codes that return the same schema into one array. - // this is to support operations that specify multiple response codes - // that return the same schema (or no schema). - // TODO: handle response codes with different schemas - // TODO: remove pageable LRO exception - let statusCodes = new Array(); - statusCodes = statusCodes.concat(firstResp.protocol.http?.statusCodes); - for (let i = 1; i < op.responses.length; ++i) { - if (!isSchemaResponse(firstResp) && !isSchemaResponse(op.responses[i])) { - // both responses return no schema, append status codes - statusCodes = statusCodes.concat(op.responses[i].protocol.http?.statusCodes); - } else if (isSchemaResponse(firstResp) && isSchemaResponse(op.responses[i])) { - // both responses return a schema, ensure they're the same - if ((firstResp).schema === (op.responses[i]).schema) { - // same schemas, append status codes - statusCodes = statusCodes.concat(op.responses[i].protocol.http?.statusCodes); + const generateResponseUnmarshaller = function (response: Response): string { + let unmarshallerText = ''; + if (!isSchemaResponse(response)) { + if (isLROOperation(op)) { + unmarshallerText += '\treturn &HTTPResponse{RawResponse: resp.Response}, nil\n'; + return unmarshallerText; } - } else if (isLROOperation(op)) { + // no response body, return the *http.Response + unmarshallerText += `\treturn resp.Response, nil\n`; + return unmarshallerText; + } else if (response.schema.type === SchemaType.DateTime || response.schema.type === SchemaType.UnixTime) { + // use the designated time type for unmarshalling + unmarshallerText += `\tvar aux *${response.schema.language.go!.internalTimeType}\n`; + unmarshallerText += `\terr := resp.UnmarshalAs${getMediaType(response.protocol)}(&aux)\n`; + const resp = `${response.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${response.schema.language.go!.responseType.value}: (*time.Time)(aux)}`; + unmarshallerText += `\treturn &${resp}, err\n`; + return unmarshallerText; + } else if (isArrayOfDateTime(response.schema)) { + // unmarshalling arrays of date/time is a little more involved + unmarshallerText += `\tvar aux *[]${(response.schema).elementType.language.go!.internalTimeType}\n`; + unmarshallerText += `\tif err := resp.UnmarshalAs${getMediaType(response.protocol)}(&aux); err != nil {\n`; + unmarshallerText += '\t\treturn nil, err\n'; + unmarshallerText += '\t}\n'; + unmarshallerText += '\tcp := make([]time.Time, len(*aux), len(*aux))\n'; + unmarshallerText += '\tfor i := 0; i < len(*aux); i++ {\n'; + unmarshallerText += '\t\tcp[i] = time.Time((*aux)[i])\n'; + unmarshallerText += '\t}\n'; + const resp = `${response.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${response.schema.language.go!.responseType.value}: &cp}`; + unmarshallerText += `\treturn &${resp}, nil\n`; + return unmarshallerText; + } else if (isMapOfDateTime(response.schema)) { + unmarshallerText += `\taux := map[string]${(response.schema).elementType.language.go!.internalTimeType}{}\n`; + unmarshallerText += `\tif err := resp.UnmarshalAs${getMediaType(response.protocol)}(&aux); err != nil {\n`; + unmarshallerText += '\t\treturn nil, err\n'; + unmarshallerText += '\t}\n'; + unmarshallerText += `\tcp := map[string]time.Time{}\n`; + unmarshallerText += `\tfor k, v := range aux {\n`; + unmarshallerText += `\t\tcp[k] = time.Time(v)\n`; + unmarshallerText += `\t}\n`; + const resp = `${response.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${response.schema.language.go!.responseType.value}: &cp}`; + unmarshallerText += `\treturn &${resp}, nil\n`; + return unmarshallerText; + } + const schemaResponse = response; + let respObj = `${schemaResponse.schema.language.go!.responseType.name}{RawResponse: resp.Response}`; + unmarshallerText += `\tresult := ${respObj}\n`; + // assign any header values + for (const prop of values(>schemaResponse.schema.language.go!.properties)) { + if (prop.language.go!.fromHeader) { + unmarshallerText += formatHeaderResponseValue(prop.language.go!.name, prop.language.go!.fromHeader, prop.schema, imports, 'result'); + } + } + const mediaType = getMediaType(response.protocol); + if (mediaType === 'none' || mediaType === 'binary') { + // nothing to unmarshal + unmarshallerText += '\treturn &result, nil\n'; + return unmarshallerText; + } + let target = `result.${schemaResponse.schema.language.go!.responseType.value}`; + // when unmarshalling a wrapped XML array or discriminated type, unmarshal into the response type, not the field + if ((mediaType === 'XML' && schemaResponse.schema.type === SchemaType.Array) || schemaResponse.schema.language.go!.discriminatorInterface) { + target = 'result'; + } + unmarshallerText += `\treturn &result, resp.UnmarshalAs${getMediaFormat(response.schema, mediaType, `&${target}`)}\n`; + return unmarshallerText; + }; + if (!isMultiRespOperation(op)) { + // concat all status codes that return the same schema into one array. + // this is to support operations that specify multiple response codes + // that return the same schema (or no schema). + let statusCodes = new Array(); + for (let i = 0; i < op.responses.length; ++i) { statusCodes = statusCodes.concat(op.responses[i].protocol.http?.statusCodes); } - } - if (isLROOperation(op) && statusCodes.find(element => element === '204') === undefined) { - statusCodes = statusCodes.concat('204'); - } - text += `\tif !resp.HasStatusCode(${formatStatusCodes(statusCodes)}) {\n`; - text += `\t\treturn nil, client.${info.protocolNaming.errorMethod}(resp)\n`; - text += '\t}\n'; - if (!isSchemaResponse(firstResp)) { - if (isLROOperation(op)) { - text += '\treturn &HTTPResponse{RawResponse: resp.Response}, nil\n'; - text += '}\n\n'; - return text; + if (isLROOperation(op) && statusCodes.find(element => element === '204') === undefined) { + statusCodes = statusCodes.concat('204'); } - // no response body, return the *http.Response - text += `\treturn resp.Response, nil\n`; - text += '}\n\n'; - return text; - } else if (firstResp.schema.type === SchemaType.DateTime || firstResp.schema.type === SchemaType.UnixTime) { - // use the designated time type for unmarshalling - text += `\tvar aux *${firstResp.schema.language.go!.internalTimeType}\n`; - text += `\terr := resp.UnmarshalAs${getMediaType(firstResp.protocol)}(&aux)\n`; - const resp = `${firstResp.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${firstResp.schema.language.go!.responseType.value}: (*time.Time)(aux)}`; - text += `\treturn &${resp}, err\n`; - text += '}\n\n'; - return text; - } else if (isArrayOfDateTime(firstResp.schema)) { - // unmarshalling arrays of date/time is a little more involved - text += `\tvar aux *[]${(firstResp.schema).elementType.language.go!.internalTimeType}\n`; - text += `\tif err := resp.UnmarshalAs${getMediaType(firstResp.protocol)}(&aux); err != nil {\n`; - text += '\t\treturn nil, err\n'; - text += '\t}\n'; - text += '\tcp := make([]time.Time, len(*aux), len(*aux))\n'; - text += '\tfor i := 0; i < len(*aux); i++ {\n'; - text += '\t\tcp[i] = time.Time((*aux)[i])\n'; + text += `\tif !resp.HasStatusCode(${formatStatusCodes(statusCodes)}) {\n`; + text += `\t\treturn nil, client.${info.protocolNaming.errorMethod}(resp)\n`; text += '\t}\n'; - const resp = `${firstResp.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${firstResp.schema.language.go!.responseType.value}: &cp}`; - text += `\treturn &${resp}, nil\n`; - text += '}\n\n'; - return text; - } else if (isMapOfDateTime(firstResp.schema)) { - text += `\taux := map[string]${(firstResp.schema).elementType.language.go!.internalTimeType}{}\n`; - text += `\tif err := resp.UnmarshalAs${getMediaType(firstResp.protocol)}(&aux); err != nil {\n`; - text += '\t\treturn nil, err\n'; - text += '\t}\n'; - text += `\tcp := map[string]time.Time{}\n`; - text += `\tfor k, v := range aux {\n`; - text += `\t\tcp[k] = time.Time(v)\n`; - text += `\t}\n`; - const resp = `${firstResp.schema.language.go!.responseType.name}{RawResponse: resp.Response, ${firstResp.schema.language.go!.responseType.value}: &cp}`; - text += `\treturn &${resp}, nil\n`; - text += '}\n\n'; - return text; - } - - const schemaResponse = firstResp; - let respObj = `${schemaResponse.schema.language.go!.responseType.name}{RawResponse: resp.Response}`; - text += `\tresult := ${respObj}\n`; - // assign any header values - for (const prop of values(>schemaResponse.schema.language.go!.properties)) { - if (prop.language.go!.fromHeader) { - text += formatHeaderResponseValue(prop.language.go!.name, prop.language.go!.fromHeader, prop.schema, imports, 'result'); + text += generateResponseUnmarshaller(op.responses![0]); + } else { + text += '\tswitch resp.StatusCode {\n'; + for (const response of values(op.responses)) { + text += `\tcase ${formatStatusCodes(response.protocol.http!.statusCodes)}:\n` + text += generateResponseUnmarshaller(response); } + text += '\tdefault:\n'; + text += `\t\treturn nil, client.${info.protocolNaming.errorMethod}(resp)\n`; + text += '\t}\n'; } - const mediaType = getMediaType(firstResp.protocol); - if (mediaType === 'none' || mediaType === 'binary') { - // nothing to unmarshal - text += '\treturn &result, nil\n'; - text += '}\n\n'; - return text; - } - let target = `result.${schemaResponse.schema.language.go!.responseType.value}`; - // when unmarshalling a wrapped XML array or discriminated type, unmarshal into the response type, not the field - if ((mediaType === 'XML' && schemaResponse.schema.type === SchemaType.Array) || schemaResponse.schema.language.go!.discriminatorInterface) { - target = 'result'; - } - text += `\treturn &result, resp.UnmarshalAs${getMediaFormat(firstResp.schema, mediaType, `&${target}`)}\n`; text += '}\n\n'; return text; } @@ -843,6 +848,9 @@ function createInterfaceDefinition(group: OperationGroup, imports: ImportManager if (hasDescription(op.language.go!)) { interfaceText += `\t// ${opName} - ${op.language.go!.description} \n`; } + if (isMultiRespOperation(op)) { + interfaceText += generateMultiRespComment(op); + } const returns = generateReturnsInfo(op, false); interfaceText += `\t${opName}(${getAPIParametersSig(op, imports)}) (${returns.join(', ')})\n`; // Add resume LRO poller method for each Begin poller method @@ -884,50 +892,48 @@ function formatConstantValue(schema: ConstantSchema) { function formatStatusCodes(statusCodes: Array): string { const asHTTPStatus = new Array(); for (const rawCode of values(statusCodes)) { - switch (rawCode) { - case '200': - asHTTPStatus.push('http.StatusOK'); - break; - case '201': - asHTTPStatus.push('http.StatusCreated'); - break; - case '202': - asHTTPStatus.push('http.StatusAccepted'); - break; - case '204': - asHTTPStatus.push('http.StatusNoContent'); - break; - case '300': - asHTTPStatus.push('http.StatusMultipleChoices'); - break; - case '301': - asHTTPStatus.push('http.StatusMovedPermanently'); - break; - case '302': - asHTTPStatus.push('http.StatusFound'); - break; - case '400': - asHTTPStatus.push('http.StatusBadRequest'); - break; - case '404': - asHTTPStatus.push('http.StatusNotFound'); - break; - case '409': - asHTTPStatus.push('http.StatusConflict'); - break; - case '500': - asHTTPStatus.push('http.StatusInternalServerError'); - break; - case '501': - asHTTPStatus.push('http.StatusNotImplemented'); - break; - default: - throw console.error(`unhandled status code ${rawCode}`); - } + asHTTPStatus.push(formatStatusCode(rawCode)); } return asHTTPStatus.join(', '); } +function formatStatusCode(statusCode: string): string { + switch (statusCode) { + case '200': + return 'http.StatusOK'; + case '201': + return 'http.StatusCreated'; + case '202': + return 'http.StatusAccepted'; + case '204': + return 'http.StatusNoContent'; + case '206': + return 'http.StatusPartialContent'; + case '300': + return 'http.StatusMultipleChoices'; + case '301': + return 'http.StatusMovedPermanently'; + case '302': + return 'http.StatusFound'; + case '303': + return 'http.StatusSeeOther'; + case '307': + return 'http.StatusTemporaryRedirect'; + case '400': + return 'http.StatusBadRequest'; + case '404': + return 'http.StatusNotFound'; + case '409': + return 'http.StatusConflict'; + case '500': + return 'http.StatusInternalServerError'; + case '501': + return 'http.StatusNotImplemented'; + default: + throw console.error(`unhandled status code ${statusCode}`); + } +} + // returns true if any responses are a binary stream function hasBinaryResponse(responses: Response[]): boolean { for (const resp of values(responses)) { @@ -1012,16 +1018,19 @@ function generateReturnsInfo(op: Operation, forHandler: boolean): string[] { if (!op.responses) { return ['*http.Response', 'error']; } - // TODO check this implementation, if any additional return information needs to be included for multiple responses - const firstResp = op.responses![0]; let returnType = '*http.Response'; - // must check pageable first as all pageable operations are also schema responses - if (!forHandler && isPageableOperation(op)) { - returnType = op.language.go!.pageableType.name; - } else if (isSchemaResponse(firstResp)) { - returnType = '*' + firstResp.schema.language.go!.responseType.name; - } else if (isLROOperation(op)) { - returnType = '*HTTPResponse'; + if (isMultiRespOperation(op)) { + returnType = 'interface{}'; + } else { + const firstResp = op.responses![0]; + // must check pageable first as all pageable operations are also schema responses + if (!forHandler && isPageableOperation(op)) { + returnType = op.language.go!.pageableType.name; + } else if (isSchemaResponse(firstResp)) { + returnType = '*' + firstResp.schema.language.go!.responseType.name; + } else if (isLROOperation(op)) { + returnType = '*HTTPResponse'; + } } return [returnType, 'error']; } @@ -1040,3 +1049,32 @@ function addResumePollerMethod(op: Operation, clientName: string): string { text += '}\n\n'; return text; } + +// returns true if the operation returns multiple response types +function isMultiRespOperation(op: Operation): boolean { + // treat LROs as single-response ops + if (!op.responses || op.responses?.length === 1 || isLROOperation(op)) { + return false; + } + // count the number of schemas returned by this operation + let schemaCount = 0; + let currentResp = op.responses![0]; + if (isSchemaResponse(currentResp)) { + ++schemaCount; + } + // check that all response types are identical + for (let i = 1; i < op.responses!.length; ++i) { + const response = op.responses![i]; + if (isSchemaResponse(response) && isSchemaResponse(currentResp)) { + // both are schema responses, ensure they match + if ((response).schema !== (currentResp).schema) { + ++schemaCount; + } + } else if (isSchemaResponse(response) && !isSchemaResponse(currentResp)) { + ++schemaCount; + // update currentResp to this response so we can compare it against the remaining responses + currentResp = response; + } + } + return schemaCount > 1; +} diff --git a/src/package.json b/src/package.json index 1bef72335..cd88f82b4 100644 --- a/src/package.json +++ b/src/package.json @@ -51,7 +51,7 @@ "typescript": "~3.7.2", "@typescript-eslint/eslint-plugin": "~2.6.0", "@typescript-eslint/parser": "~2.6.0", - "@microsoft.azure/autorest.testserver": "2.10.41", + "@microsoft.azure/autorest.testserver": "2.10.42", "@autorest/autorest": "~3.0.6173", "eslint": "~6.6.0", "@azure-tools/codegen": "~2.4.263", diff --git a/src/transform/transform.ts b/src/transform/transform.ts index 828b18284..bbf0f9994 100644 --- a/src/transform/transform.ts +++ b/src/transform/transform.ts @@ -5,7 +5,7 @@ import { camelCase, KnownMediaType, pascalCase, serialize } from '@azure-tools/codegen'; import { Host, startSession, Session } from '@azure-tools/autorest-extension-base'; -import { ObjectSchema, ArraySchema, ChoiceValue, codeModelSchema, CodeModel, DateTimeSchema, GroupProperty, HttpHeader, HttpResponse, ImplementationLocation, Language, OperationGroup, SchemaType, NumberSchema, Operation, SchemaResponse, Parameter, Property, Protocols, Schema, DictionarySchema, Protocol, ChoiceSchema, SealedChoiceSchema, ConstantSchema } from '@azure-tools/codemodel'; +import { ObjectSchema, ArraySchema, ChoiceValue, codeModelSchema, CodeModel, DateTimeSchema, GroupProperty, HttpHeader, HttpResponse, ImplementationLocation, Language, OperationGroup, SchemaType, NumberSchema, Operation, SchemaResponse, Parameter, Property, Protocols, Response, Schema, DictionarySchema, Protocol, ChoiceSchema, SealedChoiceSchema, ConstantSchema } from '@azure-tools/codemodel'; import { items, values } from '@azure-tools/linq'; import { aggregateParameters, isPageableOperation, isObjectSchema, isSchemaResponse, PagerInfo, isLROOperation, PollerInfo } from '../common/helpers'; import { namer, removePrefix } from './namer'; @@ -378,8 +378,17 @@ function processOperationResponses(session: Session) { schemaError.language.go!.errorType = true; recursiveAddMarshallingFormat(schemaError, marshallingFormat); } - // recursively add the marshalling format to the responses if applicable + if (!op.responses) { + continue; + } + // recursively add the marshalling format to the responses if applicable. + // also remove any HTTP redirects from the list of responses. + const filtered = new Array(); for (const resp of values(op.responses)) { + if (skipRedirectStatusCode(op.requests![0].protocol.http!.method, resp)) { + // redirects are transient status codes, they aren't actually returned + continue; + } if (isSchemaResponse(resp)) { resp.schema.language.go!.name = schemaTypeToGoType(session.model, resp.schema, true); } @@ -392,12 +401,45 @@ function processOperationResponses(session: Session) { for (const header of values(httpResponse.headers)) { header.schema.language.go!.name = schemaTypeToGoType(session.model, header.schema, false); } + filtered.push(resp); + } + // replace with the filtered list if applicable + if (filtered.length === 0) { + // handling of operations with no responses expects an undefined list, not an empty one + op.responses = undefined; + } else if (op.responses.length !== filtered.length) { + op.responses = filtered; } createResponseType(session.model, group, op); } } } +// returns true if the specified status code is an automatic HTTP redirect. +// certain redirects are automatically handled by the HTTP stack and thus are +// transient so they are never actually returned to the caller. we skip them +// so they aren't included in the potential result set of an operation. +function skipRedirectStatusCode(verb: string, resp: Response): boolean { + const statusCodes = >resp.protocol.http!.statusCodes; + if (statusCodes.length > 1) { + return false; + } + // taken from src/net/http/client.go in the gostdlib + switch (statusCodes[0]) { + case '301': + case '302': + case '303': + if (verb === 'get' || verb === 'head') { + return true; + } + break; + case '307': + case '308': + return true; + } + return false; +} + interface HttpHeaderWithDescription extends HttpHeader { description: string; } @@ -406,10 +448,7 @@ interface HttpHeaderWithDescription extends HttpHeader { function createResponseType(codeModel: CodeModel, group: OperationGroup, op: Operation) { // create the `type Response struct` response // type with a `RawResponse *http.Response` field - if (!op.responses) { - return; - } - const firstResp = op.responses![0]; + // when receiving multiple possible responses, they might expect the same headers in many cases // we use a map to only add unique headers to the response model based on the header name const headers = new Map(); @@ -433,180 +472,180 @@ function createResponseType(codeModel: CodeModel, group: OperationGroup, op: Ope // if the response defines a schema then add it as a field to the response type. // only do this if the response schema hasn't been processed yet. - - if (!isSchemaResponse(firstResp)) { - // the response doesn't return a model. if it returns - // headers then create a model that contains them. - if (isLROOperation(op)) { - const name = 'HTTPResponse'; - const description = `${name} contains the HTTP response from the call to the service endpoint`; - const object = new ObjectSchema(name, description); - object.language.go = object.language.default; - const pollUntilDone = newProperty('PollUntilDone', 'PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received', newObject('func(ctx context.Context, frequency time.Duration) (*http.Response, error)', 'TODO')); - const getPoller = newProperty('Poller', 'Poller contains an initialized poller', newObject('HTTPPoller', 'TODO')); - pollUntilDone.schema.language.go!.lroPointerException = true; - getPoller.schema.language.go!.lroPointerException = true; - object.language.go!.properties = [ - newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'raw HTTP response')), - pollUntilDone, - getPoller - ]; - // mark as a response type - object.language.go!.responseType = { - name: name, - description: description, - responseType: true, - }; - if (!responseExists(codeModel, object.language.go!.responseType.name)) { - // add this response schema to the global list of response - const responseSchemas = >codeModel.language.go!.responseSchemas; - responseSchemas.push(object); - // attach it to the response - (firstResp).schema = object; - } - } else if (headers.size > 0) { - const name = `${group.language.go!.name}${op.language.go!.name}Response`; - const description = `${name} contains the response from method ${group.language.go!.name}.${op.language.go!.name}.`; - const object = new ObjectSchema(name, description); - object.language.go = object.language.default; - object.language.go!.properties = [ - newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'raw HTTP response')) + for (const response of values(op.responses)) { + if (!isSchemaResponse(response)) { + // the response doesn't return a model. if it returns + // headers then create a model that contains them. + if (isLROOperation(op)) { + const name = 'HTTPResponse'; + const description = `${name} contains the HTTP response from the call to the service endpoint`; + const object = new ObjectSchema(name, description); + object.language.go = object.language.default; + const pollUntilDone = newProperty('PollUntilDone', 'PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received', newObject('func(ctx context.Context, frequency time.Duration) (*http.Response, error)', 'TODO')); + const getPoller = newProperty('Poller', 'Poller contains an initialized poller', newObject('HTTPPoller', 'TODO')); + pollUntilDone.schema.language.go!.lroPointerException = true; + getPoller.schema.language.go!.lroPointerException = true; + object.language.go!.properties = [ + newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'raw HTTP response')), + pollUntilDone, + getPoller + ]; + // mark as a response type + object.language.go!.responseType = { + name: name, + description: description, + responseType: true, + }; + if (!responseExists(codeModel, object.language.go!.responseType.name)) { + // add this response schema to the global list of response + const responseSchemas = >codeModel.language.go!.responseSchemas; + responseSchemas.push(object); + // attach it to the response + (response).schema = object; + } + } else if (headers.size > 0) { + const name = `${group.language.go!.name}${op.language.go!.name}Response`; + const description = `${name} contains the response from method ${group.language.go!.name}.${op.language.go!.name}.`; + const object = new ObjectSchema(name, description); + object.language.go = object.language.default; + object.language.go!.properties = [ + newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'raw HTTP response')) + ]; + for (const item of items(headers)) { + const prop = newProperty(item.key, item.value.description, item.value.schema); + prop.language.go!.fromHeader = item.value.header; + (>object.language.go!.properties).push(prop); + } + // mark as a response type + object.language.go!.responseType = { + name: name, + description: description, + responseType: true, + } + if (!responseExists(codeModel, object.language.go!.responseType.name)) { + // add this response schema to the global list of response + const responseSchemas = >codeModel.language.go!.responseSchemas; + responseSchemas.push(object); + // attach it to the response + (response).schema = object; + } + } + } else if (!responseTypeCreated(codeModel, response.schema) || isLROOperation(op)) { + response.schema.language.go!.responseType = generateResponseTypeName(response.schema); + response.schema.language.go!.properties = [ + newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'TODO')) ]; + const marshallingFormat = getMarshallingFormat(response.protocol); + response.schema.language.go!.responseType.marshallingFormat = marshallingFormat; + // for operations that return scalar types we use a fixed field name 'Value' + let propName = 'Value'; + if (response.schema.type === SchemaType.Object) { + // for object types use the type's name as the field name + propName = response.schema.language.go!.name; + } else if (response.schema.type === SchemaType.Array) { + // for array types use the element type's name + propName = recursiveTypeName(response.schema); + } + if (response.schema.serialization?.xml && response.schema.serialization.xml.name) { + // always prefer the XML name + propName = pascalCase(response.schema.serialization.xml.name); + } + response.schema.language.go!.responseType.value = propName; + (>response.schema.language.go!.properties).push(newProperty(propName, response.schema.language.go!.description, response.schema)); + // add any headers to the response type for (const item of items(headers)) { const prop = newProperty(item.key, item.value.description, item.value.schema); prop.language.go!.fromHeader = item.value.header; - (>object.language.go!.properties).push(prop); + (>response.schema.language.go!.properties).push(prop); } - // mark as a response type - object.language.go!.responseType = { - name: name, - description: description, - responseType: true, + if (isLROOperation(op)) { + response.schema.language.go!.isLRO = true; + let prop = newProperty('PollUntilDone', 'PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received', newObject(`func(ctx context.Context, frequency time.Duration) (*${response.schema.language.go!.responseType.name}, error)`, 'TODO')); + prop.schema.language.go!.lroPointerException = true; + (>response.schema.language.go!.properties).push(prop); + prop = newProperty('Poller', 'Poller contains an initialized poller', newObject(`${response.schema.language.go!.responseType.value}Poller`, 'TODO')); + prop.schema.language.go!.lroPointerException = true; + (>response.schema.language.go!.properties).push(prop); } - if (!responseExists(codeModel, object.language.go!.responseType.name)) { + if (!responseExists(codeModel, response.schema.language.go!.name)) { // add this response schema to the global list of response const responseSchemas = >codeModel.language.go!.responseSchemas; - responseSchemas.push(object); - // attach it to the response - (firstResp).schema = object; + responseSchemas.push(response.schema); + } else if (isLROOperation(op)) { + // add this response schema with LRO fields to the global list of responses by + // replacing the previously added response with the same name + const responseSchemas = >codeModel.language.go!.responseSchemas; + for (let i = 0; i < responseSchemas.length; i++) { + if (responseSchemas[i].language.go!.name === response.schema.language.go!.name) { + responseSchemas.splice(i, 1, response.schema); + } + } } } - } else if (!responseTypeCreated(codeModel, firstResp.schema) || isLROOperation(op)) { - firstResp.schema.language.go!.responseType = generateResponseTypeName(firstResp.schema); - firstResp.schema.language.go!.properties = [ - newProperty('RawResponse', 'RawResponse contains the underlying HTTP response.', newObject('http.Response', 'TODO')) - ]; - const marshallingFormat = getMarshallingFormat(firstResp.protocol); - firstResp.schema.language.go!.responseType.marshallingFormat = marshallingFormat; - // for operations that return scalar types we use a fixed field name 'Value' - let propName = 'Value'; - if (firstResp.schema.type === SchemaType.Object) { - // for object types use the type's name as the field name - propName = firstResp.schema.language.go!.name; - } else if (firstResp.schema.type === SchemaType.Array) { - // for array types use the element type's name - propName = recursiveTypeName(firstResp.schema); - } - if (firstResp.schema.serialization?.xml && firstResp.schema.serialization.xml.name) { - // always prefer the XML name - propName = pascalCase(firstResp.schema.serialization.xml.name); - } - firstResp.schema.language.go!.responseType.value = propName; - (>firstResp.schema.language.go!.properties).push(newProperty(propName, firstResp.schema.language.go!.description, firstResp.schema)); - // add any headers to the response type - for (const item of items(headers)) { - const prop = newProperty(item.key, item.value.description, item.value.schema); - prop.language.go!.fromHeader = item.value.header; - (>firstResp.schema.language.go!.properties).push(prop); - } - if (isLROOperation(op)) { - firstResp.schema.language.go!.isLRO = true; - let prop = newProperty('PollUntilDone', 'PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received', newObject(`func(ctx context.Context, frequency time.Duration) (*${firstResp.schema.language.go!.responseType.name}, error)`, 'TODO')); - prop.schema.language.go!.lroPointerException = true; - (>firstResp.schema.language.go!.properties).push(prop); - prop = newProperty('Poller', 'Poller contains an initialized poller', newObject(`${firstResp.schema.language.go!.responseType.value}Poller`, 'TODO')); - prop.schema.language.go!.lroPointerException = true; - (>firstResp.schema.language.go!.properties).push(prop); - } - if (!responseExists(codeModel, firstResp.schema.language.go!.name)) { - // add this response schema to the global list of response - const responseSchemas = >codeModel.language.go!.responseSchemas; - responseSchemas.push(firstResp.schema); - } else if (isLROOperation(op)) { - // add this response schema with LRO fields to the global list of responses by - // replacing the previously added response with the same name - const responseSchemas = >codeModel.language.go!.responseSchemas; - for (let i = 0; i < responseSchemas.length; i++) { - if (responseSchemas[i].language.go!.name === firstResp.schema.language.go!.name) { - responseSchemas.splice(i, 1, firstResp.schema); + // create pageable type info + if (isPageableOperation(op)) { + if (codeModel.language.go!.pageableTypes === undefined) { + codeModel.language.go!.pageableTypes = new Array(); + } + const name = `${(response).schema.language.go!.name}Pager`; + // check to see if the pager has already been created + let skipAddPager = false; // skipAdd allows not adding the pager to the list of pageable types and continue on to LRO check + const pagers = >codeModel.language.go!.pageableTypes; + for (const pager of values(pagers)) { + if (pager.name === name) { + // found a match, hook it up to the method + op.language.go!.pageableType = pager; + skipAddPager = true; + break; } } - } - } - // create pageable type info - if (isPageableOperation(op)) { - if (codeModel.language.go!.pageableTypes === undefined) { - codeModel.language.go!.pageableTypes = new Array(); - } - const name = `${(firstResp).schema.language.go!.name}Pager`; - // check to see if the pager has already been created - let skipAddPager = false; // skipAdd allows not adding the pager to the list of pageable types and continue on to LRO check - const pagers = >codeModel.language.go!.pageableTypes; - for (const pager of values(pagers)) { - if (pager.name === name) { - // found a match, hook it up to the method + if (!skipAddPager) { + // create a new one, add to global list and assign to method + const pager = { + name: name, + op: op, + }; + pagers.push(pager); op.language.go!.pageableType = pager; - skipAddPager = true; - break; } } - if (!skipAddPager) { - // create a new one, add to global list and assign to method - const pager = { - name: name, - op: op, - }; - pagers.push(pager); - op.language.go!.pageableType = pager; - } - } - // create poller type info - if (isLROOperation(op)) { - if (codeModel.language.go!.pollerTypes === undefined) { - codeModel.language.go!.pollerTypes = new Array(); - } - // Determine the type of poller that needs to be added based on whether a schema is specified in the response - // if there is no schema specified for the operation response then a simple HTTP poller will be instantiated - let type = 'HTTP'; - if (isSchemaResponse(firstResp) && firstResp.schema.language.go!.responseType.value) { - type = firstResp.schema.language.go!.responseType.value; - } - const name = `${type}Poller`; - const pollers = >codeModel.language.go!.pollerTypes; - let skipAddLRO = false; - for (const poller of values(pollers)) { - if (poller.name === name) { - // found a match, hook it up to the method - const tempPoller = { - name: poller.name, - responseType: poller.responseType, + // create poller type info + if (isLROOperation(op)) { + if (codeModel.language.go!.pollerTypes === undefined) { + codeModel.language.go!.pollerTypes = new Array(); + } + // Determine the type of poller that needs to be added based on whether a schema is specified in the response + // if there is no schema specified for the operation response then a simple HTTP poller will be instantiated + let type = 'HTTP'; + if (isSchemaResponse(response) && response.schema.language.go!.responseType.value) { + type = response.schema.language.go!.responseType.value; + } + const name = `${type}Poller`; + const pollers = >codeModel.language.go!.pollerTypes; + let skipAddLRO = false; + for (const poller of values(pollers)) { + if (poller.name === name) { + // found a match, hook it up to the method + op.language.go!.pollerType = poller; + skipAddLRO = true; + break; + } + } + if (!skipAddLRO) { + // Adding the operation group name to the poller name for polling operations that need to be unique to that operation group + // create a new one, add to global list and assign to method + const poller = { + name: name, + responseType: type, op: op, }; - op.language.go!.pollerType = tempPoller; - skipAddLRO = true; - break; + pollers.push(poller); + op.language.go!.pollerType = poller; } } - if (!skipAddLRO) { - // Adding the operation group name to the poller name for polling operations that need to be unique to that operation group - // create a new one, add to global list and assign to method - const poller = { - name: name, - responseType: type, - op: op, - }; - pollers.push(poller); - op.language.go!.pollerType = poller; + if (isLROOperation(op)) { + // treat LROs as single-response ops + break; } } } diff --git a/test/autorest/generated/azurespecialsgroup/header.go b/test/autorest/generated/azurespecialsgroup/header.go index 4649bdc97..0d6cab110 100644 --- a/test/autorest/generated/azurespecialsgroup/header.go +++ b/test/autorest/generated/azurespecialsgroup/header.go @@ -107,7 +107,7 @@ func (client *headerOperations) customNamedRequestIdHeadCreateRequest(fooClientR // customNamedRequestIdHeadHandleResponse handles the CustomNamedRequestIDHead response. func (client *headerOperations) customNamedRequestIdHeadHandleResponse(resp *azcore.Response) (*HeaderCustomNamedRequestIDHeadResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNotFound) { return nil, client.customNamedRequestIdHeadHandleError(resp) } result := HeaderCustomNamedRequestIDHeadResponse{RawResponse: resp.Response} diff --git a/test/autorest/generated/errorsgroup/pet.go b/test/autorest/generated/errorsgroup/pet.go index 62fa17999..d5e997961 100644 --- a/test/autorest/generated/errorsgroup/pet.go +++ b/test/autorest/generated/errorsgroup/pet.go @@ -115,7 +115,7 @@ func (client *petOperations) getPetByIdCreateRequest(petId string) (*azcore.Requ // getPetByIdHandleResponse handles the GetPetByID response. func (client *petOperations) getPetByIdHandleResponse(resp *azcore.Response) (*PetResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { return nil, client.getPetByIdHandleError(resp) } result := PetResponse{RawResponse: resp.Response} diff --git a/test/autorest/generated/httpinfrastructuregroup/httpredirects.go b/test/autorest/generated/httpinfrastructuregroup/httpredirects.go index 2152a3a19..bfff88f53 100644 --- a/test/autorest/generated/httpinfrastructuregroup/httpredirects.go +++ b/test/autorest/generated/httpinfrastructuregroup/httpredirects.go @@ -14,37 +14,38 @@ import ( // HTTPRedirectsOperations contains the methods for the HTTPRedirects group. type HTTPRedirectsOperations interface { // Delete307 - Delete redirected with 307, resulting in a 200 after redirect - Delete307(ctx context.Context) (*HTTPRedirectsDelete307Response, error) + Delete307(ctx context.Context) (*http.Response, error) // Get300 - Return 300 status code and redirect to /http/success/200 - Get300(ctx context.Context) (*HTTPRedirectsGet300Response, error) + // Possible return types are *HTTPRedirectsGet300Response, *StringArrayResponse + Get300(ctx context.Context) (interface{}, error) // Get301 - Return 301 status code and redirect to /http/success/200 - Get301(ctx context.Context) (*HTTPRedirectsGet301Response, error) + Get301(ctx context.Context) (*http.Response, error) // Get302 - Return 302 status code and redirect to /http/success/200 - Get302(ctx context.Context) (*HTTPRedirectsGet302Response, error) + Get302(ctx context.Context) (*http.Response, error) // Get307 - Redirect get with 307, resulting in a 200 success - Get307(ctx context.Context) (*HTTPRedirectsGet307Response, error) + Get307(ctx context.Context) (*http.Response, error) // Head300 - Return 300 status code and redirect to /http/success/200 Head300(ctx context.Context) (*HTTPRedirectsHead300Response, error) // Head301 - Return 301 status code and redirect to /http/success/200 - Head301(ctx context.Context) (*HTTPRedirectsHead301Response, error) + Head301(ctx context.Context) (*http.Response, error) // Head302 - Return 302 status code and redirect to /http/success/200 - Head302(ctx context.Context) (*HTTPRedirectsHead302Response, error) + Head302(ctx context.Context) (*http.Response, error) // Head307 - Redirect with 307, resulting in a 200 success - Head307(ctx context.Context) (*HTTPRedirectsHead307Response, error) + Head307(ctx context.Context) (*http.Response, error) // Options307 - options redirected with 307, resulting in a 200 after redirect - Options307(ctx context.Context) (*HTTPRedirectsOptions307Response, error) + Options307(ctx context.Context) (*http.Response, error) // Patch302 - Patch true Boolean value in request returns 302. This request should not be automatically redirected, but should return the received 302 to the caller for evaluation Patch302(ctx context.Context) (*HTTPRedirectsPatch302Response, error) // Patch307 - Patch redirected with 307, resulting in a 200 after redirect - Patch307(ctx context.Context) (*HTTPRedirectsPatch307Response, error) + Patch307(ctx context.Context) (*http.Response, error) // Post303 - Post true Boolean value in request returns 303. This request should be automatically redirected usign a get, ultimately returning a 200 status code Post303(ctx context.Context) (*HTTPRedirectsPost303Response, error) // Post307 - Post redirected with 307, resulting in a 200 after redirect - Post307(ctx context.Context) (*HTTPRedirectsPost307Response, error) + Post307(ctx context.Context) (*http.Response, error) // Put301 - Put true Boolean value in request returns 301. This request should not be automatically redirected, but should return the received 301 to the caller for evaluation Put301(ctx context.Context) (*HTTPRedirectsPut301Response, error) // Put307 - Put redirected with 307, resulting in a 200 after redirect - Put307(ctx context.Context) (*HTTPRedirectsPut307Response, error) + Put307(ctx context.Context) (*http.Response, error) } // httpRedirectsOperations implements the HTTPRedirectsOperations interface. @@ -53,7 +54,7 @@ type httpRedirectsOperations struct { } // Delete307 - Delete redirected with 307, resulting in a 200 after redirect -func (client *httpRedirectsOperations) Delete307(ctx context.Context) (*HTTPRedirectsDelete307Response, error) { +func (client *httpRedirectsOperations) Delete307(ctx context.Context) (*http.Response, error) { req, err := client.delete307CreateRequest() if err != nil { return nil, err @@ -81,15 +82,11 @@ func (client *httpRedirectsOperations) delete307CreateRequest() (*azcore.Request } // delete307HandleResponse handles the Delete307 response. -func (client *httpRedirectsOperations) delete307HandleResponse(resp *azcore.Response) (*HTTPRedirectsDelete307Response, error) { +func (client *httpRedirectsOperations) delete307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.delete307HandleError(resp) } - result := HTTPRedirectsDelete307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // delete307HandleError handles the Delete307 error response. @@ -102,7 +99,8 @@ func (client *httpRedirectsOperations) delete307HandleError(resp *azcore.Respons } // Get300 - Return 300 status code and redirect to /http/success/200 -func (client *httpRedirectsOperations) Get300(ctx context.Context) (*HTTPRedirectsGet300Response, error) { +// Possible return types are *HTTPRedirectsGet300Response, *StringArrayResponse +func (client *httpRedirectsOperations) Get300(ctx context.Context) (interface{}, error) { req, err := client.get300CreateRequest() if err != nil { return nil, err @@ -130,15 +128,23 @@ func (client *httpRedirectsOperations) get300CreateRequest() (*azcore.Request, e } // get300HandleResponse handles the Get300 response. -func (client *httpRedirectsOperations) get300HandleResponse(resp *azcore.Response) (*HTTPRedirectsGet300Response, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *httpRedirectsOperations) get300HandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := HTTPRedirectsGet300Response{RawResponse: resp.Response} + if val := resp.Header.Get("Location"); val != "" { + result.Location = &val + } + return &result, nil + case http.StatusMultipleChoices: + result := StringArrayResponse{RawResponse: resp.Response} + if val := resp.Header.Get("Location"); val != "" { + result.Location = &val + } + return &result, resp.UnmarshalAsJSON(&result.StringArray) + default: return nil, client.get300HandleError(resp) } - result := HTTPRedirectsGet300Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil } // get300HandleError handles the Get300 error response. @@ -151,7 +157,7 @@ func (client *httpRedirectsOperations) get300HandleError(resp *azcore.Response) } // Get301 - Return 301 status code and redirect to /http/success/200 -func (client *httpRedirectsOperations) Get301(ctx context.Context) (*HTTPRedirectsGet301Response, error) { +func (client *httpRedirectsOperations) Get301(ctx context.Context) (*http.Response, error) { req, err := client.get301CreateRequest() if err != nil { return nil, err @@ -179,15 +185,11 @@ func (client *httpRedirectsOperations) get301CreateRequest() (*azcore.Request, e } // get301HandleResponse handles the Get301 response. -func (client *httpRedirectsOperations) get301HandleResponse(resp *azcore.Response) (*HTTPRedirectsGet301Response, error) { +func (client *httpRedirectsOperations) get301HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.get301HandleError(resp) } - result := HTTPRedirectsGet301Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // get301HandleError handles the Get301 error response. @@ -200,7 +202,7 @@ func (client *httpRedirectsOperations) get301HandleError(resp *azcore.Response) } // Get302 - Return 302 status code and redirect to /http/success/200 -func (client *httpRedirectsOperations) Get302(ctx context.Context) (*HTTPRedirectsGet302Response, error) { +func (client *httpRedirectsOperations) Get302(ctx context.Context) (*http.Response, error) { req, err := client.get302CreateRequest() if err != nil { return nil, err @@ -228,15 +230,11 @@ func (client *httpRedirectsOperations) get302CreateRequest() (*azcore.Request, e } // get302HandleResponse handles the Get302 response. -func (client *httpRedirectsOperations) get302HandleResponse(resp *azcore.Response) (*HTTPRedirectsGet302Response, error) { +func (client *httpRedirectsOperations) get302HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.get302HandleError(resp) } - result := HTTPRedirectsGet302Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // get302HandleError handles the Get302 error response. @@ -249,7 +247,7 @@ func (client *httpRedirectsOperations) get302HandleError(resp *azcore.Response) } // Get307 - Redirect get with 307, resulting in a 200 success -func (client *httpRedirectsOperations) Get307(ctx context.Context) (*HTTPRedirectsGet307Response, error) { +func (client *httpRedirectsOperations) Get307(ctx context.Context) (*http.Response, error) { req, err := client.get307CreateRequest() if err != nil { return nil, err @@ -277,15 +275,11 @@ func (client *httpRedirectsOperations) get307CreateRequest() (*azcore.Request, e } // get307HandleResponse handles the Get307 response. -func (client *httpRedirectsOperations) get307HandleResponse(resp *azcore.Response) (*HTTPRedirectsGet307Response, error) { +func (client *httpRedirectsOperations) get307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.get307HandleError(resp) } - result := HTTPRedirectsGet307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // get307HandleError handles the Get307 error response. @@ -327,7 +321,7 @@ func (client *httpRedirectsOperations) head300CreateRequest() (*azcore.Request, // head300HandleResponse handles the Head300 response. func (client *httpRedirectsOperations) head300HandleResponse(resp *azcore.Response) (*HTTPRedirectsHead300Response, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusMultipleChoices) { return nil, client.head300HandleError(resp) } result := HTTPRedirectsHead300Response{RawResponse: resp.Response} @@ -347,7 +341,7 @@ func (client *httpRedirectsOperations) head300HandleError(resp *azcore.Response) } // Head301 - Return 301 status code and redirect to /http/success/200 -func (client *httpRedirectsOperations) Head301(ctx context.Context) (*HTTPRedirectsHead301Response, error) { +func (client *httpRedirectsOperations) Head301(ctx context.Context) (*http.Response, error) { req, err := client.head301CreateRequest() if err != nil { return nil, err @@ -375,15 +369,11 @@ func (client *httpRedirectsOperations) head301CreateRequest() (*azcore.Request, } // head301HandleResponse handles the Head301 response. -func (client *httpRedirectsOperations) head301HandleResponse(resp *azcore.Response) (*HTTPRedirectsHead301Response, error) { +func (client *httpRedirectsOperations) head301HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.head301HandleError(resp) } - result := HTTPRedirectsHead301Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // head301HandleError handles the Head301 error response. @@ -396,7 +386,7 @@ func (client *httpRedirectsOperations) head301HandleError(resp *azcore.Response) } // Head302 - Return 302 status code and redirect to /http/success/200 -func (client *httpRedirectsOperations) Head302(ctx context.Context) (*HTTPRedirectsHead302Response, error) { +func (client *httpRedirectsOperations) Head302(ctx context.Context) (*http.Response, error) { req, err := client.head302CreateRequest() if err != nil { return nil, err @@ -424,15 +414,11 @@ func (client *httpRedirectsOperations) head302CreateRequest() (*azcore.Request, } // head302HandleResponse handles the Head302 response. -func (client *httpRedirectsOperations) head302HandleResponse(resp *azcore.Response) (*HTTPRedirectsHead302Response, error) { +func (client *httpRedirectsOperations) head302HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.head302HandleError(resp) } - result := HTTPRedirectsHead302Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // head302HandleError handles the Head302 error response. @@ -445,7 +431,7 @@ func (client *httpRedirectsOperations) head302HandleError(resp *azcore.Response) } // Head307 - Redirect with 307, resulting in a 200 success -func (client *httpRedirectsOperations) Head307(ctx context.Context) (*HTTPRedirectsHead307Response, error) { +func (client *httpRedirectsOperations) Head307(ctx context.Context) (*http.Response, error) { req, err := client.head307CreateRequest() if err != nil { return nil, err @@ -473,15 +459,11 @@ func (client *httpRedirectsOperations) head307CreateRequest() (*azcore.Request, } // head307HandleResponse handles the Head307 response. -func (client *httpRedirectsOperations) head307HandleResponse(resp *azcore.Response) (*HTTPRedirectsHead307Response, error) { +func (client *httpRedirectsOperations) head307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.head307HandleError(resp) } - result := HTTPRedirectsHead307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // head307HandleError handles the Head307 error response. @@ -494,7 +476,7 @@ func (client *httpRedirectsOperations) head307HandleError(resp *azcore.Response) } // Options307 - options redirected with 307, resulting in a 200 after redirect -func (client *httpRedirectsOperations) Options307(ctx context.Context) (*HTTPRedirectsOptions307Response, error) { +func (client *httpRedirectsOperations) Options307(ctx context.Context) (*http.Response, error) { req, err := client.options307CreateRequest() if err != nil { return nil, err @@ -522,15 +504,11 @@ func (client *httpRedirectsOperations) options307CreateRequest() (*azcore.Reques } // options307HandleResponse handles the Options307 response. -func (client *httpRedirectsOperations) options307HandleResponse(resp *azcore.Response) (*HTTPRedirectsOptions307Response, error) { +func (client *httpRedirectsOperations) options307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.options307HandleError(resp) } - result := HTTPRedirectsOptions307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // options307HandleError handles the Options307 error response. @@ -592,7 +570,7 @@ func (client *httpRedirectsOperations) patch302HandleError(resp *azcore.Response } // Patch307 - Patch redirected with 307, resulting in a 200 after redirect -func (client *httpRedirectsOperations) Patch307(ctx context.Context) (*HTTPRedirectsPatch307Response, error) { +func (client *httpRedirectsOperations) Patch307(ctx context.Context) (*http.Response, error) { req, err := client.patch307CreateRequest() if err != nil { return nil, err @@ -620,15 +598,11 @@ func (client *httpRedirectsOperations) patch307CreateRequest() (*azcore.Request, } // patch307HandleResponse handles the Patch307 response. -func (client *httpRedirectsOperations) patch307HandleResponse(resp *azcore.Response) (*HTTPRedirectsPatch307Response, error) { +func (client *httpRedirectsOperations) patch307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.patch307HandleError(resp) } - result := HTTPRedirectsPatch307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // patch307HandleError handles the Patch307 error response. @@ -670,7 +644,7 @@ func (client *httpRedirectsOperations) post303CreateRequest() (*azcore.Request, // post303HandleResponse handles the Post303 response. func (client *httpRedirectsOperations) post303HandleResponse(resp *azcore.Response) (*HTTPRedirectsPost303Response, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusSeeOther) { return nil, client.post303HandleError(resp) } result := HTTPRedirectsPost303Response{RawResponse: resp.Response} @@ -690,7 +664,7 @@ func (client *httpRedirectsOperations) post303HandleError(resp *azcore.Response) } // Post307 - Post redirected with 307, resulting in a 200 after redirect -func (client *httpRedirectsOperations) Post307(ctx context.Context) (*HTTPRedirectsPost307Response, error) { +func (client *httpRedirectsOperations) Post307(ctx context.Context) (*http.Response, error) { req, err := client.post307CreateRequest() if err != nil { return nil, err @@ -718,15 +692,11 @@ func (client *httpRedirectsOperations) post307CreateRequest() (*azcore.Request, } // post307HandleResponse handles the Post307 response. -func (client *httpRedirectsOperations) post307HandleResponse(resp *azcore.Response) (*HTTPRedirectsPost307Response, error) { +func (client *httpRedirectsOperations) post307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.post307HandleError(resp) } - result := HTTPRedirectsPost307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // post307HandleError handles the Post307 error response. @@ -788,7 +758,7 @@ func (client *httpRedirectsOperations) put301HandleError(resp *azcore.Response) } // Put307 - Put redirected with 307, resulting in a 200 after redirect -func (client *httpRedirectsOperations) Put307(ctx context.Context) (*HTTPRedirectsPut307Response, error) { +func (client *httpRedirectsOperations) Put307(ctx context.Context) (*http.Response, error) { req, err := client.put307CreateRequest() if err != nil { return nil, err @@ -816,15 +786,11 @@ func (client *httpRedirectsOperations) put307CreateRequest() (*azcore.Request, e } // put307HandleResponse handles the Put307 response. -func (client *httpRedirectsOperations) put307HandleResponse(resp *azcore.Response) (*HTTPRedirectsPut307Response, error) { +func (client *httpRedirectsOperations) put307HandleResponse(resp *azcore.Response) (*http.Response, error) { if !resp.HasStatusCode(http.StatusOK) { return nil, client.put307HandleError(resp) } - result := HTTPRedirectsPut307Response{RawResponse: resp.Response} - if val := resp.Header.Get("Location"); val != "" { - result.Location = &val - } - return &result, nil + return resp.Response, nil } // put307HandleError handles the Put307 error response. diff --git a/test/autorest/generated/httpinfrastructuregroup/models.go b/test/autorest/generated/httpinfrastructuregroup/models.go index 898ac0858..2d48c9c71 100644 --- a/test/autorest/generated/httpinfrastructuregroup/models.go +++ b/test/autorest/generated/httpinfrastructuregroup/models.go @@ -15,6 +15,14 @@ type B struct { TextStatusCode *string `json:"textStatusCode,omitempty"` } +// BResponse is the response envelope for operations that return a B type. +type BResponse struct { + B *B + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + // BoolResponse is the response envelope for operations that return a bool type. type BoolResponse struct { // RawResponse contains the underlying HTTP response. @@ -28,10 +36,26 @@ type C struct { HTTPCode *string `json:"httpCode,omitempty"` } +// CResponse is the response envelope for operations that return a C type. +type CResponse struct { + C *C + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + type D struct { HTTPStatusCode *string `json:"httpStatusCode,omitempty"` } +// DResponse is the response envelope for operations that return a D type. +type DResponse struct { + D *D + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + type Error struct { Message *string `json:"message,omitempty"` Status *int32 `json:"status,omitempty"` @@ -51,15 +75,6 @@ func (e Error) Error() string { return msg } -// HTTPRedirectsDelete307Response contains the response from method HTTPRedirects.Delete307. -type HTTPRedirectsDelete307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - // HTTPRedirectsGet300Response contains the response from method HTTPRedirects.Get300. type HTTPRedirectsGet300Response struct { // Location contains the information returned from the Location header response. @@ -69,33 +84,6 @@ type HTTPRedirectsGet300Response struct { RawResponse *http.Response } -// HTTPRedirectsGet301Response contains the response from method HTTPRedirects.Get301. -type HTTPRedirectsGet301Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// HTTPRedirectsGet302Response contains the response from method HTTPRedirects.Get302. -type HTTPRedirectsGet302Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// HTTPRedirectsGet307Response contains the response from method HTTPRedirects.Get307. -type HTTPRedirectsGet307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - // HTTPRedirectsHead300Response contains the response from method HTTPRedirects.Head300. type HTTPRedirectsHead300Response struct { // Location contains the information returned from the Location header response. @@ -105,42 +93,6 @@ type HTTPRedirectsHead300Response struct { RawResponse *http.Response } -// HTTPRedirectsHead301Response contains the response from method HTTPRedirects.Head301. -type HTTPRedirectsHead301Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// HTTPRedirectsHead302Response contains the response from method HTTPRedirects.Head302. -type HTTPRedirectsHead302Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// HTTPRedirectsHead307Response contains the response from method HTTPRedirects.Head307. -type HTTPRedirectsHead307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - -// HTTPRedirectsOptions307Response contains the response from method HTTPRedirects.Options307. -type HTTPRedirectsOptions307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - // HTTPRedirectsPatch302Response contains the response from method HTTPRedirects.Patch302. type HTTPRedirectsPatch302Response struct { // Location contains the information returned from the Location header response. @@ -150,15 +102,6 @@ type HTTPRedirectsPatch302Response struct { RawResponse *http.Response } -// HTTPRedirectsPatch307Response contains the response from method HTTPRedirects.Patch307. -type HTTPRedirectsPatch307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - // HTTPRedirectsPost303Response contains the response from method HTTPRedirects.Post303. type HTTPRedirectsPost303Response struct { // Location contains the information returned from the Location header response. @@ -168,15 +111,6 @@ type HTTPRedirectsPost303Response struct { RawResponse *http.Response } -// HTTPRedirectsPost307Response contains the response from method HTTPRedirects.Post307. -type HTTPRedirectsPost307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - // HTTPRedirectsPut301Response contains the response from method HTTPRedirects.Put301. type HTTPRedirectsPut301Response struct { // Location contains the information returned from the Location header response. @@ -186,15 +120,6 @@ type HTTPRedirectsPut301Response struct { RawResponse *http.Response } -// HTTPRedirectsPut307Response contains the response from method HTTPRedirects.Put307. -type HTTPRedirectsPut307Response struct { - // Location contains the information returned from the Location header response. - Location *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response -} - type MyException struct { StatusCode *string `json:"statusCode,omitempty"` } @@ -217,3 +142,15 @@ type MyExceptionResponse struct { // RawResponse contains the underlying HTTP response. RawResponse *http.Response } + +// StringArrayResponse is the response envelope for operations that return a []string type. +type StringArrayResponse struct { + // Location contains the information returned from the Location header response. + Location *string + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response + + // A list of location options for the request ['/http/success/get/200'] + StringArray *[]string +} diff --git a/test/autorest/generated/httpinfrastructuregroup/multipleresponses.go b/test/autorest/generated/httpinfrastructuregroup/multipleresponses.go index b189299b3..67dd54ef0 100644 --- a/test/autorest/generated/httpinfrastructuregroup/multipleresponses.go +++ b/test/autorest/generated/httpinfrastructuregroup/multipleresponses.go @@ -15,11 +15,14 @@ import ( // MultipleResponsesOperations contains the methods for the MultipleResponses group. type MultipleResponsesOperations interface { // Get200Model201ModelDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} - Get200Model201ModelDefaultError200Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *BResponse + Get200Model201ModelDefaultError200Valid(ctx context.Context) (interface{}, error) // Get200Model201ModelDefaultError201Valid - Send a 201 response with valid payload: {'statusCode': '201', 'textStatusCode': 'Created'} - Get200Model201ModelDefaultError201Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *BResponse + Get200Model201ModelDefaultError201Valid(ctx context.Context) (interface{}, error) // Get200Model201ModelDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} - Get200Model201ModelDefaultError400Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *BResponse + Get200Model201ModelDefaultError400Valid(ctx context.Context) (interface{}, error) // Get200Model204NoModelDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} Get200Model204NoModelDefaultError200Valid(ctx context.Context) (*MyExceptionResponse, error) // Get200Model204NoModelDefaultError201Invalid - Send a 201 response with valid payload: {'statusCode': '201'} @@ -37,13 +40,17 @@ type MultipleResponsesOperations interface { // Get200ModelA200Valid - Send a 200 response with payload {'statusCode': '200'} Get200ModelA200Valid(ctx context.Context) (*MyExceptionResponse, error) // Get200ModelA201ModelC404ModelDDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} - Get200ModelA201ModelC404ModelDDefaultError200Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *CResponse, *DResponse + Get200ModelA201ModelC404ModelDDefaultError200Valid(ctx context.Context) (interface{}, error) // Get200ModelA201ModelC404ModelDDefaultError201Valid - Send a 200 response with valid payload: {'httpCode': '201'} - Get200ModelA201ModelC404ModelDDefaultError201Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *CResponse, *DResponse + Get200ModelA201ModelC404ModelDDefaultError201Valid(ctx context.Context) (interface{}, error) // Get200ModelA201ModelC404ModelDDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} - Get200ModelA201ModelC404ModelDDefaultError400Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *CResponse, *DResponse + Get200ModelA201ModelC404ModelDDefaultError400Valid(ctx context.Context) (interface{}, error) // Get200ModelA201ModelC404ModelDDefaultError404Valid - Send a 200 response with valid payload: {'httpStatusCode': '404'} - Get200ModelA201ModelC404ModelDDefaultError404Valid(ctx context.Context) (*MyExceptionResponse, error) + // Possible return types are *MyExceptionResponse, *CResponse, *DResponse + Get200ModelA201ModelC404ModelDDefaultError404Valid(ctx context.Context) (interface{}, error) // Get200ModelA202Valid - Send a 202 response with payload {'statusCode': '202'} Get200ModelA202Valid(ctx context.Context) (*MyExceptionResponse, error) // Get200ModelA400Invalid - Send a 200 response with invalid payload {'statusCodeInvalid': '400'} @@ -90,7 +97,8 @@ type multipleResponsesOperations struct { } // Get200Model201ModelDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} -func (client *multipleResponsesOperations) Get200Model201ModelDefaultError200Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *BResponse +func (client *multipleResponsesOperations) Get200Model201ModelDefaultError200Valid(ctx context.Context) (interface{}, error) { req, err := client.get200Model201ModelDefaultError200ValidCreateRequest() if err != nil { return nil, err @@ -118,12 +126,17 @@ func (client *multipleResponsesOperations) get200Model201ModelDefaultError200Val } // get200Model201ModelDefaultError200ValidHandleResponse handles the Get200Model201ModelDefaultError200Valid response. -func (client *multipleResponsesOperations) get200Model201ModelDefaultError200ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200Model201ModelDefaultError200ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := BResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.B) + default: return nil, client.get200Model201ModelDefaultError200ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200Model201ModelDefaultError200ValidHandleError handles the Get200Model201ModelDefaultError200Valid error response. @@ -136,7 +149,8 @@ func (client *multipleResponsesOperations) get200Model201ModelDefaultError200Val } // Get200Model201ModelDefaultError201Valid - Send a 201 response with valid payload: {'statusCode': '201', 'textStatusCode': 'Created'} -func (client *multipleResponsesOperations) Get200Model201ModelDefaultError201Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *BResponse +func (client *multipleResponsesOperations) Get200Model201ModelDefaultError201Valid(ctx context.Context) (interface{}, error) { req, err := client.get200Model201ModelDefaultError201ValidCreateRequest() if err != nil { return nil, err @@ -164,12 +178,17 @@ func (client *multipleResponsesOperations) get200Model201ModelDefaultError201Val } // get200Model201ModelDefaultError201ValidHandleResponse handles the Get200Model201ModelDefaultError201Valid response. -func (client *multipleResponsesOperations) get200Model201ModelDefaultError201ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200Model201ModelDefaultError201ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := BResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.B) + default: return nil, client.get200Model201ModelDefaultError201ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200Model201ModelDefaultError201ValidHandleError handles the Get200Model201ModelDefaultError201Valid error response. @@ -182,7 +201,8 @@ func (client *multipleResponsesOperations) get200Model201ModelDefaultError201Val } // Get200Model201ModelDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} -func (client *multipleResponsesOperations) Get200Model201ModelDefaultError400Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *BResponse +func (client *multipleResponsesOperations) Get200Model201ModelDefaultError400Valid(ctx context.Context) (interface{}, error) { req, err := client.get200Model201ModelDefaultError400ValidCreateRequest() if err != nil { return nil, err @@ -210,12 +230,17 @@ func (client *multipleResponsesOperations) get200Model201ModelDefaultError400Val } // get200Model201ModelDefaultError400ValidHandleResponse handles the Get200Model201ModelDefaultError400Valid response. -func (client *multipleResponsesOperations) get200Model201ModelDefaultError400ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200Model201ModelDefaultError400ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := BResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.B) + default: return nil, client.get200Model201ModelDefaultError400ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200Model201ModelDefaultError400ValidHandleError handles the Get200Model201ModelDefaultError400Valid error response. @@ -257,7 +282,7 @@ func (client *multipleResponsesOperations) get200Model204NoModelDefaultError200V // get200Model204NoModelDefaultError200ValidHandleResponse handles the Get200Model204NoModelDefaultError200Valid response. func (client *multipleResponsesOperations) get200Model204NoModelDefaultError200ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { return nil, client.get200Model204NoModelDefaultError200ValidHandleError(resp) } result := MyExceptionResponse{RawResponse: resp.Response} @@ -303,7 +328,7 @@ func (client *multipleResponsesOperations) get200Model204NoModelDefaultError201I // get200Model204NoModelDefaultError201InvalidHandleResponse handles the Get200Model204NoModelDefaultError201Invalid response. func (client *multipleResponsesOperations) get200Model204NoModelDefaultError201InvalidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { return nil, client.get200Model204NoModelDefaultError201InvalidHandleError(resp) } result := MyExceptionResponse{RawResponse: resp.Response} @@ -349,7 +374,7 @@ func (client *multipleResponsesOperations) get200Model204NoModelDefaultError202N // get200Model204NoModelDefaultError202NoneHandleResponse handles the Get200Model204NoModelDefaultError202None response. func (client *multipleResponsesOperations) get200Model204NoModelDefaultError202NoneHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { return nil, client.get200Model204NoModelDefaultError202NoneHandleError(resp) } result := MyExceptionResponse{RawResponse: resp.Response} @@ -395,7 +420,7 @@ func (client *multipleResponsesOperations) get200Model204NoModelDefaultError204V // get200Model204NoModelDefaultError204ValidHandleResponse handles the Get200Model204NoModelDefaultError204Valid response. func (client *multipleResponsesOperations) get200Model204NoModelDefaultError204ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { return nil, client.get200Model204NoModelDefaultError204ValidHandleError(resp) } result := MyExceptionResponse{RawResponse: resp.Response} @@ -441,7 +466,7 @@ func (client *multipleResponsesOperations) get200Model204NoModelDefaultError400V // get200Model204NoModelDefaultError400ValidHandleResponse handles the Get200Model204NoModelDefaultError400Valid response. func (client *multipleResponsesOperations) get200Model204NoModelDefaultError400ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { return nil, client.get200Model204NoModelDefaultError400ValidHandleError(resp) } result := MyExceptionResponse{RawResponse: resp.Response} @@ -584,7 +609,8 @@ func (client *multipleResponsesOperations) get200ModelA200ValidHandleError(resp } // Get200ModelA201ModelC404ModelDDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} -func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError200Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *CResponse, *DResponse +func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError200Valid(ctx context.Context) (interface{}, error) { req, err := client.get200ModelA201ModelC404ModelDDefaultError200ValidCreateRequest() if err != nil { return nil, err @@ -612,12 +638,20 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // get200ModelA201ModelC404ModelDDefaultError200ValidHandleResponse handles the Get200ModelA201ModelC404ModelDDefaultError200Valid response. -func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError200ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError200ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := CResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.C) + case http.StatusNotFound: + result := DResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.D) + default: return nil, client.get200ModelA201ModelC404ModelDDefaultError200ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200ModelA201ModelC404ModelDDefaultError200ValidHandleError handles the Get200ModelA201ModelC404ModelDDefaultError200Valid error response. @@ -630,7 +664,8 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // Get200ModelA201ModelC404ModelDDefaultError201Valid - Send a 200 response with valid payload: {'httpCode': '201'} -func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError201Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *CResponse, *DResponse +func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError201Valid(ctx context.Context) (interface{}, error) { req, err := client.get200ModelA201ModelC404ModelDDefaultError201ValidCreateRequest() if err != nil { return nil, err @@ -658,12 +693,20 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // get200ModelA201ModelC404ModelDDefaultError201ValidHandleResponse handles the Get200ModelA201ModelC404ModelDDefaultError201Valid response. -func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError201ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError201ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := CResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.C) + case http.StatusNotFound: + result := DResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.D) + default: return nil, client.get200ModelA201ModelC404ModelDDefaultError201ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200ModelA201ModelC404ModelDDefaultError201ValidHandleError handles the Get200ModelA201ModelC404ModelDDefaultError201Valid error response. @@ -676,7 +719,8 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // Get200ModelA201ModelC404ModelDDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} -func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError400Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *CResponse, *DResponse +func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError400Valid(ctx context.Context) (interface{}, error) { req, err := client.get200ModelA201ModelC404ModelDDefaultError400ValidCreateRequest() if err != nil { return nil, err @@ -704,12 +748,20 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // get200ModelA201ModelC404ModelDDefaultError400ValidHandleResponse handles the Get200ModelA201ModelC404ModelDDefaultError400Valid response. -func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError400ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError400ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := CResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.C) + case http.StatusNotFound: + result := DResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.D) + default: return nil, client.get200ModelA201ModelC404ModelDDefaultError400ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200ModelA201ModelC404ModelDDefaultError400ValidHandleError handles the Get200ModelA201ModelC404ModelDDefaultError400Valid error response. @@ -722,7 +774,8 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // Get200ModelA201ModelC404ModelDDefaultError404Valid - Send a 200 response with valid payload: {'httpStatusCode': '404'} -func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError404Valid(ctx context.Context) (*MyExceptionResponse, error) { +// Possible return types are *MyExceptionResponse, *CResponse, *DResponse +func (client *multipleResponsesOperations) Get200ModelA201ModelC404ModelDDefaultError404Valid(ctx context.Context) (interface{}, error) { req, err := client.get200ModelA201ModelC404ModelDDefaultError404ValidCreateRequest() if err != nil { return nil, err @@ -750,12 +803,20 @@ func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefault } // get200ModelA201ModelC404ModelDDefaultError404ValidHandleResponse handles the Get200ModelA201ModelC404ModelDDefaultError404Valid response. -func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError404ValidHandleResponse(resp *azcore.Response) (*MyExceptionResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { +func (client *multipleResponsesOperations) get200ModelA201ModelC404ModelDDefaultError404ValidHandleResponse(resp *azcore.Response) (interface{}, error) { + switch resp.StatusCode { + case http.StatusOK: + result := MyExceptionResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.MyException) + case http.StatusCreated: + result := CResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.C) + case http.StatusNotFound: + result := DResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.D) + default: return nil, client.get200ModelA201ModelC404ModelDDefaultError404ValidHandleError(resp) } - result := MyExceptionResponse{RawResponse: resp.Response} - return &result, resp.UnmarshalAsJSON(&result.MyException) } // get200ModelA201ModelC404ModelDDefaultError404ValidHandleError handles the Get200ModelA201ModelC404ModelDDefaultError404Valid error response. diff --git a/test/autorest/httpinfrastructuregroup/httpmultipleresponses_test.go b/test/autorest/httpinfrastructuregroup/httpmultipleresponses_test.go index 8ad454cdf..d88604e63 100644 --- a/test/autorest/httpinfrastructuregroup/httpmultipleresponses_test.go +++ b/test/autorest/httpinfrastructuregroup/httpmultipleresponses_test.go @@ -28,42 +28,120 @@ func TestGet200Model201ModelDefaultError200Valid(t *testing.T) { if err != nil { t.Fatal(err) } - helpers.DeepEqualOrFatal(t, result.MyException.StatusCode, to.StringPtr("200")) + switch x := result.(type) { + case *httpinfrastructuregroup.MyExceptionResponse: + helpers.DeepEqualOrFatal(t, x.MyException.StatusCode, to.StringPtr("200")) + case *httpinfrastructuregroup.BResponse: + helpers.VerifyStatusCode(t, x.RawResponse, http.StatusCreated) + default: + t.Fatalf("unhandled response type %v", x) + } } // Get200Model201ModelDefaultError201Valid - Send a 201 response with valid payload: {'statusCode': '201', 'textStatusCode': 'Created'} func TestGet200Model201ModelDefaultError201Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model201ModelDefaultError201Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + r, ok := result.(*httpinfrastructuregroup.BResponse) + if !ok { + t.Fatal("unexpected response type") + } + helpers.DeepEqualOrFatal(t, r.B, &httpinfrastructuregroup.B{ + MyException: httpinfrastructuregroup.MyException{ + StatusCode: to.StringPtr("201"), + }, + TextStatusCode: to.StringPtr("Created"), + }) } // Get200Model201ModelDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} func TestGet200Model201ModelDefaultError400Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model201ModelDefaultError400Valid(context.Background()) + r, ok := err.(httpinfrastructuregroup.Error) + if !ok { + t.Fatal("unexpected error type") + } + helpers.DeepEqualOrFatal(t, r, httpinfrastructuregroup.Error{ + Message: to.StringPtr("client error"), + Status: to.Int32Ptr(400), + }) + if result != nil { + t.Fatal("expected nil result") + } } // Get200Model204NoModelDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} func TestGet200Model204NoModelDefaultError200Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model204NoModelDefaultError200Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.MyException, &httpinfrastructuregroup.MyException{ + StatusCode: to.StringPtr("200"), + }) } // Get200Model204NoModelDefaultError201Invalid - Send a 201 response with valid payload: {'statusCode': '201'} func TestGet200Model204NoModelDefaultError201Invalid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model204NoModelDefaultError201Invalid(context.Background()) + r, ok := err.(httpinfrastructuregroup.Error) + if !ok { + t.Fatal("unexpected error type") + } + helpers.DeepEqualOrFatal(t, r, httpinfrastructuregroup.Error{}) + if result != nil { + t.Fatal("expected nil result") + } } // Get200Model204NoModelDefaultError202None - Send a 202 response with no payload: func TestGet200Model204NoModelDefaultError202None(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model204NoModelDefaultError202None(context.Background()) + r, ok := err.(httpinfrastructuregroup.Error) + if !ok { + t.Fatal("unexpected error type") + } + helpers.DeepEqualOrFatal(t, r, httpinfrastructuregroup.Error{}) + if result != nil { + t.Fatal("expected nil result") + } } // Get200Model204NoModelDefaultError204Valid - Send a 204 response with no payload func TestGet200Model204NoModelDefaultError204Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model204NoModelDefaultError204Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result.RawResponse, http.StatusNoContent) + if result.MyException != nil { + t.Fatal("expected nil payload") + } } // Get200Model204NoModelDefaultError400Valid - Send a 400 response with valid error payload: {'status': 400, 'message': 'client error'} func TestGet200Model204NoModelDefaultError400Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200Model204NoModelDefaultError400Valid(context.Background()) + r, ok := err.(httpinfrastructuregroup.Error) + if !ok { + t.Fatal("unexpected error type") + } + helpers.DeepEqualOrFatal(t, r, httpinfrastructuregroup.Error{ + Message: to.StringPtr("client error"), + Status: to.Int32Ptr(400), + }) + if result != nil { + t.Fatal("expected nil result") + } } // Get200ModelA200Invalid - Send a 200 response with invalid payload {'statusCodeInvalid': '200'} @@ -97,22 +175,67 @@ func TestGet200ModelA200Valid(t *testing.T) { // Get200ModelA201ModelC404ModelDDefaultError200Valid - Send a 200 response with valid payload: {'statusCode': '200'} func TestGet200ModelA201ModelC404ModelDDefaultError200Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200ModelA201ModelC404ModelDDefaultError200Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + r, ok := result.(*httpinfrastructuregroup.MyExceptionResponse) + if !ok { + t.Fatal("unexpected result type") + } + helpers.DeepEqualOrFatal(t, r.MyException, &httpinfrastructuregroup.MyException{ + StatusCode: to.StringPtr("200"), + }) } // Get200ModelA201ModelC404ModelDDefaultError201Valid - Send a 200 response with valid payload: {'httpCode': '201'} func TestGet200ModelA201ModelC404ModelDDefaultError201Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200ModelA201ModelC404ModelDDefaultError201Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + r, ok := result.(*httpinfrastructuregroup.CResponse) + if !ok { + t.Fatal("unexpected result type") + } + helpers.DeepEqualOrFatal(t, r.C, &httpinfrastructuregroup.C{ + HTTPCode: to.StringPtr("201"), + }) } // Get200ModelA201ModelC404ModelDDefaultError400Valid - Send a 400 response with valid payload: {'code': '400', 'message': 'client error'} func TestGet200ModelA201ModelC404ModelDDefaultError400Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200ModelA201ModelC404ModelDDefaultError400Valid(context.Background()) + r, ok := err.(httpinfrastructuregroup.Error) + if !ok { + t.Fatal("unexpected error type") + } + helpers.DeepEqualOrFatal(t, r, httpinfrastructuregroup.Error{ + Message: to.StringPtr("client error"), + Status: to.Int32Ptr(400), + }) + if result != nil { + t.Fatal("expected nil result") + } } // Get200ModelA201ModelC404ModelDDefaultError404Valid - Send a 200 response with valid payload: {'httpStatusCode': '404'} func TestGet200ModelA201ModelC404ModelDDefaultError404Valid(t *testing.T) { - t.Skip("different return schemas NYI") + client := getMultipleResponseOperations(t) + result, err := client.Get200ModelA201ModelC404ModelDDefaultError404Valid(context.Background()) + if err != nil { + t.Fatal(err) + } + r, ok := result.(*httpinfrastructuregroup.DResponse) + if !ok { + t.Fatal("unexpected result type") + } + helpers.DeepEqualOrFatal(t, r.D, &httpinfrastructuregroup.D{ + HTTPStatusCode: to.StringPtr("404"), + }) } // Get200ModelA202Valid - Send a 202 response with payload {'statusCode': '202'} diff --git a/test/autorest/httpinfrastructuregroup/httpredirects_test.go b/test/autorest/httpinfrastructuregroup/httpredirects_test.go index d9f1d9395..e71100e81 100644 --- a/test/autorest/httpinfrastructuregroup/httpredirects_test.go +++ b/test/autorest/httpinfrastructuregroup/httpredirects_test.go @@ -25,17 +25,24 @@ func TestHTTPRedirectsDelete307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsGet300(t *testing.T) { - t.Skip() + t.Skip("does not automatically redirect") client := getHTTPRedirectsOperations(t) result, err := client.Get300(context.Background()) if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + switch x := result.(type) { + case *httpinfrastructuregroup.HTTPRedirectsGet300Response: + helpers.VerifyStatusCode(t, x.RawResponse, http.StatusOK) + case *httpinfrastructuregroup.StringArrayResponse: + helpers.VerifyStatusCode(t, x.RawResponse, http.StatusMultipleChoices) + default: + t.Fatalf("unhandled response type %v", x) + } } func TestHTTPRedirectsGet301(t *testing.T) { @@ -44,7 +51,7 @@ func TestHTTPRedirectsGet301(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsGet302(t *testing.T) { @@ -53,7 +60,7 @@ func TestHTTPRedirectsGet302(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsGet307(t *testing.T) { @@ -62,11 +69,11 @@ func TestHTTPRedirectsGet307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsHead300(t *testing.T) { - t.Skip() + t.Skip("does not automatically redirect") client := getHTTPRedirectsOperations(t) result, err := client.Head300(context.Background()) if err != nil { @@ -81,7 +88,7 @@ func TestHTTPRedirectsHead301(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsHead302(t *testing.T) { @@ -90,7 +97,7 @@ func TestHTTPRedirectsHead302(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsHead307(t *testing.T) { @@ -99,21 +106,21 @@ func TestHTTPRedirectsHead307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsOptions307(t *testing.T) { - t.Skip() + t.Skip("receive a status code of 204 which is not expected") client := getHTTPRedirectsOperations(t) result, err := client.Options307(context.Background()) if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsPatch302(t *testing.T) { - t.Skip() + t.Skip("HTTP client automatically redirects, test server doesn't expect it") client := getHTTPRedirectsOperations(t) result, err := client.Patch302(context.Background()) if err != nil { @@ -128,7 +135,7 @@ func TestHTTPRedirectsPatch307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsPost303(t *testing.T) { @@ -146,11 +153,11 @@ func TestHTTPRedirectsPost307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } func TestHTTPRedirectsPut301(t *testing.T) { - t.Skip() + t.Skip("HTTP client automatically redirects, test server doesn't expect it") client := getHTTPRedirectsOperations(t) result, err := client.Put301(context.Background()) if err != nil { @@ -165,5 +172,5 @@ func TestHTTPRedirectsPut307(t *testing.T) { if err != nil { t.Fatalf("Did not expect an error, but received: %v", err) } - helpers.VerifyStatusCode(t, result.RawResponse, http.StatusOK) + helpers.VerifyStatusCode(t, result, http.StatusOK) } diff --git a/test/autorest/urlgroup/paths_test.go b/test/autorest/urlgroup/paths_test.go index 016a445c3..f351f7d29 100644 --- a/test/autorest/urlgroup/paths_test.go +++ b/test/autorest/urlgroup/paths_test.go @@ -248,9 +248,7 @@ func TestPathsStringURLNonEncoded(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } -// TODO verify how to work with this type of string func TestPathsStringUnicode(t *testing.T) { - t.Skip() client := getPathsOperations(t) result, err := client.StringUnicode(context.Background()) if err != nil { diff --git a/test/autorest/urlgroup/queries_test.go b/test/autorest/urlgroup/queries_test.go index 2402f3d41..363b565c0 100644 --- a/test/autorest/urlgroup/queries_test.go +++ b/test/autorest/urlgroup/queries_test.go @@ -122,7 +122,6 @@ func TestGetTenBillion(t *testing.T) { } func TestStringUnicode(t *testing.T) { - t.Skip("scenario NYI in test server") client := getQueriesClient(t) result, err := client.StringUnicode(context.Background()) if err != nil { diff --git a/test/storage/2019-07-07/azblob/blob.go b/test/storage/2019-07-07/azblob/blob.go index 61fb47223..a74fa6d30 100644 --- a/test/storage/2019-07-07/azblob/blob.go +++ b/test/storage/2019-07-07/azblob/blob.go @@ -843,7 +843,7 @@ func (client *blobOperations) downloadCreateRequest(blobDownloadOptions *BlobDow // downloadHandleResponse handles the Download response. func (client *blobOperations) downloadHandleResponse(resp *azcore.Response) (*BlobDownloadResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusPartialContent) { return nil, client.downloadHandleError(resp) } result := BlobDownloadResponse{RawResponse: resp.Response} @@ -2118,7 +2118,7 @@ func (client *blobOperations) setTierCreateRequest(tier AccessTier, blobSetTierO // setTierHandleResponse handles the SetTier response. func (client *blobOperations) setTierHandleResponse(resp *azcore.Response) (*BlobSetTierResponse, error) { - if !resp.HasStatusCode(http.StatusOK) { + if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { return nil, client.setTierHandleError(resp) } result := BlobSetTierResponse{RawResponse: resp.Response} diff --git a/test/storage/2019-07-07/azblob/models.go b/test/storage/2019-07-07/azblob/models.go index ca5741f61..cc51deba0 100644 --- a/test/storage/2019-07-07/azblob/models.go +++ b/test/storage/2019-07-07/azblob/models.go @@ -1038,7 +1038,7 @@ type BlobRenameOptions struct { // Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage // analytics logging is enabled. RequestId *string - // A lease ID for the source path. If specified, the source path must have an active lease and the leaase ID must match. + // A lease ID for the source path. If specified, the source path must have an active lease and the lease ID must match. SourceLeaseId *string // The timeout parameter is expressed in seconds. For more information, see Setting // Timeouts for Blob Service Operations. @@ -2420,7 +2420,7 @@ type DirectoryRenameOptions struct { // Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage // analytics logging is enabled. RequestId *string - // A lease ID for the source path. If specified, the source path must have an active lease and the leaase ID must match. + // A lease ID for the source path. If specified, the source path must have an active lease and the lease ID must match. SourceLeaseId *string // The timeout parameter is expressed in seconds. For more information, see Setting // Timeouts for Blob Service Operations.