Skip to content

Commit

Permalink
Add hidden to generated class context (#831)
Browse files Browse the repository at this point in the history
* Update ts-morph dependency to latest version

* Code change to add @hidden to generated class and context

* Add new test case to generate SDK with hidden

* Generated SDKs

* Adding a spec file for appconfiguration export

* Smoke Test Changes

* Added comments

* Change hasCustomayer to hideClient

* Change hideClient to hideClients

* Minor Fix
  • Loading branch information
sarangan12 authored Jan 11, 2021
1 parent c20fe96 commit 810897e
Show file tree
Hide file tree
Showing 660 changed files with 23,637 additions and 61,976 deletions.
292 changes: 97 additions & 195 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lodash": "^4.17.15",
"prettier": "^1.19.1",
"source-map-support": "^0.5.16",
"ts-morph": "^5.0.0"
"ts-morph": "^9.0.0"
},
"devDependencies": {
"@autorest/test-server": "^3.0.27",
Expand Down
12 changes: 11 additions & 1 deletion src/generators/clientContextFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { formatJsDocParam } from "./utils/parameterUtils";
export function generateClientContext(
clientDetails: ClientDetails,
packageDetails: PackageDetails,
project: Project
project: Project,
hideClients: boolean
) {
const importedModels = new Set<string>();
const clientParams = clientDetails.parameters.filter(
Expand Down Expand Up @@ -48,6 +49,15 @@ export function generateClientContext(
writePackageInfo(sourceFile, packageDetails);

const contextClass = buildClass(sourceFile, clientContextClassName);

if(hideClients) {
contextClass.addJsDoc({
tags: [{
tagName: "hidden"
}],
});
}

writeClassProperties(contextClass, clientParams, importedModels);

const classConstructor = buildConstructor(contextClass, {
Expand Down
10 changes: 9 additions & 1 deletion src/generators/clientFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { addPagingImports } from "./utils/pagingOperations";

type OperationDeclarationDetails = { name: string; typeName: string };

export function generateClient(clientDetails: ClientDetails, project: Project) {
export function generateClient(clientDetails: ClientDetails, project: Project, hideClients: boolean) {
const clientContextClassName = `${clientDetails.className}Context`;
const hasMappers = !!clientDetails.mappers.length;

Expand Down Expand Up @@ -123,6 +123,14 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
isExported: true
});

if(hideClients) {
clientClass.addJsDoc({
tags: [{
tagName: "hidden"
}],
});
}

const importedModels = new Set<string>();

writeConstructor(clientDetails, clientClass, importedModels);
Expand Down
9 changes: 6 additions & 3 deletions src/typescriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function generateTypeScriptLibrary(
host: Host
): Promise<void> {
const project = new Project({
useVirtualFileSystem: true,
useInMemoryFileSystem: true,
manipulationSettings: {
indentationText: IndentationText.TwoSpaces
}
Expand Down Expand Up @@ -76,6 +76,9 @@ export async function generateTypeScriptLibrary(
const shouldGenerateLicense: boolean =
(await host.GetValue("license-header")) || false;

const hideClients: boolean =
(await host.GetValue("hide-clients")) || false;

// Skip metadata generation if `generate-metadata` is explicitly false
if ((await host.GetValue("generate-metadata")) !== false) {
generatePackageJson(clientDetails, packageDetails, project);
Expand All @@ -86,8 +89,8 @@ export async function generateTypeScriptLibrary(
generateApiExtractorConfig(clientDetails, project);
}

generateClient(clientDetails, project);
generateClientContext(clientDetails, packageDetails, project);
generateClient(clientDetails, project, hideClients);
generateClientContext(clientDetails, packageDetails, project, hideClients);
generateModels(clientDetails, project);

generateMappers(clientDetails, project);
Expand Down
39 changes: 39 additions & 0 deletions test/integration/appConfigurationExport.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AppConfigurationClient } from "./generated/appconfigurationexport/src";
import * as fs from "fs";
import { assert } from "chai";

describe("Check Hidden Header", () => {
let client: AppConfigurationClient;

beforeEach(()=>{
const endpoint: string = "sampleEndPoint";
client = new AppConfigurationClient(endpoint);
assert.notEqual(client, null);
})

it("Client Class File must have Hidden Header", async() => {
const content: string = fs.readFileSync(
"./test/integration/generated/appconfigurationexport/src/appConfigurationClient.ts",
"utf-8"
);

const containsHidden = content.includes(
"/** @hidden */\nexport class AppConfigurationClient extends AppConfigurationClientContext {"
);

assert.equal(containsHidden, true, "Expected hidden Header missing");
});

it("Client Context Class File must have Hidden Header", async() => {
const content: string = fs.readFileSync(
"./test/integration/generated/appconfigurationexport/src/appConfigurationClientContext.ts",
"utf-8"
);

const containsHidden = content.includes(
"/** @hidden */\nexport class AppConfigurationClientContext extends coreHttp.ServiceClient {"
);

assert.equal(containsHidden, true, "Expected hidden Header missing");
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Microsoft
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import rollup from "rollup";
import nodeResolve from "rollup-plugin-node-resolve";
import sourcemaps from "rollup-plugin-sourcemaps";

/**
* @type {rollup.RollupFileOptions}
*/
/** @type {rollup.RollupFileOptions} */
const config = {
input: "./esm/additionalPropertiesClient.js",
external: ["@azure/core-http"],
Expand Down
152 changes: 38 additions & 114 deletions test/integration/generated/additionalProperties/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
import * as coreHttp from "@azure/core-http";

export interface PetAPTrue {
/**
* Describes unknown properties. The value of an unknown property can be of "any" type.
*/
/** Describes unknown properties. The value of an unknown property can be of "any" type. */
[property: string]: any;
id: number;
name?: string;
/**
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
/** NOTE: This property will not be serialized. It can only be populated by the server. */
readonly status?: boolean;
}

Expand All @@ -27,197 +23,125 @@ export interface ErrorModel {
}

export interface PetAPObject {
/**
* Describes unknown properties. The value of an unknown property can be of "any" type.
*/
/** Describes unknown properties. The value of an unknown property can be of "any" type. */
[property: string]: any;
id: number;
name?: string;
/**
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
/** NOTE: This property will not be serialized. It can only be populated by the server. */
readonly status?: boolean;
}

export interface PetAPString {
/**
* Describes unknown properties. The value of an unknown property can be of "any" type.
*/
/** Describes unknown properties. The value of an unknown property can be of "any" type. */
[property: string]: any;
id: number;
name?: string;
/**
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
/** NOTE: This property will not be serialized. It can only be populated by the server. */
readonly status?: boolean;
}

export interface PetAPInProperties {
id: number;
name?: string;
/**
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
/** NOTE: This property will not be serialized. It can only be populated by the server. */
readonly status?: boolean;
/**
* Dictionary of <number>
*/
/** Dictionary of <number> */
additionalProperties?: { [propertyName: string]: number };
}

export interface PetAPInPropertiesWithAPString {
/**
* Describes unknown properties. The value of an unknown property can be of "any" type.
*/
/** Describes unknown properties. The value of an unknown property can be of "any" type. */
[property: string]: any;
id: number;
name?: string;
/**
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
/** NOTE: This property will not be serialized. It can only be populated by the server. */
readonly status?: boolean;
odataLocation: string;
/**
* Dictionary of <number>
*/
/** Dictionary of <number> */
additionalProperties?: { [propertyName: string]: number };
}

export type CatAPTrue = PetAPTrue & {
friendly?: boolean;
};

/**
* Contains response data for the createAPTrue operation.
*/
/** Contains response data for the createAPTrue operation. */
export type PetsCreateAPTrueResponse = PetAPTrue & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Contains response data for the createCatAPTrue operation.
*/
/** Contains response data for the createCatAPTrue operation. */
export type PetsCreateCatAPTrueResponse = CatAPTrue & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Contains response data for the createAPObject operation.
*/
/** Contains response data for the createAPObject operation. */
export type PetsCreateAPObjectResponse = PetAPObject & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Contains response data for the createAPString operation.
*/
/** Contains response data for the createAPString operation. */
export type PetsCreateAPStringResponse = PetAPString & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Contains response data for the createAPInProperties operation.
*/
/** Contains response data for the createAPInProperties operation. */
export type PetsCreateAPInPropertiesResponse = PetAPInProperties & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Contains response data for the createAPInPropertiesWithAPString operation.
*/
/** Contains response data for the createAPInPropertiesWithAPString operation. */
export type PetsCreateAPInPropertiesWithAPStringResponse = PetAPInPropertiesWithAPString & {
/**
* The underlying HTTP response.
*/
/** The underlying HTTP response. */
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
/** The response body as text (string format) */
bodyAsText: string;

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

/**
* Optional parameters.
*/
/** Optional parameters. */
export interface AdditionalPropertiesClientOptionalParams
extends coreHttp.ServiceClientOptions {
/**
* server parameter
*/
/** server parameter */
$host?: string;
/**
* Overrides client endpoint.
*/
/** Overrides client endpoint. */
endpoint?: string;
}
Loading

0 comments on commit 810897e

Please sign in to comment.