Code & Type Generation
recon export code turns a saved request into a ready-to-paste client snippet, with secret values replaced by placeholders. recon export types reads a recorded response from the Flight Recorder and generates typed models for it. Use them to hand a working call to a teammate or to start client code without typing out headers and fields.
Export a request as code
Section titled “Export a request as code”recon export code "Create Enrollment" --lang curlcurl -X POST 'http://127.0.0.1:8787/_sandbox/local/v1/enrollments' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ${DEV_API_TOKEN}' \ -d '{ "student_id": "001001", "course": "CS-401"}'DEV_API_TOKEN is a secret in the demo local environment, so its value is replaced by ${DEV_API_TOKEN}.
recon export code
Section titled “recon export code”recon export code [OPTIONS] <REQUEST>| Argument or flag | Default | Meaning |
|---|---|---|
<REQUEST> |
required | Saved request ID or name (name compared case-insensitively). |
--lang <LANG> |
curl |
Target language. See the table below. Case-insensitive. |
--env <ENV> |
default_env |
Environment used to resolve {{variables}}. |
The snippet is printed to stdout as plain text. --format does not change it.
Languages
Section titled “Languages”--lang (aliases) |
Output |
|---|---|
curl |
A curl -X <METHOD> '<url>' command with one -H per header and -d for the body. Single quotes in the body are escaped for the shell. |
httpie (http) |
An HTTPie http <METHOD> '<url>' command with 'Name:value' header items. A body is piped in with printf '%s' '<body>' |. |
fetch (js, javascript, ts) |
const res = await fetch(url, { method, headers, body }); followed by console.log(res.status, await res.text());. |
httpx (python, py) |
import httpx and httpx.request(method, url, headers=..., content=...), then print(res.status_code, res.text). |
go (golang) |
A net/http fragment: http.NewRequest, req.Header.Set per header, http.DefaultClient.Do(req). No package or import lines. The body uses strings.NewReader. |
reqwest (rust) |
A reqwest::Client builder chain with .header(...), .body(...), .send().await?. |
mo |
A Mo Http.request(method, url) chain with .header(...) and .body("...".bytes), then req.send()?!. |
hurl |
A Hurl entry: request line, header lines, the body text directly after the headers, then HTTP 200. The status line is always HTTP 200, whatever your assertions say. |
csharp (cs, c#) |
HttpClient with an HttpRequestMessage, TryAddWithoutValidation per header, StringContent for the body. |
ruby (rb) |
Net::HTTP::GenericRequest with req["Name"] = value per header, req.body, and Net::HTTP.start. |
The same request in two other languages:
recon export code "Create Enrollment" --lang httpximport httpx
res = httpx.request( "POST", "http://127.0.0.1:8787/_sandbox/local/v1/enrollments", headers={ "Content-Type": "application/json", "Authorization": "Bearer ${DEV_API_TOKEN}", }, content="{\n \"student_id\": \"001001\",\n \"course\": \"CS-401\"\n}",)print(res.status_code, res.text)recon export code "Create Enrollment" --lang hurlPOST http://127.0.0.1:8787/_sandbox/local/v1/enrollmentsContent-Type: application/jsonAuthorization: Bearer ${DEV_API_TOKEN}{ "student_id": "001001", "course": "CS-401"}HTTP 200What goes into the snippet
Section titled “What goes into the snippet”Recon resolves the request the same way it does before sending, then renders the result:
- The URL with every
{{variable}}resolved and query parameters appended. - The request headers, plus headers from
bearer,basicandapi_keyauth (anapi_keyinquerylocation is appended to the URL). - A
Content-Typeheader when the request has none:application/json,text/plain; charset=utf-8,application/x-www-form-urlencoded, ormultipart/form-data; boundary=...with a fresh random boundary. - The body as text. URL-encoded forms appear encoded (
user=ada+lovelace). Multipart bodies appear in full when they are valid UTF-8. Binary (Base64) bodies are left out of the snippet; only theapplication/octet-streamheader remains.
Some parts of a request are not in the snippet:
- Pre-request scripts are not run, so headers or variables they would set are missing.
oauth2,aws_sigv4andhmacauth are not applied. There is noAuthorizationor signature header for them.- Secret URIs such as
age://andop://are not resolved. - Timeouts, redirect settings and assertions are not included.
- The Outbound Secret Firewall does not run.
A placeholder that does not resolve stays as {{NAME}} in the snippet. If the URL is still a placeholder, export fails with invalid URL.
How secrets are masked
Section titled “How secrets are masked”Before rendering, Recon replaces every tracked secret value with ${LABEL}:
- Secrets are environment variables defined with
secret = true, and{{$env.NAME}}values. The label is the variable’slabel, or its name if there is none. See Configuration. - Both the raw value and its Base64 form are replaced. For
basicauth, the Base64 form coversusername:password, so the whole credential becomes${LABEL}.
With a secret password labelled ADA_PW:
curl -X GET 'https://example.com/b' \ -H 'Authorization: Basic ${ADA_PW}'With the same password stored as a plain variable, nothing is masked:
http GET 'https://example.com/b' \ 'Authorization:Basic YWRhOmh1bnRlcjI='Errors
Section titled “Errors”Errors are reported as E_CLI_RUNTIME with exit status 2.
| Message | Cause |
|---|---|
request `nope` not found |
No request has that ID or name. |
parse error in `codegen`: unsupported codegen language `java` |
Unknown --lang. The request is resolved first, so a resolution error can appear before this one. |
invalid URL `{{base_url}}/v1/students`: relative URL without a base: ... |
The environment does not define a variable the URL needs, or --env names an environment that does not exist. |
Generate types from a response
Section titled “Generate types from a response”recon export types reads the response body of a recorded run and prints model definitions for it. Get a run ID from the run_id field of recon --format json send ... or from the first column of recon history.
recon export types 01a22d21-6238-7380-a5fd-12470d865dbd --lang ts --name StudentListexport interface StudentList { environment: string; request_id: string; session_token: string; students: StudentListStudentsItem[];}
export interface StudentListStudentsItem { email: string; full_name: string; gpa: number; notes: string; phone: string; program: string; ssn: string; student_id: string;}The stored response body is used as recorded. The output contains field names and types only, never values.
recon export types
Section titled “recon export types”recon export types [OPTIONS] <RUN_ID>| Argument or flag | Default | Meaning |
|---|---|---|
<RUN_ID> |
required | Flight Recorder run ID. |
--lang <LANG> |
ts |
Target. See the table below. Case-insensitive. |
--name <NAME> |
Response |
Root type name. It is converted to PascalCase: order summary becomes OrderSummary. A name with no letters or digits becomes Response. |
Targets
Section titled “Targets”--lang (aliases) |
Output | string | integer | float | bool | unknown or null |
optional | list |
|---|---|---|---|---|---|---|---|---|
ts (typescript) |
export interface |
string |
number |
number |
boolean |
unknown / null |
key?: T |
T[] |
zod |
export const <Name>Schema = z.object(...) |
z.string() |
z.number().int() |
z.number() |
z.boolean() |
z.unknown() / z.null() |
T.nullable().optional() |
z.array(T) |
rust (rs) |
Serde pub struct with #[derive(Debug, Clone, Serialize, Deserialize)] |
String |
i64 |
f64 |
bool |
serde_json::Value |
Option<T> |
Vec<T> |
go (golang) |
type <Name> struct with json:"..." tags |
string |
int64 |
float64 |
bool |
any |
*T |
[]T |
pydantic (py, python) |
class <Name>(BaseModel) |
str |
int |
float |
bool |
Any / None |
T | None = None |
list[T] |
mo |
struct <Name> ... end |
Text |
Int |
Float |
Bool |
Json.Value |
Option(T) |
List(T) |
Field names:
- TypeScript and Zod keep the JSON key, quoted when it is not a valid identifier (
"user-id"). - Rust converts keys to snake_case and adds
#[serde(rename = "...")]when the name changed. - Go converts keys to PascalCase and keeps the original in the
jsontag. - Mo converts keys to snake_case.
- Pydantic writes keys as they are.
Inference rules
Section titled “Inference rules”- An object becomes a type. Nested objects become types named after the path: parent name plus the PascalCase key (
OrderSummaryMeta). - Fields of an object appear in alphabetical key order. In a merged array item type, they appear in the order they are first seen across the items.
- JSON integers become integer types and other numbers become float types.
- An array of objects becomes a list of one merged item type named
<Parent><Key>Item. Keys missing from some items become optional. A key whose type differs between items is unified: integer and float give float, a type andnullgive an optional type, anything else gives the unknown type. - Any other array takes the type of its first element. An empty array is a list of the unknown type.
- A
nullvalue outside an array of objects gets the null type. - If the root is not an object (an array or a scalar), Recon wraps it in a root type with one field,
value. - The root type is printed first, then nested types.
Example input and Rust output:
{"user-id":7,"createdAt":"x","score":1,"tags":[],"items":[{"id":1,"price":2.5,"note":null},{"id":2,"price":3,"extra":true}],"meta":{"page":1}}use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]pub struct OrderSummary { #[serde(rename = "createdAt")] pub created_at: String, pub items: Vec<OrderSummaryItemsItem>, pub meta: OrderSummaryMeta, pub score: i64, pub tags: Vec<serde_json::Value>, #[serde(rename = "user-id")] pub user_id: i64,}
#[derive(Debug, Clone, Serialize, Deserialize)]pub struct OrderSummaryMeta { pub page: i64,}
#[derive(Debug, Clone, Serialize, Deserialize)]pub struct OrderSummaryItemsItem { pub id: i64, pub note: Option<serde_json::Value>, pub price: f64, pub extra: Option<bool>,}Known limits
Section titled “Known limits”- Types are printed parent first. Zod schemas and Pydantic classes refer to child types that are defined further down, so you may need to move the child definitions above the parent before the code runs.
- Pydantic output uses JSON keys as attribute names without changes. A key such as
user-idproducesuser-id: int, which is not valid Python. - A field that is
nullin one array item and missing in another becomes an optional null type, for examplenote?: nullin TypeScript andnote: None | None = Nonein Pydantic. - Arrays of mixed scalars take the first element’s type:
[1, "a"]givesnumber[].
Errors
Section titled “Errors”| Message | Cause |
|---|---|
run `nope` not found |
No run with that ID in the Flight Recorder. |
response body is not valid JSON |
The recorded body is not JSON. |
parse error in `typegen`: unsupported typegen target `java`; expected ts|zod|rust|go|pydantic|mo |
Unknown --lang. |
All are E_CLI_RUNTIME with exit status 2.
JWT inspection
Section titled “JWT inspection”When you send a request from the web UI, or open a recorded run there, Recon scans the response body for JSON Web Tokens and decodes them. The response viewer then shows a “JWT detected” button; it opens a panel with each token’s sub, whether it has expired (or the seconds left), and the decoded payload. The CLI does not decode JWTs.
How detection works:
- Recon looks in the response body only, not in headers, for text of the form
eyJ<chars>.<chars>.<chars>using base64url characters. - The header and payload are base64url-decoded (no padding) and must both be JSON objects. Anything else is skipped.
- The signature is not checked.
subandissare read when they are strings.iatandexpare read when they are integers and shown as RFC 3339 times.- A token is expired when
expis at or before the current time.expires_in_secsis negative after expiry. - The same token found twice is listed once.
The decoded tokens are returned in the jwts array of POST /api/v1/send and GET /api/v1/runs/{id}:
[ { "expired": false, "expires_at": "2030-01-01T00:00:00+00:00", "expires_in_secs": 97402157, "header": { "alg": "HS256", "typ": "JWT" }, "issued_at": null, "issuer": null, "payload": { "exp": 1893456000, "scope": "sis:read", "sub": "staff_01" }, "subject": "staff_01", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdGFmZl8wMSIsInNjb3BlIjoic2lzOnJlYWQiLCJleHAiOjE4OTM0NTYwMDB9.demo_sig" }]Also available via
Section titled “Also available via”- HTTP API:
POST /api/v1/codegenwith{"request": <RequestSpec>, "env": "local", "lang": "curl"}returns{"code": "..."}.POST /api/v1/typegenwith{"json_text": "...", "root_name": "Response", "lang": "ts"}returns{"code": "..."};root_namedefaults toResponse. Both need theX-Recon-Tokenheader. See HTTP API. - Web UI: the “Types & Code” tab in the response viewer generates types from the shown response (root name
Response) and snippets for the current request. See Web Studio. - There are no MCP tools for code or type generation.
recon export openapiis covered in OpenAPI & ODCS Contracts.