From 9c32bf5e7d9e4753cf2b4289aeecf04636e55fea Mon Sep 17 00:00:00 2001 From: Prasad Ghangal Date: Tue, 24 Dec 2019 14:48:31 +0530 Subject: [PATCH] Use openapi-generator to generate go-server code Signed-off-by: Prasad Ghangal --- Makefile | 3 + build/codegen.sh | 10 + .../botframework.json | 3 +- protocol/openapi-config.yaml | 3 + swagger/TokenAPI.json | 396 ------------------ swagger/connectorAPI.md | 38 -- swagger/generateClient.cmd | 37 -- swagger/tokenAPI.md | 37 -- 8 files changed, 18 insertions(+), 509 deletions(-) create mode 100644 Makefile create mode 100755 build/codegen.sh rename swagger/ConnectorAPI.json => protocol/botframework.json (99%) create mode 100644 protocol/openapi-config.yaml delete mode 100644 swagger/TokenAPI.json delete mode 100644 swagger/connectorAPI.md delete mode 100644 swagger/generateClient.cmd delete mode 100644 swagger/tokenAPI.md diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..145bf59 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +codegen: + @build/codegen.sh + diff --git a/build/codegen.sh b/build/codegen.sh new file mode 100755 index 0000000..b21abc0 --- /dev/null +++ b/build/codegen.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +OUT_DIR="pkg" + +echo 'Generating code with openapi-generator-cli' +docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/protocol/botframework.json -o /local/${OUT_DIR} -g go -c /local/protocol/openapi-config.yaml + +# Fix permissions +sudo find ${OUT_DIR} -type d -exec chmod 755 {} \; +sudo find ${OUT_DIR} -type f -exec chmod 664 {} \; diff --git a/swagger/ConnectorAPI.json b/protocol/botframework.json similarity index 99% rename from swagger/ConnectorAPI.json rename to protocol/botframework.json index 827186e..3cdf647 100644 --- a/swagger/ConnectorAPI.json +++ b/protocol/botframework.json @@ -2671,4 +2671,5 @@ "in": "header" } } -} \ No newline at end of file +} + diff --git a/protocol/openapi-config.yaml b/protocol/openapi-config.yaml new file mode 100644 index 0000000..91dfa44 --- /dev/null +++ b/protocol/openapi-config.yaml @@ -0,0 +1,3 @@ +{ + "modelPackage": "botbuilder" +} diff --git a/swagger/TokenAPI.json b/swagger/TokenAPI.json deleted file mode 100644 index 76f1dc0..0000000 --- a/swagger/TokenAPI.json +++ /dev/null @@ -1,396 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "token", - "title": "Microsoft Bot Token API - V3.1", - "termsOfService": "https://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default.aspx", - "contact": { - "name": "Bot Framework", - "url": "https://botframework.com", - "email": "botframework@microsoft.com" - }, - "license": { - "name": "The MIT License (MIT)", - "url": "https://opensource.org/licenses/MIT" - } - }, - "host": "token.botframework.com", - "schemes": [ - "https" - ], - "paths": { - "/api/botsignin/GetSignInUrl": { - "get": { - "tags": [ - "BotSignIn" - ], - "operationId": "BotSignIn_GetSignInUrl", - "consumes": [], - "produces": [ - "application/json", - "text/json", - "application/xml", - "text/xml" - ], - "parameters": [ - { - "name": "state", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "code_challenge", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "emulatorUrl", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "finalRedirect", - "in": "query", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "", - "schema": { - "type": "string" - } - } - } - } - }, - "/api/usertoken/GetToken": { - "get": { - "tags": [ - "UserToken" - ], - "operationId": "UserToken_GetToken", - "consumes": [], - "produces": [ - "application/json", - "text/json", - "application/xml", - "text/xml" - ], - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "connectionName", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "channelId", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "code", - "in": "query", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "A Token Response object will be returned\r\n", - "schema": { - "$ref": "#/definitions/TokenResponse" - } - }, - "404": { - "description": "Resource was not found\r\n", - "schema": { - "$ref": "#/definitions/TokenResponse" - } - }, - "default": { - "description": "The operation failed and the response is an error object describing the status code and failure.", - "schema": { - "$ref": "#/definitions/ErrorResponse" - } - } - } - } - }, - "/api/usertoken/GetAadTokens": { - "post": { - "tags": [ - "UserToken" - ], - "operationId": "UserToken_GetAadTokens", - "consumes": [ - "application/json", - "text/json", - "application/xml", - "text/xml", - "application/x-www-form-urlencoded" - ], - "produces": [ - "application/json", - "text/json", - "application/xml", - "text/xml" - ], - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "connectionName", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "aadResourceUrls", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/AadResourceUrls" - } - }, - { - "name": "channelId", - "in": "query", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "An array of key value pairs", - "schema": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/TokenResponse" - } - } - }, - "default": { - "description": "The operation failed and the response is an error object describing the status code and failure.", - "schema": { - "$ref": "#/definitions/ErrorResponse" - } - } - } - } - }, - "/api/usertoken/SignOut": { - "delete": { - "tags": [ - "UserToken" - ], - "operationId": "UserToken_SignOut", - "consumes": [], - "produces": [], - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "connectionName", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "channelId", - "in": "query", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "The operation succeeded, there is no response.", - "schema": { - "$ref": "#/definitions/Void" - } - }, - "204": { - "description": "No Content" - }, - "default": { - "description": "The operation failed and the response is an error object describing the status code and failure.", - "schema": { - "$ref": "#/definitions/ErrorResponse" - } - } - } - } - }, - "/api/usertoken/GetTokenStatus": { - "get": { - "tags": [ - "UserToken" - ], - "operationId": "UserToken_GetTokenStatus", - "consumes": [], - "produces": [ - "application/json", - "text/json", - "application/xml", - "text/xml" - ], - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "type": "string" - }, - { - "name": "channelId", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "include", - "in": "query", - "required": false, - "type": "string" - } - ], - "responses": { - "200": { - "description": "An array of TokenStatus objects", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/TokenStatus" - } - } - }, - "default": { - "description": "The operation failed and the response is an error object describing the status code and failure.", - "schema": { - "$ref": "#/definitions/ErrorResponse" - } - } - } - } - } - }, - "definitions": { - "TokenResponse": { - "type": "object", - "properties": { - "channelId": { - "type": "string" - }, - "connectionName": { - "type": "string" - }, - "token": { - "type": "string" - }, - "expiration": { - "type": "string" - } - } - }, - "ErrorResponse": { - "type": "object", - "properties": { - "error": { - "$ref": "#/definitions/Error" - } - } - }, - "Error": { - "type": "object", - "properties": { - "code": { - "type": "string" - }, - "message": { - "type": "string" - }, - "innerHttpError": { - "$ref": "#/definitions/InnerHttpError" - } - } - }, - "InnerHttpError": { - "type": "object", - "properties": { - "statusCode": { - "format": "int32", - "type": "integer" - }, - "body": { - "type": "object" - } - } - }, - "AadResourceUrls": { - "type": "object", - "properties": { - "resourceUrls": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "Void": { - "type": "object", - "properties": {} - }, - "TokenStatus": { - "description": "The status of a particular token", - "type": "object", - "properties": { - "channelId": { - "description": "The channelId of the token status pertains to", - "type": "string" - }, - "connectionName": { - "description": "The name of the connection the token status pertains to", - "type": "string" - }, - "hasToken": { - "description": "True if a token is stored for this ConnectionName", - "type": "boolean" - }, - "serviceProviderDisplayName": { - "description": "The display name of the service provider for which this Token belongs to", - "type": "string" - } - } - } - }, - "securityDefinitions": { - "bearer_auth": { - "type": "apiKey", - "description": "Access token to authenticate calls to the Bot Connector Service.", - "name": "Authorization", - "in": "header" - } - } -} \ No newline at end of file diff --git a/swagger/connectorAPI.md b/swagger/connectorAPI.md deleted file mode 100644 index 57dd97a..0000000 --- a/swagger/connectorAPI.md +++ /dev/null @@ -1,38 +0,0 @@ -# BotFramework Connector - -> see https://aka.ms/autorest - -Configuration for generating BotFramework Connector SDK. - -``` yaml -add-credentials: true -openapi-type: data-plane -``` -The current release for the BotFramework Connector is v3.0. - -# Releases - -## Connector API 3.0 - -``` yaml $(go) -input-file: - - ConnectorAPI.json -``` - -### Connector API 3.0 - Python Settings - -These settings apply only when `--go` is specified on the command line. -DO NOT use `--basic-setup-py` as this will overwrite the existing setup.py files. -If you upgrade autorest from npm you may need to run `autorest ---reset` before continuing. - -``` yaml $(go) -go: - license-header: MICROSOFT_MIT_NO_VERSION - add-credentials: true - payload-flattening-threshold: 2 - namespace: botframework.tokenApi - package-name: botframework-Token - override-client-name: TokenApiClient - clear-output-folder: true - output-folder: ./generated -``` diff --git a/swagger/generateClient.cmd b/swagger/generateClient.cmd deleted file mode 100644 index 10be464..0000000 --- a/swagger/generateClient.cmd +++ /dev/null @@ -1,37 +0,0 @@ -@echo off - -rd /s /q generated -echo WARNING: There is manual code for lines 127-130 in attachments_operations_async.py and lines 12-26 in the connector_client.py. -echo Calling this command script has removed those sections of code. - -@echo on -call npx autorest README.md --go --use=".\node_modules\@microsoft.azure\autorest.go" -@echo off - -pushd generated -call npx replace "query_parameters\['api-version'\][^\n]+\n" "" . --recursive --include="*.py" -popd - -rd /s /q ..\botbuilder-schema\botbuilder\schema -rd /s /q ..\botframework-connector\botframework\connector\operations -rd /s /q ..\botframework-connector\botframework\connector\aio -del ..\botframework-connector\botframework\connector\connector_client.py - -move generated\botframework\connector\models ..\botbuilder-schema\botbuilder\schema -move generated\botframework\connector\operations ..\botframework-connector\botframework\connector\operations -move generated\botframework\connector\aio ..\botframework-connector\botframework\connector\aio -move generated\botframework\connector\_connector_client.py ..\botframework-connector\botframework\connector\connector_client.py -move generated\botframework\connector\version.py ..\botframework-connector\botframework\connector\version.py -move generated\botframework\connector\_configuration.py ..\botframework-connector\botframework\connector\_configuration.py - -@echo on -call npx autorest tokenAPI.md --go --use=".\node_modules\@microsoft.azure\autorest.go" -@echo off - -echo Move tokenAPI to botframework-connector -rd /s /q ..\botframework-connector\botframework\connector\token_api -move tokenApi\botframework\tokenApi ..\botframework-connector\botframework\connector\token_api - -echo Removing generated folders ("generated/", "tokenApi/") - -rd /s /q tokenApi diff --git a/swagger/tokenAPI.md b/swagger/tokenAPI.md deleted file mode 100644 index 41967b9..0000000 --- a/swagger/tokenAPI.md +++ /dev/null @@ -1,37 +0,0 @@ -# BotFramework Token - -> see https://aka.ms/autorest - -Configuration for generating BotFramework Token SDK. - -``` yaml -add-credentials: true -openapi-type: data-plane -``` -The current release for the BotFramework Token is v3.0. - -# Releases - -## Token API 3.0 - -``` yaml -input-file: TokenAPI.json -``` - -### Token API 3.0 - Python Settings - -These settings apply only when `--go` is specified on the command line. -DO NOT use `--basic-setup-py` as this will overwrite the existing setup.py files. -If you upgrade autorest from npm you may need to run `autorest ---reset` before continuing. - -``` yaml $(go) -go: - license-header: MICROSOFT_MIT_NO_VERSION - add-credentials: true - payload-flattening-threshold: 2 - namespace: botframework.tokenApi - package-name: botframework-Token - override-client-name: TokenApiClient - clear-output-folder: true - output-folder: ./tokenApi -```