Files
cfw-autumn/shared/api/features/featureOpModels.ts
John Yeo 9b6f57f872 feat: Add OpenAPI schemas for Features, Entities, Core, and Customers (ENG-628)
- Created operation models and OpenAPI specs for Features (Create, Update, List, Get, Delete)
- Created operation models and OpenAPI specs for Entities (Create, List, Get, Delete)
- Created operation models and OpenAPI specs for Core endpoints (Cancel, Track, Query)
- Created operation models and OpenAPI specs for Customers (Create, Update, List, Get, Delete)
- Fixed bug: Added 'archived' field to UpdateProductV2Params
- Fixed enum usage: Changed z.enum() to z.nativeEnum() for TypeScript enums
- Updated all OpenAPI specs to use requestParams format (path/query with zod schemas)
- Created shared SuccessResponseSchema in common/commonResponses.ts
- Updated models.ts to export all new schemas and OpenAPI operations
- Changed OpenAPI export to JSON format (YAML export has serialization issues with zod schemas)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 14:55:58 +01:00

98 lines
2.5 KiB
TypeScript

import { APIFeatureSchema, APIFeatureType } from "./apiFeature.js";
import { z } from "zod/v4";
// Create Feature Params
export const CreateFeatureParamsSchema = z
.object({
id: z.string().meta({
description: "The ID of the feature",
example: "feature_123",
}),
name: z.string().nullish().meta({
description: "The name of the feature",
example: "API Calls",
}),
type: z.nativeEnum(APIFeatureType).meta({
description: "The type of the feature",
example: "single_use",
}),
display: z
.object({
singular: z.string(),
plural: z.string(),
})
.nullish()
.meta({
description: "Display names for the feature",
example: { singular: "API Call", plural: "API Calls" },
}),
credit_schema: z
.array(
z.object({
metered_feature_id: z.string(),
credit_cost: z.number(),
}),
)
.nullish()
.meta({
description:
"Credit schema for credit system features (only applicable when type is credit_system)",
example: [{ metered_feature_id: "api_calls", credit_cost: 10 }],
}),
})
.meta({
id: "CreateFeatureParams",
description: "Parameters for creating a feature",
});
// Update Feature Params
export const UpdateFeatureParamsSchema = z
.object({
id: z.string().optional().meta({
description: "The ID of the feature",
example: "feature_123",
}),
name: z.string().nullish().meta({
description: "The name of the feature",
example: "API Calls",
}),
type: z.nativeEnum(APIFeatureType).optional().meta({
description: "The type of the feature",
example: "single_use",
}),
display: z
.object({
singular: z.string(),
plural: z.string(),
})
.nullish()
.meta({
description: "Display names for the feature",
example: { singular: "API Call", plural: "API Calls" },
}),
credit_schema: z
.array(
z.object({
metered_feature_id: z.string(),
credit_cost: z.number(),
}),
)
.nullish()
.meta({
description:
"Credit schema for credit system features (only applicable when type is credit_system)",
example: [{ metered_feature_id: "api_calls", credit_cost: 10 }],
}),
archived: z.boolean().nullish().meta({
description: "Whether the feature is archived",
example: false,
}),
})
.meta({
id: "UpdateFeatureParams",
description: "Parameters for updating a feature",
});
export type CreateFeatureParams = z.infer<typeof CreateFeatureParamsSchema>;
export type UpdateFeatureParams = z.infer<typeof UpdateFeatureParamsSchema>;