Skip to content

Commit

Permalink
Merge pull request Azure#592 from chradek/media-fixes
Browse files Browse the repository at this point in the history
[v6] respects x-ms-client-name in mappers
  • Loading branch information
chradek authored Mar 20, 2020
2 parents aa1c3e5 + c45b94e commit a3b680d
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 147 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ More information about these can be found [here](https://github.com/Azure/autore
```yaml
version: 3.0.6246
use-extension:
"@autorest/modelerfour": "4.10.240"
"@autorest/modelerfour": "4.10.258"

modelerfour:
prenamer: true
Expand Down
5 changes: 4 additions & 1 deletion src/generators/clientContextFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,8 @@ function getRequiredParamChecks(requiredParameters: ParameterDetails[]) {
}

function getRequiredParamAssignments(requiredParameters: ParameterDetails[]) {
return requiredParameters.map(({ name }) => `this.${name} = ${name};`);
const disallowedClientParameters = ["credentials"];
return requiredParameters
.filter(({ name }) => !disallowedClientParameters.includes(name))
.map(({ name }) => `this.${name} = ${name};`);
}
3 changes: 2 additions & 1 deletion src/transforms/mapperTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ function processProperties(
) {
let modelProperties: ModelProperties = {};
properties.forEach(prop => {
const name = normalizeName(prop.serializedName, NameType.Property);
const propName = getLanguageMetadata(prop.language).name;
const name = normalizeName(propName, NameType.Property);
modelProperties[name] = getMapperOrRef(prop.schema, prop.serializedName, {
...options,
required: prop.required,
Expand Down
4 changes: 4 additions & 0 deletions test/integration/generated/bodyArray/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface Product {
* Defines values for Enum0.
*/
export type Enum0 = "foo1" | "foo2" | "foo3";
/**
* Defines values for Enum1.
*/
export type Enum1 = "foo1" | "foo2" | "foo3";
/**
* Defines values for FooEnum.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const arrayBody8: coreHttp.OperationParameter = {
required: true,
type: {
name: "Sequence",
element: { type: { name: "String" }, serializedName: "Enum0" }
element: { type: { name: "String" }, serializedName: "Enum1" }
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class Array {
* @param options The options parameters.
*/
putStringEnumValid(
arrayBody: Models.Enum0[],
arrayBody: Models.Enum1[],
options?: coreHttp.OperationOptions
): Promise<coreHttp.RestResponse> {
return this.client.sendOperationRequest(
Expand Down
28 changes: 24 additions & 4 deletions test/integration/generated/bodyComplex/src/models/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,45 @@ export const complexBody12: coreHttp.OperationParameter = {

export const complexBody13: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.DictionaryWrapper
mapper: Mappers.ArrayWrapper
};

export const complexBody14: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Siamese
mapper: Mappers.DictionaryWrapper
};

export const complexBody15: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Fish
mapper: Mappers.DictionaryWrapper
};

export const complexBody16: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Salmon
mapper: Mappers.Siamese
};

export const complexBody17: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Fish
};

export const complexBody18: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Salmon
};

export const complexBody19: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Fish
};

export const complexBody20: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.Fish
};

export const complexBody21: coreHttp.OperationParameter = {
parameterPath: "complexBody",
mapper: Mappers.ReadonlyObj
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export class Array {

/**
* Put complex types with array property which is empty
* @param complexBody Please put an array with 4 items: "1, 2, 3, 4", "", null, "&S#$(*Y", "The quick
* brown fox jumps over the lazy dog"
* @param complexBody Please put an empty array
* @param options The options parameters.
*/
putEmpty(
Expand Down Expand Up @@ -151,7 +150,7 @@ const putEmptyOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody12,
requestBody: Parameters.complexBody13,
urlParameters: [Parameters.$host],
serializer
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export class Dictionary {

/**
* Put complex types with dictionary property which is empty
* @param complexBody Please put a dictionary with 5 key-value pairs: "txt":"notepad", "bmp":"mspaint",
* "xls":"excel", "exe":"", "":null
* @param complexBody Please put an empty dictionary
* @param options The options parameters.
*/
putEmpty(
Expand Down Expand Up @@ -137,7 +136,7 @@ const putValidOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody13,
requestBody: Parameters.complexBody14,
urlParameters: [Parameters.$host],
serializer
};
Expand All @@ -164,7 +163,7 @@ const putEmptyOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody13,
requestBody: Parameters.complexBody15,
urlParameters: [Parameters.$host],
serializer
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const putValidOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody14,
requestBody: Parameters.complexBody16,
urlParameters: [Parameters.$host],
serializer
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,57 @@ export class Polymorphicrecursive {
* Put complex types that are polymorphic and have recursive references
* @param complexBody Please put a salmon that looks like this:
* {
* 'fishtype':'Salmon',
* 'location':'alaska',
* 'iswild':true,
* 'species':'king',
* 'length':1.0,
* 'siblings':[
* {
* 'fishtype':'Shark',
* 'age':6,
* 'birthday': '2012-01-05T01:00:00Z',
* 'length':20.0,
* 'species':'predator',
* },
* {
* 'fishtype':'Sawshark',
* 'age':105,
* 'birthday': '1900-01-05T01:00:00Z',
* 'length':10.0,
* 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'),
* 'species':'dangerous',
* },
* {
* 'fishtype': 'goblin',
* 'age': 1,
* 'birthday': '2015-08-08T00:00:00Z',
* 'length': 30.0,
* 'species': 'scary',
* 'jawsize': 5
* }
* ]
* };
* "fishtype": "salmon",
* "species": "king",
* "length": 1,
* "age": 1,
* "location": "alaska",
* "iswild": true,
* "siblings": [
* {
* "fishtype": "shark",
* "species": "predator",
* "length": 20,
* "age": 6,
* "siblings": [
* {
* "fishtype": "salmon",
* "species": "coho",
* "length": 2,
* "age": 2,
* "location": "atlantic",
* "iswild": true,
* "siblings": [
* {
* "fishtype": "shark",
* "species": "predator",
* "length": 20,
* "age": 6
* },
* {
* "fishtype": "sawshark",
* "species": "dangerous",
* "length": 10,
* "age": 105
* }
* ]
* },
* {
* "fishtype": "sawshark",
* "species": "dangerous",
* "length": 10,
* "age": 105
* }
* ]
* },
* {
* "fishtype": "sawshark",
* "species": "dangerous",
* "length": 10,
* "age": 105
* }
* ]
* }
* @param options The options parameters.
*/
putValid(
Expand Down Expand Up @@ -113,7 +133,7 @@ const putValidOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody15,
requestBody: Parameters.complexBody20,
urlParameters: [Parameters.$host],
serializer
};
Original file line number Diff line number Diff line change
Expand Up @@ -177,39 +177,33 @@ export class Polymorphism {
/**
* Put complex types that are polymorphic, attempting to omit required 'birthday' field - the request
* should not be allowed from the client
* @param complexBody Please put a salmon that looks like this:
* @param complexBody Please attempt put a sawshark that looks like this, the client should not allow
* this data to be sent:
* {
* 'fishtype':'Salmon',
* 'location':'alaska',
* 'iswild':true,
* 'species':'king',
* 'length':1.0,
* 'siblings':[
* {
* 'fishtype':'Shark',
* 'age':6,
* 'birthday': '2012-01-05T01:00:00Z',
* 'length':20.0,
* 'species':'predator',
* },
* {
* 'fishtype':'Sawshark',
* 'age':105,
* 'birthday': '1900-01-05T01:00:00Z',
* 'length':10.0,
* 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'),
* 'species':'dangerous',
* },
* {
* 'fishtype': 'goblin',
* 'age': 1,
* 'birthday': '2015-08-08T00:00:00Z',
* 'length': 30.0,
* 'species': 'scary',
* 'jawsize': 5
* }
* ]
* };
* "fishtype": "sawshark",
* "species": "snaggle toothed",
* "length": 18.5,
* "age": 2,
* "birthday": "2013-06-01T01:00:00Z",
* "location": "alaska",
* "picture": base64(FF FF FF FF FE),
* "siblings": [
* {
* "fishtype": "shark",
* "species": "predator",
* "birthday": "2012-01-05T01:00:00Z",
* "length": 20,
* "age": 6
* },
* {
* "fishtype": "sawshark",
* "species": "dangerous",
* "picture": base64(FF FF FF FF FE),
* "length": 10,
* "age": 105
* }
* ]
* }
* @param options The options parameters.
*/
putValidMissingRequired(
Expand Down Expand Up @@ -249,7 +243,7 @@ const putValidOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody15,
requestBody: Parameters.complexBody17,
urlParameters: [Parameters.$host],
serializer
};
Expand Down Expand Up @@ -318,7 +312,7 @@ const putComplicatedOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody16,
requestBody: Parameters.complexBody18,
urlParameters: [Parameters.$host],
serializer
};
Expand All @@ -333,7 +327,7 @@ const putMissingDiscriminatorOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody16,
requestBody: Parameters.complexBody18,
urlParameters: [Parameters.$host],
serializer
};
Expand All @@ -346,7 +340,7 @@ const putValidMissingRequiredOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody15,
requestBody: Parameters.complexBody19,
urlParameters: [Parameters.$host],
serializer
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const putValidOperationSpec: coreHttp.OperationSpec = {
bodyMapper: Mappers.ErrorModel
}
},
requestBody: Parameters.complexBody17,
requestBody: Parameters.complexBody21,
urlParameters: [Parameters.$host],
serializer
};
Loading

0 comments on commit a3b680d

Please sign in to comment.