Skip to content

Commit

Permalink
Fix the support of generating Example Model of DataFactoryKeyVaultRef…
Browse files Browse the repository at this point in the history
…erence type of DataFactoryElement (#6561)

* support keyvaultreference dfe type

* update changelog and version

* fix lint error
  • Loading branch information
RodgeFu authored Aug 8, 2023
1 parent b18b218 commit 3f3d96c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
12 changes: 12 additions & 0 deletions tools/sdk-testgen/packages/autorest.testmodeler/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@autorest/testmodeler",
"entries": [
{
"version": "2.6.1",
"tag": "@autorest/testmodeler_v2.6.1",
"date": "Fri, 21 Jul 2023 08:36:29 GMT",
"comments": {
"patch": [
{
"comment": "Support DataFactoryKeyVaultSecretReference of DataFactoryElement"
}
]
}
},
{
"version": "2.6.0",
"tag": "@autorest/testmodeler_v2.6.0",
Expand Down
9 changes: 8 additions & 1 deletion tools/sdk-testgen/packages/autorest.testmodeler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log - @autorest/testmodeler

This log was last generated on Mon, 19 Jun 2023 08:50:04 GMT and should not be manually modified.
This log was last generated on Fri, 21 Jul 2023 08:36:29 GMT and should not be manually modified.

## 2.6.1
Fri, 21 Jul 2023 08:36:29 GMT

### Patches

- Support DataFactoryKeyVaultSecretReference of DataFactoryElement

## 2.6.0
Mon, 19 Jun 2023 08:50:04 GMT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorest/testmodeler",
"version": "2.6.0",
"version": "2.6.1",
"description": "Autorest extension for testmodeler",
"main": "dist/index.js",
"scripts": {
Expand Down
25 changes: 19 additions & 6 deletions tools/sdk-testgen/packages/autorest.testmodeler/src/core/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class ExampleValue {
const format = extensions[xMsFormat];
const elementFormat = extensions[xMsFormatElementType];

const dfeObjSchema = ExampleValue.createSchemaForDfeObject(rawValue, format);
const dfeObjSchema = ExampleValue.createSchemaForDfeObject(session, rawValue, format);
if (dfeObjSchema) {
return this.createInstance(session, rawValue, usedProperties, dfeObjSchema, language, undefined, searchDescents);
} else {
Expand All @@ -231,17 +231,30 @@ export class ExampleValue {
return instance;
}

private static createSchemaForDfeObject(raw: any, dfeFormat: string): ObjectSchema | undefined {
private static createSchemaForDfeObject(session: Session<TestCodeModel>, raw: any, dfeFormat: string): ObjectSchema | undefined {
const dfeObjectType = 'type';
const dfeObjectValue = 'value';
const dfeObjectTypeValues = ['Expression', 'SecureString', 'AzureKeyVaultSecretReference'];
const dfeObjectSchemaPrefix = 'DataFactoryElement-';

if (Object(raw) && raw[dfeObjectType] && raw[dfeObjectValue] && dfeObjectTypeValues.includes(raw[dfeObjectType])) {
if (Object(raw) && raw[dfeObjectType] && raw[dfeObjectValue]) {
const r = new ObjectSchema(dfeObjectSchemaPrefix + raw[dfeObjectType], '');
r.addProperty(new Property(dfeObjectType, '', new StringSchema(`${dfeFormat}-${dfeObjectType}`, '')));
r.addProperty(new Property(dfeObjectValue, '', new StringSchema(`${dfeFormat}-${dfeObjectValue}`, '')));
return r;
switch (raw[dfeObjectType]) {
case 'Expression':
case 'SecureString':
r.addProperty(new Property(dfeObjectValue, '', new StringSchema(`${dfeFormat}-${dfeObjectValue}`, '')));
return r;
case 'AzureKeyVaultSecretReference': {
const valueSchema = session.model.schemas.objects.find((s) => s.language.default.name === `AzureKeyVaultSecretReference`);
if (!valueSchema) {
throw new Error('Cant find schema for the value of DataFactoryElement KeyVaultSecret Reference');
}
r.addProperty(new Property(dfeObjectValue, '', valueSchema));
return r;
}
default:
return undefined;
}
}
return undefined;
}
Expand Down

0 comments on commit 3f3d96c

Please sign in to comment.