generate service
Create a service trio (protocol + impl + mock) and register it in DI.
Creates a service in three files (protocol, real implementation, mock) and registers it in the DI container automatically.
Synopsis
Section titled “Synopsis”swiftspawn generate service <Name> [--with-tests] [--dry-run] [--force] [--quiet] [--verbose]Description
Section titled “Description”A service is one resource’s behavior. It’s always emitted as three files so tests, previews, and production code each have the implementation they need.
The Service suffix is optional; both generate service Movie and generate service MovieService produce the same files. Internally the canonical name is Movie and the protocol is MovieService.
The implementation has // TODO: markers where you write the real URLSession / API calls. The mock returns canned values suitable for previews. The protocol has a single placeholder method (fetch() by default). For a CRUD-shaped service, use recipe crud instead.
Examples
Section titled “Examples”swiftspawn generate service Movieswiftspawn generate service UserService --with-testsGenerated files
Section titled “Generated files”Services/<Name>Service.swiftServices/<Name>ServiceImpl.swiftServices/Mock<Name>Service.swiftWith --with-tests:
Tests/<App>Tests/Services/<Name>ServiceTests.swiftSide effects
Section titled “Side effects”-
Registers the service factory in
DIContainer.swiftbetween markers:// MARK: - Service Factories (auto-generated)var movieService: Factory<MovieService> { self { MovieServiceImpl() } }// MARK: - End auto-generated
If DIContainer.swift doesn’t have those markers (legacy projects), the generator prints the snippet to paste in instead.
Options
Section titled “Options”| Flag | Description |
|---|---|
--with-tests | Also emit a service test file. |
--dry-run | Preview without writing. |
--force | Overwrite existing files. |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 2 | Invalid name. |
| 5 | Not in a swiftspawn project. |
See also
Section titled “See also”generate screenwith--usesto wire ViewModels to services.recipe crudfor the 5-method CRUD shape.- Markers