Skip to content

Commit

Permalink
Property 'required' missing in the Spec Mapper (#834)
Browse files Browse the repository at this point in the history
* Code changes to add required to mapper

* Generated SDK

* Additional Generated Changes

* Add Test Case

* Smoke Test Changes
  • Loading branch information
sarangan12 authored Jan 14, 2021
2 parents 48795ec + 3b5f8a7 commit 039817e
Show file tree
Hide file tree
Showing 19 changed files with 565 additions and 20 deletions.
37 changes: 31 additions & 6 deletions src/generators/operationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,19 @@ function writeSpec(spec: OperationSpecDetails, writer: CodeBlockWriter): void {
? `Mappers.${requestBody.mapper}`
: `${JSON.stringify(requestBody.mapper)}`;

writer.write(
`requestBody: { parameterPath: ${JSON.stringify(
requestBody.parameterPath
)}, mapper: ${mapper}}, `
);
if (requestBody.required) {
writer.write(
`requestBody: { parameterPath: ${JSON.stringify(
requestBody.parameterPath
)}, mapper: {...${mapper}, required: true}},`
);
} else {
writer.write(
`requestBody: { parameterPath: ${JSON.stringify(
requestBody.parameterPath
)}, mapper: ${mapper}}, `
);
}
}

if (formDataParams) {
Expand Down Expand Up @@ -251,6 +259,7 @@ type RequestBody = {
[propertyName: string]: ParameterPath;
};
mapper: string | Mapper;
required: boolean;
};

/**
Expand All @@ -277,6 +286,21 @@ function buildRequestBody({

// First get the mapper, this will be the mapper for the parameter before flattening
const mapper = requestBody[0].mapper;
let required: boolean = requestBody[0].required ?? false;

// If one of the requestbody in the spec has required set to true,
// we do not want to look into others.
if (!required) {
for (const rb of requestBody) {
required = rb.required
? rb.required
: rb.parameter.groupedBy && rb.parameter.groupedBy.required
? rb.parameter.groupedBy.required
: required;

if (required) break;
}
}

// Generate the request body from the parameters
const parameters = requestBody.reduce((acc, curr) => {
Expand Down Expand Up @@ -313,7 +337,8 @@ function buildRequestBody({

return {
parameterPath: parameters,
mapper
mapper,
required
};
}

Expand Down
21 changes: 21 additions & 0 deletions test/integration/generated/mapperrequired/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 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.
27 changes: 27 additions & 0 deletions test/integration/generated/mapperrequired/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Azure MapperRequiredClient SDK for JavaScript

This package contains an isomorphic SDK for MapperRequiredClient.

### Currently supported environments

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

### How to Install

```bash
npm install mapperrequired
```

### 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)
18 changes: 18 additions & 0 deletions test/integration/generated/mapperrequired/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" }
}
}
}
48 changes: 48 additions & 0 deletions test/integration/generated/mapperrequired/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "mapperrequired",
"author": "Microsoft Corporation",
"description": "The key vault client performs cryptographic key operations and vault operations against the Key Vault service.",
"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/mapperrequired.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"
},
"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 && npm run extract-api",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/mapperrequired.js.map'\" -o ./dist/mapperrequired.min.js ./dist/mapperrequired.js",
"prepack": "npm install && npm run build",
"extract-api": "api-extractor run --local"
},
"sideEffects": false,
"autoPublish": true
}
36 changes: 36 additions & 0 deletions test/integration/generated/mapperrequired/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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/mapperRequiredClient.js",
external: ["@azure/core-http"],
output: {
file: "./dist/mapperrequired.js",
format: "umd",
name: "Mapperrequired",
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;
11 changes: 11 additions & 0 deletions test/integration/generated/mapperrequired/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export * from "./models";
export { MapperRequiredClient } from "./mapperRequiredClient";
export { MapperRequiredClientContext } from "./mapperRequiredClientContext";
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 * as coreHttp from "@azure/core-http";
import * as Parameters from "./models/parameters";
import * as Mappers from "./models/mappers";
import { MapperRequiredClientContext } from "./mapperRequiredClientContext";
import {
MapperRequiredClientOptionalParams,
MapperRequiredClientUpdateCertificateIssuerOptionalParams,
MapperRequiredClientUpdateCertificateIssuerResponse
} from "./models";

export class MapperRequiredClient extends MapperRequiredClientContext {
/**
* Initializes a new instance of the MapperRequiredClient class.
* @param $host server parameter
* @param options The parameter options
*/
constructor($host: string, options?: MapperRequiredClientOptionalParams) {
super($host, options);
}

/**
* The UpdateCertificateIssuer operation performs an update on the specified certificate issuer entity.
* This operation requires the certificates/setissuers permission.
* @param issuerName The name of the issuer.
* @param options The options parameters.
*/
updateCertificateIssuer(
issuerName: string,
options?: MapperRequiredClientUpdateCertificateIssuerOptionalParams
): Promise<MapperRequiredClientUpdateCertificateIssuerResponse> {
const operationArguments: coreHttp.OperationArguments = {
issuerName,
options: coreHttp.operationOptionsToRequestOptionsBase(options || {})
};
return this.sendOperationRequest(
operationArguments,
updateCertificateIssuerOperationSpec
) as Promise<MapperRequiredClientUpdateCertificateIssuerResponse>;
}
}
// Operation Specifications
const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false);

