Skip to content
Merged
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
93 changes: 93 additions & 0 deletions __tests__/__snapshots__/nullables.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,99 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`const values 1`] = `
"export type StringConst = "hello";
export type NumberConst = 42;
export type BooleanConst = true;
export type NullConst = null;
"
`;

exports[`const values 2`] = `
"import * as v from "valibot";

export const stringConstSchema = v.literal("hello");
export const numberConstSchema = v.literal(42);
export const booleanConstSchema = v.literal(true);
export const nullConstSchema = v.null();
"
`;

exports[`header parameters 1`] = `
"export type UploadStatus = "pending" | "complete";
export type UploadDataCommandHeader = {
"content-type": "application/json" | "text/csv" | "application/xml";
"content-length": number;
"x-idempotency-key"?: string | undefined;
};
export type UploadDataCommandParams = {
uploadId: string;
};
export type UploadDataCommandInput = UploadDataCommandParams;
"
`;

exports[`header parameters 2`] = `
"import * as v from "valibot";

export const uploadStatusSchema = v.picklist(["pending", "complete"]);
export const uploadDataCommandParamsSchema = v.strictObject({
"uploadId": v.string()
});
export const uploadDataCommandHeaderSchema = v.object({
"content-type": v.picklist(["application/json", "text/csv", "application/xml"]),
"content-length": v.pipe(v.number(), v.integer()),
"x-idempotency-key": v.exactOptional(v.pipe(v.string(), v.uuid()))
});
"
`;

exports[`header parameters 3`] = `
"import { validator } from "hono/validator";
import * as v from "valibot";
import { PublicValibotHonoError } from "@block65/rest-client";
import { uploadDataCommandParamsSchema } from "./valibot.js";

function toPublicValibotHonoError(err: unknown): never {

if (err instanceof v.ValiError) {
throw PublicValibotHonoError.from(err);
}
throw err;

}

export const uploadData = [
validator("param", (value) => {
return v.parseAsync(uploadDataCommandParamsSchema, value).catch(toPublicValibotHonoError);
}),
] as const;
"
`;

exports[`nullables 1`] = `
"export type MySchemaLolOrNullable = "lol" | "kek" | null;
"
`;

exports[`top-level type array with null 1`] = `
"export type NullableString = string | null;
export type NullableStringEnum = "active" | "inactive" | null;
export type NullableInteger = number | null;
export type MultiType = string | number;
"
`;

exports[`top-level type array with null 2`] = `
"import * as v from "valibot";

export const nullableStringSchema = v.nullable(v.string());
export const nullableStringEnumSchema = v.nullable(v.picklist(["active", "inactive"]));
export const nullableIntegerSchema = v.nullable(v.pipe(v.number(), v.integer()));
export const multiTypeSchema = v.union([v.string(), v.number()]);
"
`;

