From 7cb3568b0f877fec70eb361fe81cb6bf77ecdcdc Mon Sep 17 00:00:00 2001 From: Xiaogang Date: Tue, 1 Sep 2020 16:52:17 +0800 Subject: [PATCH] Generate model for all the dictionaries and add support for unixtime (#685) * Enable two test cases, and drop the workaround for x-ms-enum * Add utils folder include a script to decrypt securestring * Generate model for all the dictionaries and add support for unixtime --- powershell/llcsharp/model/namespace.ts | 5 ++ powershell/llcsharp/schema/schema-resolver.ts | 5 +- tests-upgrade/Configuration.json | 1 + .../datamodels-datatypes-unixtime/readme.md | 10 +++ .../swagger.json | 76 +++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests-upgrade/datamodels-datatypes-unixtime/readme.md create mode 100644 tests-upgrade/datamodels-datatypes-unixtime/swagger.json diff --git a/powershell/llcsharp/model/namespace.ts b/powershell/llcsharp/model/namespace.ts index 57680266b50..58d0d0d64ac 100644 --- a/powershell/llcsharp/model/namespace.ts +++ b/powershell/llcsharp/model/namespace.ts @@ -179,6 +179,11 @@ export class NewModelsNamespace extends Namespace { this.NewResolveTypeDeclaration(schema, true, state); } } + if (schemas.dictionaries) { + for (const schema of schemas.dictionaries) { + this.NewResolveTypeDeclaration(schema, true, state); + } + } if (schemas.any) { for (const schema of schemas.any) { diff --git a/powershell/llcsharp/schema/schema-resolver.ts b/powershell/llcsharp/schema/schema-resolver.ts index fe51afa73ef..bd1eab1c708 100644 --- a/powershell/llcsharp/schema/schema-resolver.ts +++ b/powershell/llcsharp/schema/schema-resolver.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { codeModelSchema, ArraySchema, CodeModel, Schema as NewSchema, StringSchema, BooleanSchema, NumberSchema, ByteArraySchema, DateTimeSchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ConstantSchema, ChoiceSchema, DurationSchema, BinarySchema, DateSchema } from '@azure-tools/codemodel'; +import { codeModelSchema, ArraySchema, UnixTimeSchema, CodeModel, Schema as NewSchema, StringSchema, BooleanSchema, NumberSchema, ByteArraySchema, DateTimeSchema, ObjectSchema, GroupSchema, isObjectSchema, SchemaType, GroupProperty, ParameterLocation, Operation, Parameter, VirtualParameter, getAllProperties, ImplementationLocation, OperationGroup, Request, SchemaContext, ConstantSchema, ChoiceSchema, DurationSchema, BinarySchema, DateSchema } from '@azure-tools/codemodel'; import { ModelState, codemodel, IntegerFormat, NumberFormat, StringFormat, JsonType } from '@azure-tools/codemodel-v3'; import { Schema } from '../code-model'; @@ -222,6 +222,9 @@ export class NewSchemaDefinitionResolver { // fallback to int if the format isn't recognized return new NewNumeric(schema, required, required ? 'int' : 'int?'); + case SchemaType.UnixTime: + return new NewUnixTime(schema, required); + case SchemaType.Number: switch ((schema).precision) { case 64: diff --git a/tests-upgrade/Configuration.json b/tests-upgrade/Configuration.json index 9d25b6c293d..045f89ef52b 100644 --- a/tests-upgrade/Configuration.json +++ b/tests-upgrade/Configuration.json @@ -24,6 +24,7 @@ "datamodels-datatypes-integer", "datamodels-datatypes-string", "datamodels-datatypes-object", + "datamodels-datatypes-unixtime", "datamodels-combineschema", "directive-model", "directive-tableformat", diff --git a/tests-upgrade/datamodels-datatypes-unixtime/readme.md b/tests-upgrade/datamodels-datatypes-unixtime/readme.md new file mode 100644 index 00000000000..cd6b9c0ac24 --- /dev/null +++ b/tests-upgrade/datamodels-datatypes-unixtime/readme.md @@ -0,0 +1,10 @@ +### AutoRest Configuration +> see https://aka.ms/autorest + +``` yaml +require: + - $(this-folder)/../readme.azure.noprofile.md +input-file: + - $(this-folder)/swagger.json + +``` diff --git a/tests-upgrade/datamodels-datatypes-unixtime/swagger.json b/tests-upgrade/datamodels-datatypes-unixtime/swagger.json new file mode 100644 index 00000000000..27427d16396 --- /dev/null +++ b/tests-upgrade/datamodels-datatypes-unixtime/swagger.json @@ -0,0 +1,76 @@ +{ + "swagger": "2.0", + "info": { + "title": "DatabricksClient", + "version": "2018-04-01", + "description": "ARM Databricks" + }, + "host": "management.azure.com", + "schemes": [ + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "security": [ + { + "azure_auth": [ + "user_impersonation" + ] + } + ], + "securityDefinitions": { + "azure_auth": { + "type": "oauth2", + "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize", + "flow": "implicit", + "description": "Azure Active Directory OAuth2 Flow", + "scopes": { + "user_impersonation": "impersonate your user account" + } + } + }, + "paths": { + "/subscriptions/resourceGroup": { + "get": { + "tags": [ + "Workspaces" + ], + "operationId": "Workspaces_Get", + "description": "Gets the workspace.", + "responses": { + "200": { + "description": "OK-Return workspace." + }, + "default": { + "description": "Error response describing why the operation failed.", + "schema": { + "$ref": "#/definitions/BasicErrorModel" + } + } + } + } + } + }, + "definitions": { + "BasicErrorModel": { + "type": "object", + "required": [ + "message", + "code" + ], + "properties": { + "message": { + "type": "string" + }, + "code": { + "type": "integer", + "format": "unixtime" + } + } + } + } +} \ No newline at end of file