Skip to content

Commit

Permalink
[v6] Add Smoke Test + Fix parameter name (Azure#630)
Browse files Browse the repository at this point in the history
* Add Smoke Test + Fix parameter name

* Fix typo
  • Loading branch information
joheredi authored Apr 29, 2020
1 parent 8ae3cd5 commit 22606e9
Show file tree
Hide file tree
Showing 34 changed files with 13,605 additions and 68 deletions.
4 changes: 4 additions & 0 deletions .scripts/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ steps:
npm run test
displayName: 'Run Tests'

- script: |
npm run smoke-test
displayName: 'Run Smoke Tests'

- script: |
npm run coverage-push -- $(Build.Repository.Name) $(Build.SourceBranch) $(github-token) $(storage-coverage-user) $(storage-coverage-pass)
workingDirectory: node_modules/@microsoft.azure/autorest.testserver
Expand Down
465 changes: 415 additions & 50 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"start-test-server:v1": "start-autorest-express node",
"stop-test-server": "stop-autorest-testserver",
"debug": "node --inspect-brk ./dist/src/main.js",
"generate-swaggers": "ts-node ./test/utils/test-swagger-gen.ts"
"generate-swaggers": "ts-node ./test/utils/test-swagger-gen.ts",
"smoke-test": "ts-node ./test/utils/smoke-test.ts"
},
"files": [
"src",
Expand Down Expand Up @@ -52,9 +53,11 @@
"@types/node": "12.7.12",
"@types/prettier": "^1.18.4",
"@types/xmlbuilder": "0.0.34",
"@types/yargs": "^15.0.4",
"@typescript-eslint/eslint-plugin": "~2.0.0",
"@typescript-eslint/parser": "~2.0.0",
"chai": "^4.2.0",
"chalk": "^4.0.0",
"eslint": "~6.2.2",
"express": "^4.17.1",
"mocha": "6.2.1",
Expand All @@ -65,6 +68,7 @@
"start-server-and-test": "^1.10.6",
"ts-node": "^8.5.2",
"typescript": "^3.7.5",
"wait-port": "^0.2.6"
"wait-port": "^0.2.6",
"yargs": "^15.3.1"
}
}
38 changes: 27 additions & 11 deletions src/transforms/parameterTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,22 @@ export function populateOperationParameters(
targetMediaType?: KnownMediaType
): void {
const parameterName = getParameterName(parameter);
let description =
getLanguageMetadata(parameter.language).description ||
getLanguageMetadata(parameter.schema.language).description;
const parameterMetadata = getLanguageMetadata(parameter.language);
const schemaMetadata = getLanguageMetadata(parameter.schema.language);

if (!parameterName) {
throw new Error(
`Couldn't get parameter serializedName for operation: ${operationName}`
`Couldn't get parameter name for operation: ${operationName}`
);
}

const serializedName: string =
parameterMetadata.serializedName ||
schemaMetadata.serializedName ||
parameterName;

let description = parameterMetadata.description || schemaMetadata.description;

// Ignore parameters with SchemaType.Group, since these are "virtual".
// These are handled separately in GroupTransforms and through
// parameter.groupedBy here in parameterTransforms
Expand All @@ -207,8 +213,7 @@ export function populateOperationParameters(
NameType.Parameter,
true /** shouldGuard */
);
const serializedName =
getLanguageMetadata(parameter.language).serializedName || name;

const sameNameParams = operationParameters.filter(p => p.name === name);
if (parameter.schema.type === SchemaType.Time) {
description += `\nThis value should be an ISO-8601 formatted string representing time. E.g. "HH:MM:SS" or "HH:MM:SS.mm".`;
Expand Down Expand Up @@ -252,6 +257,7 @@ export function populateOperationParameters(
parameter,
operationParameters,
serializedName,
parameterName,
sameNameParams,
operationName,
hasXmlMetadata,
Expand Down Expand Up @@ -366,18 +372,28 @@ function getCollectionFormat(parameter: Parameter): string | undefined {
}

function getParameterName(parameter: Parameter) {
const fromExtension =
const nameFromExtension: string | undefined =
parameter.extensions && parameter.extensions["x-ms-requestBody-name"];
const metadata = getLanguageMetadata(parameter.language);
const parameterSerializedName = metadata.name || metadata.serializedName;
const { name: originalName } = getLanguageMetadata(parameter.language);

const name = nameFromExtension || originalName;

return fromExtension || parameterSerializedName;
if (!name) {
throw new Error(
`ParameterTransform: Expected parameter to have a name ${JSON.stringify(
parameter.language
)}`
);
}

return name;
}

export function disambiguateParameter(
parameter: Parameter,
operationParameters: ParameterDetails[],
serializedName: string,
parameterName: string,
sameNameParams: ParameterDetails[],
operationName: string,
hasXmlMetadata: boolean,
Expand All @@ -397,7 +413,7 @@ export function disambiguateParameter(
} else {
// Since there is already a parameter with the same name, we need to ad a sufix
const name = normalizeName(
serializedName,
parameterName,
NameType.Parameter,
true /** shouldGuard */
);
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function transformCodeModel(
]);

return {
name: codeModel.info.title,
name: className,
className,
description: codeModel.info.description,
sourceFileName: normalizeName(className, NameType.File),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const contentType: coreHttp.OperationParameter = {
parameterPath: "contentType",
mapper: {
defaultValue: "application/octet-stream",
serializedName: "Content-Type",
isConstant: true,
serializedName: "Content-Type",
type: {
name: "String"
}
Expand All @@ -35,8 +35,8 @@ export const contentType1: coreHttp.OperationParameter = {
parameterPath: "contentType",
mapper: {
defaultValue: "text/plain",
serializedName: "Content-Type",
isConstant: true,
serializedName: "Content-Type",
type: {
name: "String"
}
Expand Down Expand Up @@ -72,7 +72,7 @@ export const excluded: coreHttp.OperationQueryParameter = {
serializedName: "excluded",
type: {
name: "Sequence",
element: { type: { name: "String" }, serializedName: "Post0ItemsItem" }
element: { type: { name: "String" } }
}
}
};
Expand All @@ -94,7 +94,7 @@ export const excluded1: coreHttp.OperationQueryParameter = {
serializedName: "excluded",
type: {
name: "Sequence",
element: { type: { name: "String" }, serializedName: "Post1ItemsItem" }
element: { type: { name: "String" } }
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Azure ADHybridHealthService SDK for JavaScript

This package contains an isomorphic SDK for ADHybridHealthService.

### Currently supported environments

- Node.js version 8.x.x or higher
- Browser JavaScript

### How to Install

```bash
npm install adhybridhealthservice-resource-manager
```

### How to use

#### Sample code

Refer the sample code in the [azure-sdk-for-js-samples](https://github.com/Azure/azure-sdk-for-js-samples) repository.

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)


![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcdn%2Farm-cdn%2FREADME.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "adhybridhealthservice-resource-manager",
"author": "Microsoft Corporation",
"description": "REST APIs for Azure Active Directory Connect Health",
"version": null,
"dependencies": {
"@azure/core-http": "^1.0.4",
"tslib": "^1.9.3"
},
"keywords": [
"node",
"azure",
"typescript",
"browser",
"isomorphic"
],
"license": "MIT",
"main": "./dist/adhybridhealthservice-resource-manager.js",
"module": "./esm/aDHybridHealthService.js",
"types": "./esm/aDHybridHealthService.d.ts",
"devDependencies": {
"typescript": "^3.1.1",
"rollup": "^0.66.2",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"uglify-js": "^3.4.9"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js",
"repository": {
"type": "git",
"url": "https://github.com/Azure/azure-sdk-for-js.git"
},
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"files": [
"dist/**/*.js",
"dist/**/*.js.map",
"dist/**/*.d.ts",
"dist/**/*.d.ts.map",
"esm/**/*.js",
"esm/**/*.js.map",
"esm/**/*.d.ts",
"esm/**/*.d.ts.map",
"src/**/*.ts",
"README.md",
"rollup.config.js",
"tsconfig.json"
],
"scripts": {
"build": "tsc && rollup -c rollup.config.js && npm run minify",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/adhybridhealthservice-resource-manager.js.map'\" -o ./dist/adhybridhealthservice-resource-manager.min.js ./dist/adhybridhealthservice-resource-manager.js",
"prepack": "npm install && npm run build"
},
"sideEffects": false,
"autoPublish": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import rollup from "rollup";
import nodeResolve from "rollup-plugin-node-resolve";
import sourcemaps from "rollup-plugin-sourcemaps";

/**
* @type {rollup.RollupFileOptions}
*/
const config = {
input: "./esm/aDHybridHealthService.js",
external: ["@azure/core-http", "@azure/core-arm"],
output: {
file: "./dist/adhybridhealthservice-resource-manager.js",
format: "umd",
name: "AdhybridhealthserviceResourceManager",
sourcemap: true,
globals: {
"@azure/core-http": "coreHttp",
"@azure/core-arm": "coreArm"
},
banner: `/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/ `
},
plugins: [nodeResolve({ module: true }), sourcemaps()]
};

export default config;
Loading

0 comments on commit 22606e9

Please sign in to comment.