Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rest client collection generation #888

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions JenkinsConsoleUtility/jcuSrc/Commands/VersionVarWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions SDKBuildScripts/Linux/rest_client_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

SdkName="RESTClientCollection"
delSrc=false

cd ..
. ./shared_build.sh
5 changes: 5 additions & 0 deletions SDKBuildScripts/Windows/rest_client_build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set SdkName=RESTClientCollection
set delSrc=false

cd ..
call shared_build.bat
1 change: 1 addition & 0 deletions SDKBuildScripts/shared_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions SDKBuildScripts/shared_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CleanCodeFiles () {
NukeAll "*.cpp"
NukeAll "*.cs"
NukeAll "*.h"
NukeAll "*.http"
NukeAll "*.java"
NukeAll "*.js"
NukeAll "*.lua"
Expand Down
15 changes: 15 additions & 0 deletions SDKGenerator.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<OutputPath>bin\</OutputPath>
<ScriptArguments>-destpath ..\sdks\PythonSdk -apiSpecGitUrl -buildIdentifier PythonSdk_Manual</ScriptArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'RESTClientCollection' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
<ScriptArguments>-destpath ..\sdks\RESTClientCollection -apiSpecGitUrl -buildIdentifier RESTClientCollection_manual</ScriptArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'UnitySdk' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
Expand Down Expand Up @@ -445,6 +450,12 @@
<Content Include="targets\PythonSdk\source\setup.py.ejs" />
<Content Include="targets\PythonSdk\source\uploadPython.sh" />
<Content Include="targets\PythonSdk\templates\API.py.ejs" />
<Content Include="targets\restclient\make.js" />
<Content Include="targets\restclient\replacements.json">
<SubType>Code</SubType>
</Content>
<Content Include="targets\restclient\templates\playfab.http.ejs" />
<Content Include="targets\restclient\templates\settings.json.ejs" />
<Content Include="targets\SdkTestingCloudScript\make.js" />
<Content Include="targets\SdkTestingCloudScript\source\package.json.ejs" />
<Content Include="targets\SdkTestingCloudScript\source\Scripts\typings\PlayFab\CloudScript.d.ts.ejs" />
Expand Down Expand Up @@ -937,6 +948,8 @@
<Content Include="targets\UnrealMarketplacePlugin\templates\PlayFab\PlayFab_Models.h.ejs" />
</ItemGroup>
<ItemGroup>
<Folder Include="SDKBuildScripts\" />
<Folder Include="SDKBuildScripts\Linux\" />
<Folder Include="targets\" />
<Folder Include="targets\csharp\" />
<Folder Include="targets\csharp\source\" />
Expand Down Expand Up @@ -1070,6 +1083,8 @@
<Folder Include="targets\PythonSdk\source\" />
<Folder Include="targets\PythonSdk\source\playfab\" />
<Folder Include="targets\PythonSdk\templates\" />
<Folder Include="targets\restclient\" />
<Folder Include="targets\restclient\templates\" />
<Folder Include="targets\SdkTestingCloudScript\" />
<Folder Include="targets\SdkTestingCloudScript\source\" />
<Folder Include="targets\SdkTestingCloudScript\source\Scripts\" />
Expand Down
19 changes: 11 additions & 8 deletions SDKGenerator.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,12 +17,13 @@ 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
RESTClientCollection|Any CPU = RESTClientCollection|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
Expand All @@ -46,18 +47,20 @@ 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
{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
{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
Expand Down
165 changes: 165 additions & 0 deletions targets/restclient/make.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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, apiCallName, 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]);
}
if (apiReplaceName === apiCallName) {
for (let apiCallReplaceName in propertyReplacements[replaceCategory][apiReplaceName])
doReplace(obj, apiCallReplaceName, propertyReplacements[replaceCategory][apiReplaceName][apiCallReplaceName]);
}
}
}
}
}

const doReplace = (obj, paramName, newValue) => {
if (obj.hasOwnProperty(paramName)) {
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];
});
}
};

const fixRequestExample = (apiName, apiCallName, example) => {
if (example) {
let output = JSON.parse(example);
checkReplacements(apiName, apiCallName, output);
if (Object.keys(output).length === 0) return "";
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 + ".{{domain}}";
}
return "https://{{titleId}}.{{domain}}";
}

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("@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("@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');
}

const getVerticalTag = () => {
if (sdkGlobals.verticalName) {
return " for vertical: " + sdkGlobals.verticalName;
}

return "";
}
Loading