Skip to content

Add a --config file for all generation options and dependency sources - #368

Open
farkasseb wants to merge 9 commits into
uber:masterfrom
farkasseb:feat/config-file
Open

farkasseb wants to merge 9 commits into
uber:masterfrom
farkasseb:feat/config-file

Conversation

@farkasseb

@farkasseb farkasseb commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the config file agreed in #363: one JSON5 file per run, with paths relative to the file. It accepts every key below:

// mockolo.json5
{
  sources: ["Sources/ModuleB", "Generated/Strings.swift"],
  destination: "Mocks/ModuleBMocks.swift",
  module: "ModuleB",
  dependencies: { ModuleA: ["Sources/ModuleA"] },  // resolve inherited types, never mocked
  mockfiles: ["Mocks/ModuleAMocks.swift"],
  annotation: "@mockable",
  header: "// swiftlint:disable all",
  macro: "DEBUG",
  concurrencyLimit: 4,
  loggingLevel: 1,
  mockFinal: true,
  enableArgsHistory: true,
  mockAll: false,
  allowSetCallCount: true,
  disableCombineDefaultValues: false,
  useTemplateFunc: false,
  customImports: ["Combine"],
  testableImports: ["ModuleB"],
  excludeImports: ["UIKit"],
  excludeSuffixes: ["Tests"],
}
mockolo --config mockolo.json5 --destination Other.swift   # the CLI value overrides
  • The README table lists the config keys and their CLI options. A CLI value overrides, a non-empty CLI list replaces, and a flag is on if the CLI sets it or the config sets it to true.
  • dependencies are keyed by module name, but types still resolve by name alone.
  • Wrong types are errors that name the key; so are missing input paths, when the key is used. Unknown keys are ignored.
  • --dependency-sourcedirs from Add dependency sources for cross-module inheritance #363 is dropped. generate() gains dependencySourceFiles:.
  • The framework tests move to Tests/MockoloFrameworkTests/, and the new Tests/MockoloTests/ runs the built binary.

Blast Radius: additive. Existing command lines behave as before. Linux toolchains older than 6.0 read strict JSON only.

🤖 Generated with Claude Code

farkasseb and others added 8 commits November 14, 2026 22:03
Test targets follow SwiftPM naming, one per tested target: the
framework tests live in MockoloFrameworkTests at the default path,
making room for a MockoloTests target for the executable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
generate() takes dependencySourceFiles: declarations parsed from these
files resolve inherited types of the source protocols but are never
mocked and never replace a source declaration. When several dependency
files declare the same name, the earliest file in the list wins. The
existing import merges in generate() now use Dictionary.merge too, to
match the new block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mockolo --config reads a JSON5 file describing the run. It can set
sources (directories and files, relative to the config file) and
destination, so --destination is no longer required when the config
sets it. --sourcedirs, --filelist or --sourcefiles replace sources and
--destination overrides destination. Unknown keys, wrong types, null
values and missing paths fail with the config path and the key path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The config file can set module and dependencies, a map from module
name to source directories and files. Dependency declarations resolve
inherited types of the sources but are never mocked; modules are read
in name order and the CLI source options leave them unchanged. module
is reserved for module-qualified lookup. Empty module names are
errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he config

The config file can set annotation, header, macro, concurrencyLimit
and loggingLevel. The CLI value overrides the config's, which
overrides the default. A loggingLevel outside 0 to 3 in the config is
an error even when --logging-level overrides it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The config file can set mockFinal, enableArgsHistory, mockAll,
allowSetCallCount, disableCombineDefaultValues and useTemplateFunc.
Either the CLI flag or the config value turns each one on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s to the config

The config file can set customImports, testableImports, excludeImports
and excludeSuffixes. The CLI list replaces the config's list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The config file can set mockfiles, parent mock files and directories
relative to the config file, checked and expanded like sources.
--mockfiles or --mock-filelist on the command line replaces the
config's list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@farkasseb

Copy link
Copy Markdown
Contributor Author

I recommend checking the diff commit by commit for easier review. The first commit renaming the test target is arguably not the scope of this PR but adding a new test target begged for using the default naming conventions for the tests. Let me know what you think and I'm happy to adjust / split.

@farkasseb

Copy link
Copy Markdown
Contributor Author

@sidepelican gentle ping if you have time to review. Please let me know what to change / how do you like it.

@sidepelican

Copy link
Copy Markdown
Contributor

I lost my maintainer access to mockolo after Uber recently updated its 2FA requirements.
@alanzeino , I’ve updated my GitHub account settings. Could you add me back as a maintainer?

I’ve also had less time to spend on mockolo maintenance lately. Given @farkasseb ’s recent contributions, I think they’d make a great maintainer. Could you consider adding them to the team as well?

Comment thread Sources/Mockolo/ConfigSchema.swift Outdated
import ArgumentParser
import Foundation

enum ConfigSchema {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfigSchema seems to be used only for decoding, and it feels like more code than we need here.
Could we simplify this by using decoder.decode(Config.self, from: data) directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it to catch unknown keys, so typos fail loudly (and also to catch explicit nulls, which I could drop since every key is optional anyway). A plain decode(Config.self, from:) ignores unknown keys. I could drop ConfigSchema and keep just that check implemented differently, maybe comparing top-level keys. I'm not 100% sure if that's better but happy to go either direction. What's your suggestion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d suggest dropping ConfigSchema and decoding Config directly.
Catching unknown keys feels like a nice-to-have here, but I’d prioritize keeping the implementation simple and stick with the default JSONDecoder behavior that Swift developers are familiar with.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I kept a small DecodingError → ValidationError mapping, let me know if that should also be cut. It's making the error message much nicer and more informative so I'd keep it but up to you.

Drop ConfigSchema and decode Config with JSONDecoder, as suggested in
review. Unknown keys are now ignored and null counts as absent. A
DecodingError becomes a ValidationError that names the config file,
the key path when the decoder gives one, and the decoder's message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sidepelican sidepelican left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!
But I don't have any permissions now ... 😥

@sidepelican

Copy link
Copy Markdown
Contributor

Hi @rudro, could you help with the mockolo maintainer access request at #368 (comment) ? Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants