Repository navigation
feat(mock): add the mock generate command - #484
Merged
Merged
Conversation
apimatic mock generate zips the project's src folder, sends it to codegen's /mock endpoint, waits for the run and replaces the stubs directory with the stub files it downloads. The default destination is the folder mock serve reads by default, so the two commands work in a project directory with no flags. The download is unpacked and loaded as mock serve would load it before the stubs directory is touched, so a run that fails or returns stub files the mock would refuse leaves the last set in place. The three routes and the layout of the download are stated in stub-generation-service.ts alone. The endpoint does not exist yet, so the command is hidden and its tests run against a local stand-in for it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
docs/mock/generator-handoff.md gains a section on the three /mock routes the command calls, the statuses it reads, the layout it expects in the download and the two points still open on the codegen side. The plan records phase 8: what was built, how it differs from plugin generate, what could not be run without the endpoint and what to do when it is live. CONTEXT.md says what mock generate does to the stubs directory. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mock generate took the download as a stream, so a connection that dropped or stalled after the headers failed while the action saved it, and the error was thrown out of the command. The service now receives the download whole: a break is one more failed request, reported like the others, and the stubs directory keeps the last set. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Adds
apimatic mock generate, stacked on #474. It sends the project's build to codegen, waits for the run, downloads the stub files and writes them to the folderapimatic mock servereads. In a project directory the two commands work with no flags:The endpoint it calls does not exist yet. The command is written against the planned
/mockcontract, which has the shape of/plugin, and is hidden until that endpoint is live, so a release cannot ship a command that always fails.What it does
plugin generatedoes: a zip ofsrc/, toPOST /mock. It asks for no language and needs nopluginblock or metadata inapimatic.json.GET /mock/{id}/statuswith the sharedpollUntilCompleted, then downloadsGET /mock/{id}/download.mock serveuses. Stub files the mock would refuse are reported problem by problem, and the stubs directory is left as it was. So is a run that fails, and a download without a stub.mock serveloads every file in the folder, so one left from the last set would be served beside the new one. Only a.gitfolder is kept.--forceskips the question.Flags:
--input(the project directory),--destination(defaultstubsin the project directory, so--input Xwrites toX/stubs),--force,--auth-key. Errors use the wording ofplugin generate.How it is built
plugin generatelayer by layer:commands/mock/generate.ts,actions/mock/generate.ts,prompts/mock/generate.ts,infrastructure/services/stub-generation-service.ts, withtypes/stubs-context.tsfor the stubs directory.stub-generation-service.ts: the three routes, and the place of the stub files in the download (STUB_FILES_IN_DOWNLOAD). A change on the codegen side is an edit to that one file.STUBS_DIRECTORY_NAMEintypes/project-layout.tsis now the one name both commands share;mock serve's default is built from it.docs/mock/generator-handoff.mdgains section 6, which states the contract as the CLI reads it..ai/plans/mock-server.mdrecords the work as phase 8, with what to do when the endpoint is live.How it was checked
pnpm build,pnpm lintandpnpm testpass locally (3917 passing, 93 pending). 68 of the tests are new.test/helpers/stub-generation-endpoint.ts), asplugin-service.test.tsdoes for/plugin./healthanswers 200).mock generatewith only an auth key, thenmock servewith no stubs flag, served the generated set; a second run with--forceremoved a file left from the first.Not run: the real endpoint, since there is none, and the overwrite question in a real terminal.
For the reviewer
/plugin.originsent isAPIMATIC CLI mock:generate, since oclif spells the command's id with a colon, asplugin generatesendsplugin:generate.plugin generatein two places. The overwrite question counts hidden files, because the replace removes them. A run that returns no stub is a failure and leaves the folder as it was.plugin generateandsdk generatestream theirs, so the same break throws while they save it; they are not changed here.stubsis not added to the foldersquickstartputs in a project's.gitignore. Whether it should be is left for when the command is shown.hidden, widen themocktopic's description, runpnpm readme.🤖 Generated with Claude Code