const updateCertificateIssuerOperationSpec: coreHttp.OperationSpec = {
path: "/certificates/issuers/{issuer-name}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: { type: { name: "String" } }
}
},
requestBody: {
parameterPath: { provider: ["options", "provider"] },
mapper: { ...Mappers.CertificateIssuerUpdateParameters, required: true }
},
urlParameters: [Parameters.$host, Parameters.issuerName],
headerParameters: [Parameters.contentType, Parameters.accept],
mediaType: "json",
serializer
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 * as coreHttp from "@azure/core-http";
import { MapperRequiredClientOptionalParams } from "./models";

const packageName = "mapperrequired";
const packageVersion = "1.0.0-preview1";

export class MapperRequiredClientContext extends coreHttp.ServiceClient {
$host: string;

/**
* Initializes a new instance of the MapperRequiredClientContext class.
* @param $host server parameter
* @param options The parameter options
*/
constructor($host: string, options?: MapperRequiredClientOptionalParams) {
if ($host === undefined) {
throw new Error("'$host' cannot be null");
}

// Initializing default values for options
if (!options) {
options = {};
}

if (!options.userAgent) {
const defaultUserAgent = coreHttp.getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`;
}

super(undefined, options);

this.requestContentType = "application/json; charset=utf-8";

this.baseUri = options.endpoint || "{$host}";

// Parameter assignments
this.$host = $host;
}
}
44 changes: 44 additions & 0 deletions test/integration/generated/mapperrequired/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 * as coreHttp from "@azure/core-http";

/** The certificate issuer update parameters. */
export interface CertificateIssuerUpdateParameters {
/** The issuer provider. */
provider?: string;
}

/** Optional parameters. */
export interface MapperRequiredClientUpdateCertificateIssuerOptionalParams
extends coreHttp.OperationOptions {
/** The issuer provider. */
provider?: string;
}

/** Contains response data for the updateCertificateIssuer operation. */
export type MapperRequiredClientUpdateCertificateIssuerResponse = {
/** The parsed response body. */
body: string;

/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/** The response body as text (string format) */
bodyAsText: string;

/** The response body as parsed JSON or XML */
parsedBody: string;
};
};

/** Optional parameters. */
export interface MapperRequiredClientOptionalParams
extends coreHttp.ServiceClientOptions {
/** Overrides client endpoint. */
endpoint?: string;
}
Loading

0 comments on commit 039817e

Please sign in to comment.