Skip to content

Commit

Permalink
Merge pull request #843 from sarangan12/Issue826
Browse files Browse the repository at this point in the history
Handle MapperType.Sequence in the Parameters
  • Loading branch information
sarangan12 authored Jan 21, 2021
2 parents bfef180 + b7eeb87 commit 0ee2670
Show file tree
Hide file tree
Showing 17 changed files with 2,749 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/generators/mappersGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ function writeDefaultValue(
) {
if (!isNil(defaultValue)) {
return writer.write(
`defaultValue: ${getStringForValue(defaultValue, mapperType.name)},`
`defaultValue: ${getStringForValue(
defaultValue,
mapperType.name,
true,
mapperType
)},`
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/transforms/mapperTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
getAdditionalProperties
} from "../utils/schemaHelpers";
import { ObjectDetails } from "../models/modelDetails";
import { MapperTypes } from "../utils/valueHelpers";

interface PipelineValue {
schema: Schema;
Expand Down Expand Up @@ -771,7 +772,9 @@ export function getMapperTypeFromSchema(type: SchemaType, format?: string) {
case SchemaType.Object:
return MapperType.Object;
case SchemaType.Any:
return "any";
return MapperTypes.any;
case SchemaType.Uuid:
return MapperTypes.Uuid;
default:
throw new Error(`There is no known Mapper type for schema type ${type}`);
}
Expand Down
12 changes: 11 additions & 1 deletion src/utils/valueHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { SchemaType, AllSchemaTypes } from "@azure-tools/codemodel";
import { isNil, isEmpty } from "lodash";
import { MapperType, SequenceMapperType } from "@azure/core-http";

export enum MapperTypes {
Base64Url = "Base64Url",
Expand All @@ -19,6 +20,7 @@ export enum MapperTypes {
UnixTime = "UnixTime",
Uuid = "Uuid",
Number = "Number",
Sequence = "Sequence",
any = "any"
}

Expand All @@ -31,7 +33,8 @@ export enum MapperTypes {
export function getStringForValue(
value: any,
valueType: AllSchemaTypes | MapperTypes | string,
quotedStrings = true
quotedStrings = true,
mapperType?: MapperType
): string {
switch (valueType) {
case SchemaType.ByteArray:
Expand Down Expand Up @@ -60,6 +63,13 @@ export function getStringForValue(
case MapperTypes.Enum:
const valueString = !!value ? value.toString() : "";
return quotedStrings ? `"${valueString}"` : `${valueString}`;
case MapperTypes.Sequence:
if (mapperType) {
return getStringForValue(
value,
(mapperType as SequenceMapperType).element.type.name
);
}
default:
throw new Error(`Unexpected value type: ${valueType}`);
}
Expand Down
27 changes: 27 additions & 0 deletions test/integration/generated/petstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Azure PetStore SDK for JavaScript

This package contains an isomorphic SDK for PetStore.

### Currently supported environments

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

### How to Install

```bash
npm install petstore
```

### How to use

#### Sample code

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

## 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)
18 changes: 18 additions & 0 deletions test/integration/generated/petstore/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./esm/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./esm/index.d.ts"
},
"messages": {
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
"extractorMessageReporting": {
"ae-missing-release-tag": { "logLevel": "none" },
"ae-unresolved-link": { "logLevel": "none" }
}
}
}
49 changes: 49 additions & 0 deletions test/integration/generated/petstore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "petstore",
"author": "Microsoft Corporation",
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
"version": "1.0.0-preview1",
"dependencies": { "@azure/core-http": "^1.1.4", "tslib": "^1.9.3" },
"keywords": ["node", "azure", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "./dist/petstore.js",
"module": "./esm/index.js",
"types": "./esm/index.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",
"@microsoft/api-extractor": "7.9.10",
"mkdirp": "^1.0.4"
},
"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 && mkdirp ./review && npm run extract-api",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/petstore.js.map'\" -o ./dist/petstore.min.js ./dist/petstore.js",
"prepack": "npm install && npm run build",
"extract-api": "api-extractor run --local"
},
"sideEffects": false,
"autoPublish": true
}
28 changes: 28 additions & 0 deletions test/integration/generated/petstore/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import rollup from "rollup";
import nodeResolve from "rollup-plugin-node-resolve";
import sourcemaps from "rollup-plugin-sourcemaps";

/** @type {rollup.RollupFileOptions} */
const config = {
input: "./esm/petStore.js",
external: ["@azure/core-http"],
output: {
file: "./dist/petstore.js",
format: "umd",
name: "Petstore",
sourcemap: true,
globals: {
"@azure/core-http": "coreHttp"
},
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;
3 changes: 3 additions & 0 deletions test/integration/generated/petstore/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./models";
export { PetStore } from "./petStore";
export { PetStoreContext } from "./petStoreContext";
Loading

0 comments on commit 0ee2670

Please # to comment.