Skip to content

Commit c02f5df

Browse files
authored
Fixed an enum related issue and add some RPs in the test (#669)
* Add databricks, fix several issues * Fixed a completer related issue and add support for credential * Add two m4 configuration and fix some issues * Add support for enum with one value * Fixed an enum related issue and add some RPs in the test
1 parent ce1b3af commit c02f5df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+11855
-124
lines changed

powershell/cmdlets/class.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ export class NewCmdletClass extends Class {
24682468
addDefaultInfo(cmdletParameter, vParam);
24692469
}
24702470

2471-
const isEnum = propertyType.schema.language.csharp?.enum !== undefined;
2471+
const isEnum = propertyType instanceof NewEnumImplementation;;
24722472
const hasEnum = propertyType instanceof NewArrayOf && propertyType.elementType instanceof NewEnumImplementation;
24732473
if (isEnum || hasEnum) {
24742474
cmdletParameter.add(new Attribute(ArgumentCompleterAttribute, { parameters: [`typeof(${hasEnum ? (<NewArrayOf>propertyType).elementType.declaration : propertyType.declaration})`] }));
@@ -2613,7 +2613,7 @@ export class NewCmdletClass extends Class {
26132613
// regularCmdletParameter.add(new Attribute(ArgumentCompleterAttribute, { parameters: [`typeof(${this.declaration})`] }));
26142614
}
26152615

2616-
const isEnum = propertyType.schema.language.csharp?.enum !== undefined;
2616+
const isEnum = propertyType instanceof NewEnumImplementation;
26172617
const hasEnum = propertyType instanceof NewArrayOf && propertyType.elementType instanceof NewEnumImplementation;
26182618
if (isEnum || hasEnum) {
26192619
regularCmdletParameter.add(new Attribute(ArgumentCompleterAttribute, { parameters: [`typeof(${hasEnum ? (<NewArrayOf>propertyType).elementType.declaration : propertyType.declaration})`] }));

powershell/llcsharp/schema/schema-resolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { EnhancedTypeDeclaration, NewEnhancedTypeDeclaration } from './extended-
2525
import { PwshModel } from '../../utils/PwshModel';
2626
import { NewModelState } from '../../utils/model-state';
2727
import { Channel, Host, Session, startSession } from '@azure-tools/autorest-extension-base';
28+
import { schemaHasEnum } from '../validations';
2829

2930
export class SchemaDefinitionResolver {
3031
private readonly cache = new Map<string, EnhancedTypeDeclaration>();
@@ -244,6 +245,9 @@ export class NewSchemaDefinitionResolver {
244245
return new NewString(schema, required);
245246
}
246247
case SchemaType.SealedChoice:
248+
if (schema.language.default.skip === true) {
249+
return new NewString(schema, required);
250+
}
247251
return new NewEnumImplementation(schema, required);
248252
case undefined:
249253
if (schema.extensions && schema.extensions['x-ms-enum']) {

powershell/llcsharp/schema/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ ${this.validateEnum(eventListener, property)}
398398
return `await ${eventListener}.AssertRegEx(${nameof(property.value)},${property},@"${pattern}");`;
399399
}
400400
private validateEnum(eventListener: Variable, property: Variable): string {
401-
if (this.schema.type !== SchemaType.SealedChoice) {
401+
if (this.schema.type !== SchemaType.SealedChoice && this.schema.type != SchemaType.Choice) {
402402
return '';
403403
}
404404
const choiceValues = (<SealedChoiceSchema>this.schema).choices.map((c) => c.value);

powershell/plugins/plugin-create-inline-properties.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ function createVirtualProperties(schema: ObjectSchema, stack: Array<string>, thr
270270
alias: [],
271271
required: property.required || property.language.default.required
272272
});
273-
// dolauli, set constant value and make it readonly, if it is constant
274-
if (property.schema.type === SchemaType.Constant) {
275-
property.language.default.readOnly = true;
276-
property.language.default.constantValue = (<ConstantSchema>property.schema).value.value;
277-
}
278273
}
279274

280275
// resolve name collisions.

powershell/plugins/plugin-tweak-model.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { Property, codeModelSchema, CodeModel, StringSchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ChoiceSchema, Scheme, Schema, ConstantSchema } from '@azure-tools/codemodel';
5+
import { Property, SealedChoiceSchema, codeModelSchema, CodeModel, StringSchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ChoiceSchema, Scheme, Schema, ConstantSchema } from '@azure-tools/codemodel';
66
//import { ModelState } from '@azure-tools/codemodel-v3';
77
//import { KnownMediaType, knownMediaType, ParameterLocation, getPolymorphicBases, isSchemaObject, JsonType, Property, Schema, processCodeModel, StringFormat, codemodel, ModelState } from '@azure-tools/codemodel-v3';
88
import { pascalCase, deconstruct, fixLeadingNumber, serialize, KnownMediaType } from '@azure-tools/codegen';
@@ -286,6 +286,21 @@ async function tweakModelV2(state: State): Promise<PwshModel> {
286286
} else if (parameter.schema.type === SchemaType.Constant) {
287287
const constantSchema = parameter.schema as ConstantSchema;
288288
parameter.language.default.constantValue = constantSchema.value.value;
289+
} else if (parameter.schema.type === SchemaType.SealedChoice) {
290+
const sealedChoiceSchema = parameter.schema as SealedChoiceSchema;
291+
if (sealedChoiceSchema.choices.length === 1) {
292+
parameter.language.default.constantValue = sealedChoiceSchema.choices[0].value;
293+
if (sealedChoiceSchema.language.default.skip !== false) {
294+
sealedChoiceSchema.language.default.skip = true;
295+
}
296+
}
297+
}
298+
} else {
299+
if (parameter.schema.type === SchemaType.SealedChoice) {
300+
const sealedChoiceSchema = parameter.schema as SealedChoiceSchema;
301+
if (sealedChoiceSchema.choices.length === 1) {
302+
sealedChoiceSchema.language.default.skip = false;
303+
}
289304
}
290305
}
291306
}
@@ -306,6 +321,21 @@ async function tweakModelV2(state: State): Promise<PwshModel> {
306321
} else if (property.schema.type === SchemaType.Constant) {
307322
const constantSchema = property.schema as ConstantSchema;
308323
property.language.default.constantValue = constantSchema.value.value;
324+
} else if (property.schema.type === SchemaType.SealedChoice) {
325+
const sealedChoiceSchema = property.schema as SealedChoiceSchema;
326+
if (sealedChoiceSchema.choices.length === 1) {
327+
property.language.default.constantValue = sealedChoiceSchema.choices[0].value;
328+
if (sealedChoiceSchema.language.default.skip !== false) {
329+
sealedChoiceSchema.language.default.skip = true;
330+
}
331+
}
332+
}
333+
} else {
334+
if (property.schema.type === SchemaType.SealedChoice) {
335+
const sealedChoiceSchema = property.schema as SealedChoiceSchema;
336+
if (sealedChoiceSchema.choices.length === 1) {
337+
sealedChoiceSchema.language.default.skip = false;
338+
}
309339
}
310340
}
311341
}
Lines changed: 109 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,125 @@
11
{
2-
3-
"swagger": "2.0",
4-
"info": {
5-
"title": "DatabricksClient",
6-
"version": "2018-04-01",
7-
"description": "ARM Databricks"
8-
},
9-
"host": "management.azure.com",
10-
"schemes": [
11-
"https"
12-
],
13-
"consumes": [
14-
"application/json"
15-
],
16-
"produces": [
17-
"application/json"
18-
],
19-
"security": [
20-
{
21-
"azure_auth": [
22-
"user_impersonation"
23-
]
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "DatabricksClient",
5+
"version": "2018-04-01",
6+
"description": "ARM Databricks"
7+
},
8+
"host": "management.azure.com",
9+
"schemes": [
10+
"https"
11+
],
12+
"consumes": [
13+
"application/json"
14+
],
15+
"produces": [
16+
"application/json"
17+
],
18+
"security": [
19+
{
20+
"azure_auth": [
21+
"user_impersonation"
22+
]
23+
}
24+
],
25+
"securityDefinitions": {
26+
"azure_auth": {
27+
"type": "oauth2",
28+
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
29+
"flow": "implicit",
30+
"description": "Azure Active Directory OAuth2 Flow",
31+
"scopes": {
32+
"user_impersonation": "impersonate your user account"
2433
}
25-
],
26-
"securityDefinitions": {
27-
"azure_auth": {
28-
"type": "oauth2",
29-
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
30-
"flow": "implicit",
31-
"description": "Azure Active Directory OAuth2 Flow",
32-
"scopes": {
33-
"user_impersonation": "impersonate your user account"
34+
}
35+
},
36+
"paths": {
37+
"/subscriptions/resourceGroup": {
38+
"get": {
39+
"tags": [
40+
"Workspaces"
41+
],
42+
"operationId": "Workspaces_Get",
43+
"description": "Gets the workspace.",
44+
"responses": {
45+
"200": {
46+
"description": "OK-Return workspace."
47+
}
3448
}
3549
}
36-
},
37-
"paths": {
38-
"/subscriptions/resourceGroup": {
39-
"get": {
40-
"tags": [
41-
"Workspaces"
42-
],
43-
"operationId": "Workspaces_Get",
44-
"description": "Gets the workspace.",
45-
"responses": {
46-
"200": {
47-
"description": "OK-Return workspace."
48-
}
49-
}
50+
}
51+
},
52+
"definitions": {
53+
"Model": {
54+
"type": "object",
55+
"properties": {
56+
"message": {
57+
"type": "string"
58+
},
59+
"code": {
60+
"type": "integer"
5061
}
5162
}
5263
},
53-
"definitions": {
54-
"Model": {
55-
"type": "object",
56-
"properties": {
57-
"message": {
58-
"type": "string"
59-
},
60-
"code": {
61-
"type": "integer"
62-
}
63-
}
64+
"Model2": {
65+
"type": "object",
66+
"properties": {
67+
"id": {
68+
"type": "integer"
6469
},
65-
"Model2": {
66-
"type": "object",
67-
"properties": {
68-
"id": {
69-
"type": "integer"
70-
},
71-
"username": {
72-
"type": "string"
73-
},
74-
"name": {
75-
"type": "string"
76-
}
77-
},
78-
"required": [
79-
"id",
80-
"username"
81-
]
70+
"username": {
71+
"type": "string"
8272
},
83-
"Model3": {
84-
"type": "object",
85-
"properties": {
86-
"id": {
87-
"type": "integer",
88-
"readOnly": true
89-
},
90-
"password": {
91-
"type": "string"
92-
}
93-
},
94-
"required": [
95-
"id",
96-
"username"
97-
]
98-
},
99-
"ContactInfo": {
100-
"type": "object",
101-
"properties": {
102-
"email": {
103-
"type": "string",
104-
"format": "email"
105-
},
106-
"phone": {
107-
"type": "string"
108-
}
73+
"name": {
74+
"type": "string"
10975
}
11076
},
111-
"User": {
112-
"type": "object",
113-
"properties": {
114-
"id": {
115-
"type": "integer"
116-
},
117-
"name": {
118-
"type": "string"
119-
},
120-
"contact_info": {
121-
"$ref": "#/definitions/ContactInfo"
122-
}
77+
"required": [
78+
"id",
79+
"username"
80+
]
81+
},
82+
"Model3": {
83+
"type": "object",
84+
"properties": {
85+
"id": {
86+
"type": "integer",
87+
"readOnly": true
88+
},
89+
"password": {
90+
"type": "string"
12391
}
12492
},
125-
"Model4": {
126-
"type": "object",
127-
"minProperties": 2,
128-
"maxProperties": 10
93+
"required": [
94+
"id",
95+
"username"
96+
]
97+
},
98+
"ContactInfo": {
99+
"type": "object",
100+
"properties": {
101+
"email": {
102+
"type": "string",
103+
"format": "email"
104+
},
105+
"phone": {
106+
"type": "string"
107+
}
108+
}
109+
},
110+
"User": {
111+
"type": "object",
112+
"properties": {
113+
"id": {
114+
"type": "integer"
115+
},
116+
"name": {
117+
"type": "string"
118+
},
119+
"contact_info": {
120+
"$ref": "#/definitions/ContactInfo"
121+
}
129122
}
130123
}
124+
}
131125
}

0 commit comments

Comments
 (0)