Skip to content

Code Generator

The Template Editor can generate model code from your template’s JSON schema. Use the Code button next to Schema to create typed code for the data you send in PDF submission requests.

DocSpring uses quicktype in the browser to generate the code. Your template schema is fetched from DocSpring, but it is not sent to quicktype.app or another third-party code generation service.

The Code Generator currently supports:

  • TypeScript
  • JavaScript
  • Ruby
  • Python
  • PHP
  • Java
  • C#
  • Elixir
  • Go
  1. Open a PDF template in the Template Editor.
  2. Add or review your field names.
  3. Click Code in the editor header.
  4. Select a target language.
  5. Copy or download the generated code.

The Code button is disabled until the template has named fields. Field names define the shape of the generated schema, so names such as person/name become nested data structures.

The generated code describes the data object for a PDF submission. It does not replace the DocSpring API client or generate the full API request.

Build your template data using the generated model, then pass the object, hash, dict, map, or struct as submission.data when you call the Create PDF Submission endpoint.

For example, in TypeScript:

const data: W9Form = {
name: "Jane Smith",
tin: "123456789",
};
const submission = {
data,
metadata: { source: "onboarding" },
field_overrides: {},
};
const result = await apiInstance.generatePdf(templateId, submission, wait);

In Ruby, pass a hash:

data = {
name: 'Jane Smith',
tin: '123456789',
}
submission = {
data: data,
metadata: { source: 'onboarding' },
field_overrides: {},
}
response = client.generate_pdf(template_id, submission, wait: nil)

In Python, pass a dict:

data = {
"name": "Jane Smith",
"tin": "123456789",
}
submission = {
"data": data,
"metadata": {"source": "onboarding"},
"field_overrides": {},
}
response = client.generate_pdf(template_id, submission, wait=None)

Generated models help your application catch schema mismatches before sending a request to DocSpring. The exact checks depend on the target language and quicktype output.

DocSpring still validates the final API request on the server. If the submitted data does not match your template fields or field settings, the API returns a validation error.