JSON to SDK Program Generator
As we've previously announced, we're working on a new tool, the forthcoming API Request Builder, that can generate DocuSign eSignature REST SDK programs for C#, PHP, Java, Node.js, Python, and Ruby from a JSON source. It can also generate VB.NET programs that call the API directly.
We’ve now extracted the code that translates the JSON object to an SDK program into a new standalone online tool, JsonToSDK.dshackathon.com.
The tool has two windows: one for the JSON input and one for the SDK program output. See the screenshot, above.
The output window is live; it is immediately updated when you make a change to the source JSON in the input window.
To run the generated program:
- Select Download Framework to download the ancillary files for running the program. These files include example source documents, package manager files, and more.
- Select Download Code to download the generated code to replace the skeleton program file included with the framework.
- Invoke your language’s package manager to download the DocuSign SDK.
- Add an access token and account ID to the source file.
- Run the program.
For production, you must use an OAuth flow to obtain an access token. You will also need the account’s base URI (used for the basePath variable in the code). Obtain the base URI from the /oauth/userinfo API call.
Embedded or remote (email) recipients
The first version of the tool only supports the Envelopes:create and EnvelopeViews:createRecipient API calls. If the JSON includes a top-level createRecipientViewReq attribute, then the generated program will request an embedded signing ceremony URL for the first recipient.
When the tool is started, the initial example JSON demonstrates an envelope with an embedded signing ceremony.
How does it work?
Each time the input JSON is changed, the tool checks that it’s valid JSON. If it isn’t, then the tool shows a message and colors the appropriate section of the source red.
The tool then uses recursion to walk the JSON tree and generate the matching calls to the selected SDK. (The VB.NET program directly uses the JSON source.) A reduced version of the eSignature API’s Swagger file is used to check the names of the complex attributes (arrays and objects) and the types of their attributes. The intermediate output of this process is then used with a language-specific template file to generate the tool’s output window.
A program is included with the source code to reduce the Swagger file.
The JSON to SDK source is available on GitHub. It is a React.JS application and uses the React-Bootstrap UX library. There is no server component. When you “download” the output code from the tool, the React application is creating the file object on-the-fly: you’re “downloading” from the browser, not from a server.
Let us know what you think via the comments/issues for the repository. You can also ask questions about the tool there. Pull requests that use the MIT License are welcomed.