Skip to content

Commit

Permalink
Check for operation groups (#855)
Browse files Browse the repository at this point in the history
* Check for operation groups

* Update M4

* Update swaggers and test

* Update generated files
  • Loading branch information
joheredi authored Feb 2, 2021
1 parent 5d5535f commit 023ed10
Show file tree
Hide file tree
Showing 47 changed files with 432 additions and 79 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.6320
use-extension:
"@autorest/modelerfour": "4.15.448"
"@autorest/modelerfour": "4.15.456"

modelerfour:
# this runs a pre-namer step to clean up names
Expand Down
4 changes: 3 additions & 1 deletion src/generators/mappersGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ function writeMapperContraints(
.write("constraints:")
.block(() => {
if (Pattern) {
writer.write(`Pattern: new RegExp("${Pattern.source}"), `);
writer.write(
`Pattern: new RegExp("${Pattern.source.replace(/\\/g, "\\\\")}"), `
);
}

writeObjectProps(restContstraints, writer);
Expand Down
4 changes: 3 additions & 1 deletion src/generators/modelsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ function getExtensibleChoiceDescription(choice: UnionDetails) {

const valueDescriptions = choice.properties
.map(p => `**${p.value}**${p.description ? `: ${p.description}` : ""}`)
.join(` \\\n`);
.join(` \\\n`)
// Escape the character / to make sure we don't incorrectly announce a comment blocks /** */
.replace(/\//g, "\\/");
const enumName = getExtensibleEnumName(choice);
const enumLink = `{@link ${enumName}} can be used interchangeably with ${choice.name},\n this enum contains the known values that the service supports.`;

Expand Down
8 changes: 5 additions & 3 deletions src/transforms/urlTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export async function transformBaseUrl(

if (!$host) {
// No support yet for multi-baseUrl yet Issue #553
const { requests } = codeModel.operationGroups[0].operations[0];
isCustom = true;
endpoint = requests![0].protocol.http!.uri;
if (codeModel.operationGroups && codeModel.operationGroups.length) {
const { requests } = codeModel.operationGroups[0].operations[0];
isCustom = true;
endpoint = requests![0].protocol.http!.uri;
}
} else {
endpoint = $host.clientDefaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const pageRange: OperationQueryParameter = {
name: "Sequence",
element: {
constraints: {
Pattern: new RegExp("^d+(-d+)?$"),
Pattern: new RegExp("^\\d+(-\\d+)?$"),
MaxLength: 24,
MinLength: 1
},
Expand Down
20 changes: 4 additions & 16 deletions test/integration/generated/mediaTypes/src/mediaTypesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MediaTypesClientAnalyzeBody$binaryOptionalParams,
MediaTypesClientAnalyzeBody$jsonOptionalParams,
MediaTypesClientAnalyzeBodyResponse,
MediaTypesClientContentTypeWithEncodingOptionalParams,
MediaTypesClientContentTypeWithEncodingResponse
} from "./models";

Expand All @@ -31,12 +32,10 @@ export class MediaTypesClient extends MediaTypesClientContext {
/**
* Analyze body, that could be different media types.
* @param contentType Upload file type
* @param input Input parameter.
* @param options The options parameters.
*/
analyzeBody(
contentType: ContentType,
input: coreHttp.HttpRequestBody,
options?: MediaTypesClientAnalyzeBody$binaryOptionalParams
): Promise<MediaTypesClientAnalyzeBodyResponse>;
/**
Expand All @@ -54,11 +53,7 @@ export class MediaTypesClient extends MediaTypesClientContext {
*/
analyzeBody(
...args:
| [
ContentType,
coreHttp.HttpRequestBody,
MediaTypesClientAnalyzeBody$binaryOptionalParams?
]
| [ContentType, MediaTypesClientAnalyzeBody$binaryOptionalParams?]
| ["application/json", MediaTypesClientAnalyzeBody$jsonOptionalParams?]
): Promise<MediaTypesClientAnalyzeBodyResponse> {
let operationSpec: coreHttp.OperationSpec;
Expand All @@ -70,11 +65,7 @@ export class MediaTypesClient extends MediaTypesClientContext {
args[0] === "image/tiff"
) {
operationSpec = analyzeBody$binaryOperationSpec;
operationArguments = {
contentType: args[0],
input: args[1],
options: args[2]
};
operationArguments = { contentType: args[0], options: args[1] };
} else if (args[0] === "application/json") {
operationSpec = analyzeBody$jsonOperationSpec;
operationArguments = { contentType: args[0], options: args[1] };
Expand All @@ -94,15 +85,12 @@ export class MediaTypesClient extends MediaTypesClientContext {

/**
* Pass in contentType 'text/plain; encoding=UTF-8' to pass test. Value for input does not matter
* @param input Input parameter.
* @param options The options parameters.
*/
contentTypeWithEncoding(
input: string,
options?: coreHttp.OperationOptions
options?: MediaTypesClientContentTypeWithEncodingOptionalParams
): Promise<MediaTypesClientContentTypeWithEncodingResponse> {
const operationArguments: coreHttp.OperationArguments = {
input,
options: coreHttp.operationOptionsToRequestOptionsBase(options || {})
};
return this.sendOperationRequest(
Expand Down
12 changes: 11 additions & 1 deletion test/integration/generated/mediaTypes/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export type ContentType =

/** Optional parameters. */
export interface MediaTypesClientAnalyzeBody$binaryOptionalParams
extends coreHttp.OperationOptions {}
extends coreHttp.OperationOptions {
/** Input parameter. */
input?: coreHttp.HttpRequestBody;
}

/** Optional parameters. */
export interface MediaTypesClientAnalyzeBody$jsonOptionalParams
Expand All @@ -47,6 +50,13 @@ export type MediaTypesClientAnalyzeBodyResponse = {
};
};

/** Optional parameters. */
export interface MediaTypesClientContentTypeWithEncodingOptionalParams
extends coreHttp.OperationOptions {
/** Input parameter. */
input?: string;
}

/** Contains response data for the contentTypeWithEncoding operation. */
export type MediaTypesClientContentTypeWithEncodingResponse = {
/** The parsed response body. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ export const contentType: OperationParameter = {
};

export const input: OperationParameter = {
parameterPath: "input",
parameterPath: ["options", "input"],
mapper: {
serializedName: "input",
required: true,
type: {
name: "Stream"
}
Expand Down Expand Up @@ -103,10 +102,9 @@ export const contentType2: OperationParameter = {
};

export const input2: OperationParameter = {
parameterPath: "input",
parameterPath: ["options", "input"],
mapper: {
serializedName: "input",
required: true,
type: {
name: "String"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MediaTypesWithTracingClientAnalyzeBody$binaryOptionalParams,
MediaTypesWithTracingClientAnalyzeBody$jsonOptionalParams,
MediaTypesWithTracingClientAnalyzeBodyResponse,
MediaTypesWithTracingClientContentTypeWithEncodingOptionalParams,
MediaTypesWithTracingClientContentTypeWithEncodingResponse
} from "./models";

Expand All @@ -33,12 +34,10 @@ export class MediaTypesWithTracingClient extends MediaTypesWithTracingClientCont
/**
* Analyze body, that could be different media types.
* @param contentType Upload file type
* @param input Input parameter.
* @param options The options parameters.
*/
analyzeBody(
contentType: ContentType,
input: coreHttp.HttpRequestBody,
options?: MediaTypesWithTracingClientAnalyzeBody$binaryOptionalParams
): Promise<MediaTypesWithTracingClientAnalyzeBodyResponse>;
/**
Expand All @@ -58,7 +57,6 @@ export class MediaTypesWithTracingClient extends MediaTypesWithTracingClientCont
...args:
| [
ContentType,
coreHttp.HttpRequestBody,
MediaTypesWithTracingClientAnalyzeBody$binaryOptionalParams?
]
| [
Expand All @@ -75,11 +73,7 @@ export class MediaTypesWithTracingClient extends MediaTypesWithTracingClientCont
args[0] === "image/tiff"
) {
operationSpec = analyzeBody$binaryOperationSpec;
operationArguments = {
contentType: args[0],
input: args[1],
options: args[2]
};
operationArguments = { contentType: args[0], options: args[1] };
} else if (args[0] === "application/json") {
operationSpec = analyzeBody$jsonOperationSpec;
operationArguments = { contentType: args[0], options: args[1] };
Expand Down Expand Up @@ -114,19 +108,16 @@ export class MediaTypesWithTracingClient extends MediaTypesWithTracingClientCont

/**
* Pass in contentType 'text/plain; encoding=UTF-8' to pass test. Value for input does not matter
* @param input Input parameter.
* @param options The options parameters.
*/
async contentTypeWithEncoding(
input: string,
options?: coreHttp.OperationOptions
options?: MediaTypesWithTracingClientContentTypeWithEncodingOptionalParams
): Promise<MediaTypesWithTracingClientContentTypeWithEncodingResponse> {
const { span, updatedOptions } = createSpan(
"MediaTypesWithTracingClient-contentTypeWithEncoding",
coreHttp.operationOptionsToRequestOptionsBase(options || {})
);
const operationArguments: coreHttp.OperationArguments = {
input,
options: updatedOptions
};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export type ContentType =

/** Optional parameters. */
export interface MediaTypesWithTracingClientAnalyzeBody$binaryOptionalParams
extends coreHttp.OperationOptions {}
extends coreHttp.OperationOptions {
/** Input parameter. */
input?: coreHttp.HttpRequestBody;
}

/** Optional parameters. */
export interface MediaTypesWithTracingClientAnalyzeBody$jsonOptionalParams
Expand All @@ -47,6 +50,13 @@ export type MediaTypesWithTracingClientAnalyzeBodyResponse = {
};
};

/** Optional parameters. */
export interface MediaTypesWithTracingClientContentTypeWithEncodingOptionalParams
extends coreHttp.OperationOptions {
/** Input parameter. */
input?: string;
}

/** Contains response data for the contentTypeWithEncoding operation. */
export type MediaTypesWithTracingClientContentTypeWithEncodingResponse = {
/** The parsed response body. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ export const contentType: OperationParameter = {
};

export const input: OperationParameter = {
parameterPath: "input",
parameterPath: ["options", "input"],
mapper: {
serializedName: "input",
required: true,
type: {
name: "Stream"
}
Expand Down Expand Up @@ -103,10 +102,9 @@ export const contentType2: OperationParameter = {
};

export const input2: OperationParameter = {
parameterPath: "input",
parameterPath: ["options", "input"],
mapper: {
serializedName: "input",
required: true,
type: {
name: "String"
}
Expand Down
21 changes: 21 additions & 0 deletions test/integration/generated/noOperation/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/noOperation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Azure NoOperationsClient SDK for JavaScript

This package contains an isomorphic SDK for NoOperationsClient.

### Currently supported environments

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

### How to Install

```bash
npm install no-operation
```

### 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/noOperation/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" }
}
}
}
Loading

0 comments on commit 023ed10

Please # to comment.