exports[`top-level type array with null 3`] = `
"export const nullableStringEnum = ["active", "inactive"] as const;
"
`;
97 changes: 96 additions & 1 deletion __tests__/fixtures/test1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi": "3.0.3",
"openapi": "3.1.0",
"info": {
"title": "Billing Service REST API",
"version": "1.0.0"
Expand Down Expand Up @@ -58,6 +58,33 @@
"maxLength": 256,
"pattern": "/^[A-Z0-9]$/"
},
"ApiVersion": {
"type": "string",
"const": "2024-01-01",
"description": "The API version"
},
"MaxRetries": {
"type": "integer",
"const": 3
},
"DefaultEnabled": {
"const": true
},
"NullableNotes": {
"type": ["string", "null"],
"description": "Optional notes field"
},
"NullableDiscount": {
"type": ["number", "null"]
},
"NullableStatus": {
"type": ["string", "null"],
"enum": ["active", "paused", "cancelled"]
},
"AccountTier": {
"type": "string",
"enum": ["free", "pro", "enterprise"]
},
"LongRunningOperationIndeterminate": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -778,6 +805,74 @@
}
},
"paths": {
"/billing-accounts/{billingAccountId}/import": {
"post": {
"operationId": "importBillingDataCommand",
"tags": [],
"parameters": [
{
"$ref": "#/components/parameters/BillingAccountIdParameter"
},
{
"name": "Content-Type",
"in": "header",
"required": true,
"description": "The content type of the import data",
"schema": {
"type": "string",
"enum": [
"application/json",
"text/csv",
"application/xml"
]
}
},
{
"name": "Content-Length",
"in": "header",
"required": true,
"description": "The size of the import data in bytes",
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "X-Idempotency-Key",
"in": "header",
"required": false,
"description": "Optional idempotency key for safe retries",
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"responses": {
"200": {
"description": "Import 200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LongRunningOperation"
}
}
}
}
}
}
},
"/operations/{operationId}": {
"get": {
"operationId": "getOperationCommand",
Expand Down
5 changes: 3 additions & 2 deletions __tests__/fixtures/test1/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* WARN: Do not edit directly.
*
* Generated on 2026-03-17T13:15:38.356Z
* Generated on 2026-04-02T04:52:00.193Z
*
*/
/** eslint-disable max-classes */
Expand Down Expand Up @@ -40,7 +40,8 @@ import type {
} from "./types.js";

/**
* Tagged template literal that applies encodeURIComponent to all interpolated values, protecting path integrity from characters like `/` and `#`.
* Tagged template literal that applies encodeURIComponent to all interpolated
* values, protecting path integrity from characters like `/` and `#`.
* @example encodePath`/users/${userId}` // "/users/foo%2Fbar"
*/
function encodePath(
Expand Down
34 changes: 34 additions & 0 deletions __tests__/fixtures/test1/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This file was auto generated by @block65/openapi-codegen
*
* WARN: Do not edit directly.
*
* Generated on 2026-04-02T04:52:00.193Z
*
*/
export const nullableStatus = ["active", "paused", "cancelled"] as const;
export const accountTier = ["free", "pro", "enterprise"] as const;
export const billingSubscriptionStatus = ["active", "inactive"] as const;
export const billingSubscriptionInterval = ["monthly", "yearly"] as const;
export const planSku = [
"donotuse",
"plasku1",
"plasku2",
"plasku3",
"plasku4",
] as const;
export const paymentMethodBrand = [
"amex",
"diners",
"discover",
"jcb",
"mastercard",
"unionpay",
"visa",
"unknown",
] as const;
export const billingLocale = ["en"] as const;
export const billingAccountType = ["standard", "agency", "reseller"] as const;
export const currency = ["usd", "aud", "sgd", "myr", "gbp"] as const;
export const billingAccountStatus = ["nominal", "delinquent"] as const;
export const billingCountry = ["us", "au", "sg", "my", "gb"] as const;
2 changes: 1 addition & 1 deletion __tests__/fixtures/test1/hono-valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* WARN: Do not edit directly.
*
* Generated on 2026-03-17T13:15:38.356Z
* Generated on 2026-04-02T04:52:00.193Z
*
*/

Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/test1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* WARN: Do not edit directly.
*
* Generated on 2026-03-17T13:15:38.356Z
* Generated on 2026-04-02T04:52:00.193Z
*
*/
import {
Expand Down
11 changes: 10 additions & 1 deletion __tests__/fixtures/test1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
*
* WARN: Do not edit directly.
*
* Generated on 2026-03-17T13:15:38.356Z
* Generated on 2026-04-02T04:52:00.193Z
*
*/
import type { Jsonifiable, Jsonify } from "type-fest";

export type PromoCode = string;
/** The API version */
export type ApiVersion = "2024-01-01";
export type MaxRetries = 3;
export type DefaultEnabled = true;
/** Optional notes field */
export type NullableNotes = string | null;
export type NullableDiscount = number | null;
export type NullableStatus = "active" | "paused" | "cancelled" | null;
export type AccountTier = "free" | "pro" | "enterprise";
export type StripeId = string;
export type DateTime = Jsonify<Date>;
export type BillingSubscriptionStatus = "active" | "inactive";
Expand Down
13 changes: 12 additions & 1 deletion __tests__/fixtures/test1/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* WARN: Do not edit directly.
*
* Generated on 2026-03-17T13:15:38.356Z
* Generated on 2026-04-02T04:52:00.193Z
*
*/
import * as v from "valibot";
Expand All @@ -14,6 +14,17 @@ export const promoCodeSchema = v.pipe(
v.maxLength(256),
v.regex(/\/^[A-Z0-9]$\//),
);
/** The API version */
export const apiVersionSchema = v.literal("2024-01-01");
export const maxRetriesSchema = v.literal(3);
export const defaultEnabledSchema = v.literal(true);
/** Optional notes field */
export const nullableNotesSchema = v.nullable(v.string());
export const nullableDiscountSchema = v.nullable(v.number());
export const nullableStatusSchema = v.nullable(
v.picklist(["active", "paused", "cancelled"]),
);
export const accountTierSchema = v.picklist(["free", "pro", "enterprise"]);
export const stripeIdSchema = v.pipe(
v.string(),
v.minLength(11),
Expand Down
Loading
Loading