From de69480ccfb70ad4fa3a769ba7fc63ac3017ed42 Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Wed, 18 Sep 2024 15:40:13 -0700 Subject: [PATCH 1/6] add rest client collection generation --- .../jcuSrc/Commands/VersionVarWriter.cs | 1 + SDKBuildScripts/Linux/rest_client_build.sh | 7 + SDKBuildScripts/Windows/rest_client_build.bat | 5 + SDKBuildScripts/shared_build.bat | 1 + SDKBuildScripts/shared_build.sh | 1 + SDKGenerator.njsproj | 15 ++ SDKGenerator.sln | 20 +-- targets/restclient/make.js | 147 ++++++++++++++++++ targets/restclient/replacements.json | 30 ++++ targets/restclient/templates/playfab.http.ejs | 21 +++ .../restclient/templates/settings.json.ejs | 15 ++ 11 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 SDKBuildScripts/Linux/rest_client_build.sh create mode 100644 SDKBuildScripts/Windows/rest_client_build.bat create mode 100644 targets/restclient/make.js create mode 100644 targets/restclient/replacements.json create mode 100644 targets/restclient/templates/playfab.http.ejs create mode 100644 targets/restclient/templates/settings.json.ejs diff --git a/JenkinsConsoleUtility/jcuSrc/Commands/VersionVarWriter.cs b/JenkinsConsoleUtility/jcuSrc/Commands/VersionVarWriter.cs index 5ef97b9d4..b3f45ce71 100644 --- a/JenkinsConsoleUtility/jcuSrc/Commands/VersionVarWriter.cs +++ b/JenkinsConsoleUtility/jcuSrc/Commands/VersionVarWriter.cs @@ -139,6 +139,7 @@ private string GetSdkGenKey(string sdkName) case "xplatcppsdk": case "xplatbetasdk": case "xplatcppsdk-private-switch": case "xplatcppsdk-private-ps4": case "xplatcppsdk-private-gdk": return "xplatcppsdk"; case "javasdk": case "javabetasdk": return "java"; case "pythonsdk": case "pythonbetasdk": return "pythonsdk"; + case "restclientcollection": return "restclient"; default: return sdkName.ToLower(); // Most new sdks have matching names } diff --git a/SDKBuildScripts/Linux/rest_client_build.sh b/SDKBuildScripts/Linux/rest_client_build.sh new file mode 100644 index 000000000..d28cbc4cf --- /dev/null +++ b/SDKBuildScripts/Linux/rest_client_build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SdkName="RESTClientCollection" +delSrc=false + +cd .. +. ./shared_build.sh \ No newline at end of file diff --git a/SDKBuildScripts/Windows/rest_client_build.bat b/SDKBuildScripts/Windows/rest_client_build.bat new file mode 100644 index 000000000..f6ab84893 --- /dev/null +++ b/SDKBuildScripts/Windows/rest_client_build.bat @@ -0,0 +1,5 @@ +set SdkName=RESTClientCollection +set delSrc=false + +cd .. +call shared_build.bat diff --git a/SDKBuildScripts/shared_build.bat b/SDKBuildScripts/shared_build.bat index 42cfaf3b1..d2b00a28f 100644 --- a/SDKBuildScripts/shared_build.bat +++ b/SDKBuildScripts/shared_build.bat @@ -5,6 +5,7 @@ if [%delSrc%] == [true] ( del /S *.cpp del /S *.cs del /S *.h + del /S *.http del /S *.java del /S *.js del /S *.lua diff --git a/SDKBuildScripts/shared_build.sh b/SDKBuildScripts/shared_build.sh index 2ca48b49d..fedca758f 100644 --- a/SDKBuildScripts/shared_build.sh +++ b/SDKBuildScripts/shared_build.sh @@ -54,6 +54,7 @@ CleanCodeFiles () { NukeAll "*.cpp" NukeAll "*.cs" NukeAll "*.h" + NukeAll "*.http" NukeAll "*.java" NukeAll "*.js" NukeAll "*.lua" diff --git a/SDKGenerator.njsproj b/SDKGenerator.njsproj index f9bd08c8c..8ab4e3f81 100644 --- a/SDKGenerator.njsproj +++ b/SDKGenerator.njsproj @@ -86,6 +86,11 @@ bin\ -destpath ..\sdks\PythonSdk -apiSpecGitUrl -buildIdentifier PythonSdk_Manual + + true + bin\ + -destpath ..\sdks\RESTClientCollection -apiSpecGitUrl -buildIdentifier RESTClientCollection_manual + true bin\ @@ -445,6 +450,12 @@ + + + Code + + + @@ -937,6 +948,8 @@ + + @@ -1070,6 +1083,8 @@ + + diff --git a/SDKGenerator.sln b/SDKGenerator.sln index a962aa067..b6926deaf 100644 --- a/SDKGenerator.sln +++ b/SDKGenerator.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35303.130 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "SDKGenerator", "SDKGenerator.njsproj", "{2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}" EndProject @@ -17,17 +17,17 @@ Global NodeSDK|Any CPU = NodeSDK|Any CPU ObjCSdk|Any CPU = ObjCSdk|Any CPU PhpSdk|Any CPU = PhpSdk|Any CPU + PlayFabCoreCSdk|Any CPU = PlayFabCoreCSdk|Any CPU + PlayFabServicesCSdk|Any CPU = PlayFabServicesCSdk|Any CPU PostmanCollection|Any CPU = PostmanCollection|Any CPU Python|Any CPU = Python|Any CPU UnitySdk|Any CPU = UnitySdk|Any CPU Unreal|Any CPU = Unreal|Any CPU - PlayFabCoreCSdk|Any CPU = PlayFabCoreCSdk|Any CPU - PlayFabServicesCSdk|Any CPU = PlayFabServicesCSdk|Any CPU XPlatCppSdk|Any CPU = XPlatCppSdk|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.ActiveCfg = CloudScript|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.Build.0 = CloudScript|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.ActiveCfg = RESTClientCollection|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.Build.0 = RESTClientCollection|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CocosSDK|Any CPU.ActiveCfg = CocosSDK|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CocosSDK|Any CPU.Build.0 = CocosSDK|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CSharpSDK|Any CPU.ActiveCfg = CSharpSDK|Any CPU @@ -46,6 +46,10 @@ Global {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.ObjCSdk|Any CPU.Build.0 = ObjCSdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PhpSdk|Any CPU.ActiveCfg = PhpSdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PhpSdk|Any CPU.Build.0 = PhpSdk|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabCoreCSdk|Any CPU.ActiveCfg = PlayFabCoreCSdk|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabCoreCSdk|Any CPU.Build.0 = PlayFabCoreCSdk|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabServicesCSdk|Any CPU.ActiveCfg = PlayFabServicesCSdk|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabServicesCSdk|Any CPU.Build.0 = PlayFabServicesCSdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PostmanCollection|Any CPU.ActiveCfg = PostmanCollection|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PostmanCollection|Any CPU.Build.0 = PostmanCollection|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Python|Any CPU.ActiveCfg = Python|Any CPU @@ -54,10 +58,6 @@ Global {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.UnitySdk|Any CPU.Build.0 = UnitySdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Unreal|Any CPU.ActiveCfg = Unreal|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Unreal|Any CPU.Build.0 = Unreal|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabCoreCSdk|Any CPU.ActiveCfg = PlayFabCoreCSdk|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabCoreCSdk|Any CPU.Build.0 = PlayFabCoreCSdk|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabServicesCSdk|Any CPU.ActiveCfg = PlayFabServicesCSdk|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PlayFabServicesCSdk|Any CPU.Build.0 = PlayFabServicesCSdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.XPlatCppSdk|Any CPU.ActiveCfg = XPlatCppSdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.XPlatCppSdk|Any CPU.Build.0 = XPlatCppSdk|Any CPU EndGlobalSection diff --git a/targets/restclient/make.js b/targets/restclient/make.js new file mode 100644 index 000000000..99e218c6a --- /dev/null +++ b/targets/restclient/make.js @@ -0,0 +1,147 @@ +const path = require("path"); + +// Making resharper less noisy - These are defined in Generate.js +if (typeof (getCompiledTemplate) === "undefined") getCompiledTemplate = () => { }; +if (typeof (templatizeTree) === "undefined") templatizeTree = () => { }; + +let propertyReplacements = {}; + +// generate.js looks for some specific exported functions (as defined in TOC.json) in make.js, like: +exports.makeCombinedAPI = (apis, sourceDir, apiOutputDir) => { + // Builds every api. The provided "apis" variable is a list of objects, Examples: API_SPECS/Legacy/PlayFab/admin.api.json, API_SPECS/Legacy/PlayFab/server.api.json, and API_SPECS/Legacy/PlayFab/client.api.json + + console.log("Generating Combined api from: " + sourceDir + " to: " + apiOutputDir); + + try { + propertyReplacements = require(path.resolve(sourceDir, "replacements.json")); + } catch (ex) { + throw "The file: replacements.json was not properly formatted JSON"; + } + + const envTemplate = getCompiledTemplate(path.resolve(sourceDir, "templates/settings.json.ejs")); + writeFile(path.resolve(apiOutputDir, ".vscode/settings.json"), envTemplate()); + + // Filter empty apis + apis = apis.filter(api => api.calls.length > 0); + + var groupedApis = {}; + apis.forEach(api => { + if (!groupedApis[api.name]) { + groupedApis[api.name] = []; + } + api.calls.forEach(call => { + var key = call.subgroup; + if (!groupedApis[api.name][key]) { + groupedApis[api.name][key] = []; + } + groupedApis[api.name][key].push(call); + }); + }); + + const locals = { + apis: groupedApis, + sdkVersion: sdkGlobals.sdkVersion, + fixRequestExample: fixRequestExample, + getBaseUrl: getBaseUrl, + getHeaders: getHeaders, + getVariables: getVariables, + getVerticalTag: getVerticalTag + }; + + const template = getCompiledTemplate(path.resolve(sourceDir, "templates/playfab.http.ejs")); + const generatedTemplateText = template(locals); + writeFile(path.resolve(apiOutputDir, "playfab.http"), generatedTemplateText); +} + +const checkReplacements = (apiName, obj) => { + for (let replaceCategory in propertyReplacements) { + if (replaceCategory === "generic") { + for (let genReplaceName1 in propertyReplacements[replaceCategory]) + doReplace(obj, genReplaceName1, propertyReplacements[replaceCategory][genReplaceName1]); + } + if (replaceCategory === apiName) { + for (let apiReplaceName in propertyReplacements[replaceCategory]) { + if (apiReplaceName === "generic") { + for (let genReplaceName2 in propertyReplacements[replaceCategory][apiReplaceName]) + doReplace(obj, genReplaceName2, propertyReplacements[replaceCategory][apiReplaceName][genReplaceName2]); + } + doReplace(obj, apiReplaceName, propertyReplacements[replaceCategory][apiReplaceName]); + } + } + } +} + +const doReplace = (obj, paramName, newValue) => { + if (obj.hasOwnProperty(paramName)) { + console.log("Replaced: " + obj[paramName] + " with " + newValue); + obj[paramName] = newValue; + } +}; + +const fixRequestExample = (apiName, example) => { + if (example) { + let output = JSON.parse(example); + if (Object.keys(output).length === 0) return ""; + checkReplacements(apiName, output); + return JSON.stringify(output, undefined, 2); + } + return example; +} + +const getBaseUrl = () => { + if (sdkGlobals.verticalName) + // verticalName isn't an established variable in Postman, and we know it here, so we can just apply it + return "https://" + sdkGlobals.verticalName + ".playfabapi.com"; + return "https://{{titleId}}.playfabapi.com"; +} + +const getHeaders = (apiCall) => { + let headers = []; + headers.push('Accept-Encoding: gzip'); + headers.push('Content-Type: application/json'); + headers.push(`X-PlayFabSDK: RESTClientCollection-${sdkGlobals.sdkVersion}`); + if (apiCall.url === "/Authentication/GetEntityToken") { + headers.push('X-Authorization: {{sessionTicket}}'); + headers.push('X-SecretKey: {{secretKey}}'); + return headers.join('\n'); + } + + if (apiCall.auth === "SessionTicket") { + headers.push('X-Authorization: {{sessionTicket}}'); + return headers.join('\n'); + } + + if (apiCall.auth === "SecretKey") { + headers.push('X-SecretKey: {{secretKey}}'); + return headers.join('\n'); + } + + if (apiCall.auth === "EntityToken") { + headers.push('X-EntityToken: {{entityToken}}'); + return headers.join('\n'); + } + + return headers.join('\n'); +} + +const getVariables = () => { + let variables = []; + variables.push("@entityToken = {{GetEntityToken.response.body.data.EntityToken}}"); + variables.push("# LoginWithCustomID can be replaced by other authentication methods (e.g., LoginWithFacebook)"); + variables.push("@sessionTicket = {{LoginWithCustomID.response.body.data.SessionTicket}}"); + variables.push("@playFabId = {{LoginWithCustomID.response.body.data.PlayFabId}}"); + variables.push("@characterId = {{GrantCharacterToUser.response.body.data.CharacterId}}"); + variables.push("@newsId = {{AddNews.response.body.data.NewsId}}"); + variables.push("@sharedSecretKey = {{CreatePlayerSharedSecret.response.body.data.SecretKey}}"); + variables.push("@segmentId = {{ GetPlayerSegments.response.body.data.Segments[0].Id }}"); + + return variables.join('\n'); +} + +const getVerticalTag = () => { + if (sdkGlobals.verticalName) { + return " for vertical: " + sdkGlobals.verticalName; + } + + return ""; +} \ No newline at end of file diff --git a/targets/restclient/replacements.json b/targets/restclient/replacements.json new file mode 100644 index 000000000..3bf8c510d --- /dev/null +++ b/targets/restclient/replacements.json @@ -0,0 +1,30 @@ +{ + "generic": { + "_info": "Allows replacements for parameter-values within the post body (of any API-Call anywhere). All breaklines in json-strings are currently removed, rather than parsed. (Known issue)", + "CharacterId": "{{characterId}}", + "EntityId": "{{entityId}}", + "PlayFabId": "{{playFabId}}", + "TitleId": "{{titleId}}", + "EntityToken": "{{entityToken}}", + "CatalogVersion": "{{primaryCatalogName}}", + "ConnectionId": "{{connectionId}}" + }, + "Client": { + "CustomId": "{{customId}}", + "CreateAccount": true, + "FriendPlayFabId": "{{friendPlayFabId}}", + "PlayFabIds": [ + "{{playFabId}}" + ], + "SharedGroupId": "{{sharedGroupId}}" + }, + "Server": { + }, + "Admin": { + "NewsId": "{{newsId}}", + "SecretKey": "{{sharedSecretKey}}", + "SegmentId": "{{segmentId}}", + "StatisticName": "{{statisticName}}", + "VirtualCurrency": "{{currencyCode}}" + } +} \ No newline at end of file diff --git a/targets/restclient/templates/playfab.http.ejs b/targets/restclient/templates/playfab.http.ejs new file mode 100644 index 000000000..68a5ba0e3 --- /dev/null +++ b/targets/restclient/templates/playfab.http.ejs @@ -0,0 +1,21 @@ +# PlayFab REST Client SDK <%- sdkVersion %><%- getVerticalTag() %> + +<%- getVariables() %> +<% for(var a in apis) { + var api = apis[a];%> +###### <%- a %> ###### +<% for(var g in api) { + var subgroup = api[g]; %> +###### <%- g %> ###### +<% for(var c in subgroup) { + var apiCall = subgroup[c]; %> +### +# @name <%- apiCall.name %> +# @description <%- apiCall.summary %> +<%- apiCall.method %> <%- getBaseUrl() %><%- `${apiCall.url}?sdk=RESTClientCollection-${sdkVersion}` %> +<%- getHeaders(apiCall) %> + +<%- fixRequestExample(a, apiCall.requestExample) %> +<% } + } +} %> \ No newline at end of file diff --git a/targets/restclient/templates/settings.json.ejs b/targets/restclient/templates/settings.json.ejs new file mode 100644 index 000000000..cb614e8be --- /dev/null +++ b/targets/restclient/templates/settings.json.ejs @@ -0,0 +1,15 @@ +{ + "rest-client.environmentVariables": { + "$shared": { + "connectionId": "exampleprovider", + "currencyCode": "GC", + "customId": "12345678123412341234123456789abc", + "friendPlayFabId": "", + "primaryCatalogName": "products", + "secretKey": "", + "sharedGroupId": "Clan Data", + "statisticName": "headshots", + "titleId": "" + } + } +} \ No newline at end of file From 121b4317f6fad5ec36e513ccc2111a4f579aeac9 Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Thu, 19 Sep 2024 11:06:12 -0700 Subject: [PATCH 2/6] parameterize the API domain name --- targets/restclient/make.js | 9 +++++---- targets/restclient/templates/settings.json.ejs | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/targets/restclient/make.js b/targets/restclient/make.js index 99e218c6a..d785c3548 100644 --- a/targets/restclient/make.js +++ b/targets/restclient/make.js @@ -86,13 +86,14 @@ const fixRequestExample = (apiName, example) => { return JSON.stringify(output, undefined, 2); } return example; -} +}gi const getBaseUrl = () => { - if (sdkGlobals.verticalName) + if (sdkGlobals.verticalName) { // verticalName isn't an established variable in Postman, and we know it here, so we can just apply it - return "https://" + sdkGlobals.verticalName + ".playfabapi.com"; - return "https://{{titleId}}.playfabapi.com"; + return "https://" + sdkGlobals.verticalName + ".{{domain}}"; + } + return "https://{{titleId}}.{{domain}}"; } const getHeaders = (apiCall) => { diff --git a/targets/restclient/templates/settings.json.ejs b/targets/restclient/templates/settings.json.ejs index cb614e8be..095331a71 100644 --- a/targets/restclient/templates/settings.json.ejs +++ b/targets/restclient/templates/settings.json.ejs @@ -4,7 +4,8 @@ "connectionId": "exampleprovider", "currencyCode": "GC", "customId": "12345678123412341234123456789abc", - "friendPlayFabId": "", + "domain": "playfabapi.com", + "friendPlayFabId": "", "primaryCatalogName": "products", "secretKey": "", "sharedGroupId": "Clan Data", From f02c8e561b36aa3862670102bf3251eb623fa402 Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Thu, 19 Sep 2024 12:12:58 -0700 Subject: [PATCH 3/6] add tier 2 replacement support --- targets/restclient/make.js | 19 ++++++++++++++----- targets/restclient/replacements.json | 5 +++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/targets/restclient/make.js b/targets/restclient/make.js index d785c3548..1757d27e0 100644 --- a/targets/restclient/make.js +++ b/targets/restclient/make.js @@ -73,8 +73,15 @@ const checkReplacements = (apiName, obj) => { const doReplace = (obj, paramName, newValue) => { if (obj.hasOwnProperty(paramName)) { - console.log("Replaced: " + obj[paramName] + " with " + newValue); - obj[paramName] = newValue; + console.log("Replaced: " + obj[paramName] + " with " + JSON.stringify(newValue)); + if (typeof newValue !== 'object' || Array.isArray(newValue)) { + obj[paramName] = newValue; + return; + } + + Object.keys(newValue).forEach(key => { + if (!!obj[paramName][key]) obj[paramName][key] = newValue[key]; + }); } }; @@ -86,7 +93,7 @@ const fixRequestExample = (apiName, example) => { return JSON.stringify(output, undefined, 2); } return example; -}gi +} const getBaseUrl = () => { if (sdkGlobals.verticalName) { @@ -134,8 +141,10 @@ const getVariables = () => { variables.push("@characterId = {{GrantCharacterToUser.response.body.data.CharacterId}}"); variables.push("@newsId = {{AddNews.response.body.data.NewsId}}"); variables.push("@sharedSecretKey = {{CreatePlayerSharedSecret.response.body.data.SecretKey}}"); - variables.push("@segmentId = {{ GetPlayerSegments.response.body.data.Segments[0].Id }}"); - + variables.push("@segmentId = {{GetAllSegments.response.body.data.Segments[0].Id }}"); + variables.push("@taskId = {{CreateCloudScriptTask.response.body.data.TaskId}}"); + variables.push("@taskInstanceId = {{RunTask.response.body.data.TaskInstanceId}}"); + variables.push("@actionsOnPlayersInSegmentTaskId = {{CreateActionsOnPlayersInSegmentTask.response.body.data.TaskId}}"); return variables.join('\n'); } diff --git a/targets/restclient/replacements.json b/targets/restclient/replacements.json index 3bf8c510d..18258df3a 100644 --- a/targets/restclient/replacements.json +++ b/targets/restclient/replacements.json @@ -22,9 +22,14 @@ }, "Admin": { "NewsId": "{{newsId}}", + "Parameter": { + "SegmentId": "{{segmentId}}" + }, "SecretKey": "{{sharedSecretKey}}", "SegmentId": "{{segmentId}}", "StatisticName": "{{statisticName}}", + "TaskId": "{{taskId}}", + "TaskInstanceId": "{{taskInstanceId}}", "VirtualCurrency": "{{currencyCode}}" } } \ No newline at end of file From f70c9f496a20d310604059eba7b401b2fca8a87b Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Fri, 20 Sep 2024 11:08:01 -0700 Subject: [PATCH 4/6] add more replacement variables for RESTClientCollection --- targets/restclient/make.js | 18 ++- targets/restclient/replacements.json | 127 ++++++++++++++---- targets/restclient/templates/playfab.http.ejs | 5 +- .../restclient/templates/settings.json.ejs | 5 +- 4 files changed, 123 insertions(+), 32 deletions(-) diff --git a/targets/restclient/make.js b/targets/restclient/make.js index 1757d27e0..4722af924 100644 --- a/targets/restclient/make.js +++ b/targets/restclient/make.js @@ -53,7 +53,7 @@ exports.makeCombinedAPI = (apis, sourceDir, apiOutputDir) => { writeFile(path.resolve(apiOutputDir, "playfab.http"), generatedTemplateText); } -const checkReplacements = (apiName, obj) => { +const checkReplacements = (apiName, apiCallName, obj) => { for (let replaceCategory in propertyReplacements) { if (replaceCategory === "generic") { for (let genReplaceName1 in propertyReplacements[replaceCategory]) @@ -65,7 +65,10 @@ const checkReplacements = (apiName, obj) => { for (let genReplaceName2 in propertyReplacements[replaceCategory][apiReplaceName]) doReplace(obj, genReplaceName2, propertyReplacements[replaceCategory][apiReplaceName][genReplaceName2]); } - doReplace(obj, apiReplaceName, propertyReplacements[replaceCategory][apiReplaceName]); + if (apiReplaceName === apiCallName) { + for (let apiCallReplaceName in propertyReplacements[replaceCategory][apiReplaceName]) + doReplace(obj, apiCallReplaceName, propertyReplacements[replaceCategory][apiReplaceName][apiCallReplaceName]); + } } } } @@ -85,11 +88,11 @@ const doReplace = (obj, paramName, newValue) => { } }; -const fixRequestExample = (apiName, example) => { +const fixRequestExample = (apiName, apiCallName, example) => { if (example) { let output = JSON.parse(example); + checkReplacements(apiName, apiCallName, output); if (Object.keys(output).length === 0) return ""; - checkReplacements(apiName, output); return JSON.stringify(output, undefined, 2); } return example; @@ -138,13 +141,18 @@ const getVariables = () => { variables.push("# LoginWithCustomID can be replaced by other authentication methods (e.g., LoginWithFacebook)"); variables.push("@sessionTicket = {{LoginWithCustomID.response.body.data.SessionTicket}}"); variables.push("@playFabId = {{LoginWithCustomID.response.body.data.PlayFabId}}"); + variables.push("@titlePlayerAccountId = {{GetAccountInfo.response.body.data.AccountInfo.TitleInfo.TitlePlayerAccount.Id}}"); variables.push("@characterId = {{GrantCharacterToUser.response.body.data.CharacterId}}"); variables.push("@newsId = {{AddNews.response.body.data.NewsId}}"); variables.push("@sharedSecretKey = {{CreatePlayerSharedSecret.response.body.data.SecretKey}}"); variables.push("@segmentId = {{GetAllSegments.response.body.data.Segments[0].Id }}"); variables.push("@taskId = {{CreateCloudScriptTask.response.body.data.TaskId}}"); + variables.push("#@taskId = {{CreateActionsOnPlayersInSegmentTask.response.body.data.TaskId}}"); variables.push("@taskInstanceId = {{RunTask.response.body.data.TaskInstanceId}}"); - variables.push("@actionsOnPlayersInSegmentTaskId = {{CreateActionsOnPlayersInSegmentTask.response.body.data.TaskId}}"); + variables.push("@gameServerId = {{AuthenticateGameServerWithCustomId.response.body.data.EntityToken.Entity.Id}}"); + variables.push("@profileExpectedVersion = {{GetPlayerProfile.response.body.data.Profile.VersionNumber}}"); + variables.push("@segmentExportId = {{ExportPlayersInSegment.response.body.data.ExportId}}"); + variables.push("@policyExpectedVersion = {{GetPolicy.response.body.data.PolicyVersion}}"); return variables.join('\n'); } diff --git a/targets/restclient/replacements.json b/targets/restclient/replacements.json index 18258df3a..741ee99b2 100644 --- a/targets/restclient/replacements.json +++ b/targets/restclient/replacements.json @@ -1,35 +1,116 @@ { "generic": { - "_info": "Allows replacements for parameter-values within the post body (of any API-Call anywhere). All breaklines in json-strings are currently removed, rather than parsed. (Known issue)", + "CatalogVersion": "{{primaryCatalogName}}", "CharacterId": "{{characterId}}", + "ConnectionId": "{{connectionId}}", "EntityId": "{{entityId}}", - "PlayFabId": "{{playFabId}}", - "TitleId": "{{titleId}}", "EntityToken": "{{entityToken}}", - "CatalogVersion": "{{primaryCatalogName}}", - "ConnectionId": "{{connectionId}}" + "PlayFabId": "{{playFabId}}", + "TitleId": "{{titleId}}" + }, + "Admin": { + "generic": { + "NewsId": "{{newsId}}", + "Parameter": { + "SegmentId": "{{segmentId}}" + }, + "SecretKey": "{{sharedSecretKey}}", + "SegmentId": "{{segmentId}}", + "StatisticName": "{{statisticName}}", + "TaskId": "{{taskId}}", + "TaskInstanceId": "{{taskInstanceId}}", + "VirtualCurrency": "{{currencyCode}}" + }, + "DeleteTask": { + "Identifier": { + "Id": "{{taskId}}" + } + }, + "GetSegmentExport": { + "ExportId": "{{segmentExportId}}" + }, + "RunTask": { + "Identifier": { + "Id": "{{taskId}}" + } + } + }, + "Authentication": { + "generic": { + "CustomId": "{{serverCustomId}}" + }, + "Delete": { + "Entity": { + "Id": "{{gameServerId}}" + } + } }, "Client": { - "CustomId": "{{customId}}", - "CreateAccount": true, - "FriendPlayFabId": "{{friendPlayFabId}}", - "PlayFabIds": [ - "{{playFabId}}" - ], - "SharedGroupId": "{{sharedGroupId}}" + "generic": { + "CreateAccount": true, + "CustomId": "{{userCustomId}}", + "FriendPlayFabId": "{{friendPlayFabId}}", + "PlayFabIds": [ + "{{playFabId}}" + ], + "SharedGroupId": "{{sharedGroupId}}" + } }, - "Server": { + "CloudScript": { + "generic": { + "Entity": { + "Id": "{{titlePlayerAccountId}}" + } + }, + "PostFunctionResultForPlayerTriggeredAction": { + "PlayStreamEventEnvelope": { + "EntityId": "{{titlePlayerAccountId}}" + }, + "PlayerProfile": { + "TitleId": "{{titleId}}", + "PlayerId": "{{titlePlayerAccountId}}" + } + } }, - "Admin": { - "NewsId": "{{newsId}}", - "Parameter": { - "SegmentId": "{{segmentId}}" + "Data": { + "generic": { + "Entity": { + "Id": "{{titlePlayerAccountId}}" + }, + "ExpectedVersion": "profileExptectedVersion" + } + }, + "Multiplayer": { + "generic": { + "Entity": { + "Id": "{{titlePlayerAccountId}}" + }, + "ServerEntity": { + "Id": "{{gameServerId}}" + } + } + }, + "Profiles": { + "generic": { + "Entity": { + "Id": "{{titlePlayerAccountId}}" + } + }, + "GetTitlePlayersFromMasterPlayerAccountIds": { + "MasterPlayerAccountIds": [ + "{{playFabId}}" + ] }, - "SecretKey": "{{sharedSecretKey}}", - "SegmentId": "{{segmentId}}", - "StatisticName": "{{statisticName}}", - "TaskId": "{{taskId}}", - "TaskInstanceId": "{{taskInstanceId}}", - "VirtualCurrency": "{{currencyCode}}" + "GetProfiles": { + "Entities": [ + { + "Id": "{{titlePlayerAccountId}}", + "Type": "title_player_account", + "TypeString": "title_player_account" + } + ] + } + }, + "Server": { } } \ No newline at end of file diff --git a/targets/restclient/templates/playfab.http.ejs b/targets/restclient/templates/playfab.http.ejs index 68a5ba0e3..093744522 100644 --- a/targets/restclient/templates/playfab.http.ejs +++ b/targets/restclient/templates/playfab.http.ejs @@ -11,11 +11,12 @@ var apiCall = subgroup[c]; %> ### # @name <%- apiCall.name %> -# @description <%- apiCall.summary %> +# summary: <%- apiCall.summary %> +# request details: <%- apiCall.requestDetails %> <%- apiCall.method %> <%- getBaseUrl() %><%- `${apiCall.url}?sdk=RESTClientCollection-${sdkVersion}` %> <%- getHeaders(apiCall) %> -<%- fixRequestExample(a, apiCall.requestExample) %> +<%- fixRequestExample(a, apiCall.name, apiCall.requestExample) %> <% } } } %> \ No newline at end of file diff --git a/targets/restclient/templates/settings.json.ejs b/targets/restclient/templates/settings.json.ejs index 095331a71..9b0e67630 100644 --- a/targets/restclient/templates/settings.json.ejs +++ b/targets/restclient/templates/settings.json.ejs @@ -3,14 +3,15 @@ "$shared": { "connectionId": "exampleprovider", "currencyCode": "GC", - "customId": "12345678123412341234123456789abc", "domain": "playfabapi.com", "friendPlayFabId": "", "primaryCatalogName": "products", "secretKey": "", + "serverCustomId": "server12345678123412341234123456789abc", "sharedGroupId": "Clan Data", "statisticName": "headshots", - "titleId": "" + "titleId": "", + "userCustomId": "user12345678123412341234123456789abc" } } } \ No newline at end of file From 31f00dfb4b387061a17d6f90f33e8a3b7f1fa12a Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Wed, 25 Sep 2024 10:07:32 -0700 Subject: [PATCH 5/6] change delimiter for api calls to five # from six --- targets/restclient/templates/playfab.http.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/restclient/templates/playfab.http.ejs b/targets/restclient/templates/playfab.http.ejs index 093744522..381277df2 100644 --- a/targets/restclient/templates/playfab.http.ejs +++ b/targets/restclient/templates/playfab.http.ejs @@ -6,7 +6,7 @@ ###### <%- a %> ###### <% for(var g in api) { var subgroup = api[g]; %> -###### <%- g %> ###### +##### <%- g %> ##### <% for(var c in subgroup) { var apiCall = subgroup[c]; %> ### From 32f54617198606aaff69f567215aa64042dfe2a8 Mon Sep 17 00:00:00 2001 From: Manny Ovena Date: Fri, 27 Sep 2024 12:35:38 -0700 Subject: [PATCH 6/6] fix configuration in SLN file --- SDKGenerator.sln | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SDKGenerator.sln b/SDKGenerator.sln index b6926deaf..c385afc05 100644 --- a/SDKGenerator.sln +++ b/SDKGenerator.sln @@ -21,13 +21,14 @@ Global PlayFabServicesCSdk|Any CPU = PlayFabServicesCSdk|Any CPU PostmanCollection|Any CPU = PostmanCollection|Any CPU Python|Any CPU = Python|Any CPU + RESTClientCollection|Any CPU = RESTClientCollection|Any CPU UnitySdk|Any CPU = UnitySdk|Any CPU Unreal|Any CPU = Unreal|Any CPU XPlatCppSdk|Any CPU = XPlatCppSdk|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.ActiveCfg = RESTClientCollection|Any CPU - {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.Build.0 = RESTClientCollection|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.ActiveCfg = CloudScript|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CloudScript|Any CPU.Build.0 = CloudScript|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CocosSDK|Any CPU.ActiveCfg = CocosSDK|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CocosSDK|Any CPU.Build.0 = CocosSDK|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.CSharpSDK|Any CPU.ActiveCfg = CSharpSDK|Any CPU @@ -54,6 +55,8 @@ Global {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.PostmanCollection|Any CPU.Build.0 = PostmanCollection|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Python|Any CPU.ActiveCfg = Python|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Python|Any CPU.Build.0 = Python|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.RESTClientCollection|Any CPU.ActiveCfg = RESTClientCollection|Any CPU + {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.RESTClientCollection|Any CPU.Build.0 = RESTClientCollection|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.UnitySdk|Any CPU.ActiveCfg = UnitySdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.UnitySdk|Any CPU.Build.0 = UnitySdk|Any CPU {2BA807EF-310C-43B5-8D42-1ABCFFF39BE9}.Unreal|Any CPU.ActiveCfg = Unreal|Any CPU