import { CliCommand, CliOption, type ParentCliCommandDefinition, } from '@causa/cli'; import { WorkspaceFunction } from '@causa/workspace'; import { AllowMissing } from '@causa/workspace/validation'; import { IsBoolean, IsString } from 'class-validator'; /** * The `openapi` parent command, grouping all commands related to OpenAPI specifications. */ export const openApiCommandDefinition: ParentCliCommandDefinition = { name: 'openapi', description: 'Tools for OpenAPI specifications.', }; /** * Generates the OpenAPI specification for the service or workspace. * When run at the workspace level, the specifications for all services are generated and merged. * Returns the path to the generated specification, or the specification itself if the `returnSpecification` option is * set. */ @CliCommand({ parent: openApiCommandDefinition, name: 'generateSpecification', aliases: ['genSpec'], description: `Generates the OpenAPI specification for the service or workspace. When run at the workspace level, the specifications for all services are generated and merged.`, summary: 'Generates the OpenAPI specification for the service or workspace.', outputFn: (path) => console.log(path), }) export abstract class OpenApiGenerateSpecification extends WorkspaceFunction< Promise > { /** * The location where the OpenAPI specification should be written. */ @CliOption({ flags: '-o, --output ', description: `The location where the OpenAPI specification should be written.`, }) @IsString() @AllowMissing() readonly output?: string; /** * The version to set in `info.version` of the generated specification. */ @CliOption({ flags: '--version ', description: 'The version to set in info.version of the generated specification.', }) @IsString() @AllowMissing() readonly version?: string; /** * Whether the function should return the specification instead of writing it to a file. * This is not accessible from the command line, but is used when merging specifications. * Project-specific implementations should support this option. */ @IsBoolean() @AllowMissing() readonly returnSpecification?: boolean; }