Skip to content

Commit 07d33fe

Browse files
ggreifclaude
andcommitted
feat(motoko): add useIcp canary option for icp-cli deployment
Adds a new `useIcp` boolean generator option (default: false) as a canary for the icp-cli tool that replaces dfx: - When useIcp=true, generates an icp.yaml scaffold configured with the @dfinity/motoko recipe pointing at the consumer canister's main.mo - README cycles section switches to icp-cli commands (local network auto-seeds cycles; mainnet via icp deploy -e ic) - api.mustache: remove dfx-specific wording from PUT/DELETE TODO comment (both dfx and icp-cli use moc for ic:aaaaa-aa resolution) - useDfx flag and behaviour unchanged Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 10afe76 commit 07d33fe

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MotokoClientCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
public class MotokoClientCodegen extends DefaultCodegen implements CodegenConfig {
3333
public static final String PROJECT_NAME = "projectName";
3434
public static final String USE_DFX = "useDfx";
35+
public static final String USE_ICP = "useIcp";
3536

3637
protected String projectName = "OpenAPI";
3738
protected boolean useDfx = false;
39+
protected boolean useIcp = false;
3840

3941
@Override
4042
public CodegenType getTag() {
@@ -146,6 +148,7 @@ public MotokoClientCodegen() {
146148

147149
cliOptions.add(CliOption.newString(PROJECT_NAME, "Project name for generated code"));
148150
cliOptions.add(CliOption.newBoolean(USE_DFX, "Generate code for dfx with ic:aaaaa-aa imports", useDfx));
151+
cliOptions.add(CliOption.newBoolean(USE_ICP, "Generate icp.yaml for deployment with icp-cli (canary; replaces dfx)", useIcp));
149152

150153
// Enable inline enum resolution to create model files for inline enum parameters
151154
// This ensures type-safe enum variants instead of raw Text types
@@ -164,6 +167,14 @@ public void processOpts() {
164167
setUseDfx(convertPropertyToBooleanAndWriteBack(USE_DFX));
165168
}
166169
additionalProperties.put(USE_DFX, useDfx);
170+
171+
if (additionalProperties.containsKey(USE_ICP)) {
172+
setUseIcp(convertPropertyToBooleanAndWriteBack(USE_ICP));
173+
}
174+
additionalProperties.put(USE_ICP, useIcp);
175+
if (useIcp) {
176+
supportingFiles.add(new SupportingFile("icp.yaml.mustache", "", "icp.yaml"));
177+
}
167178
}
168179

169180
@Override
@@ -228,6 +239,14 @@ public boolean getUseDfx() {
228239
return useDfx;
229240
}
230241

242+
public void setUseIcp(boolean useIcp) {
243+
this.useIcp = useIcp;
244+
}
245+
246+
public boolean getUseIcp() {
247+
return useIcp;
248+
}
249+
231250
@Override
232251
public String toModelImport(String name) {
233252
// For Motoko, imports are relative to the current Models directory

modules/openapi-generator/src/main/resources/motoko/README.mustache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ The generated API client makes HTTP outcalls using the Internet Computer's manag
7474

7575
**Important:** Before calling any API endpoints, ensure your canister has sufficient cycles:
7676

77+
{{#useIcp}}
78+
For local development with icp-cli:
79+
```bash
80+
icp network start -d # local replica auto-seeds cycles — no fabrication needed
81+
icp deploy # build + deploy
82+
```
83+
84+
For mainnet:
85+
```bash
86+
icp cycles balance -n ic # check balance
87+
icp deploy -e ic # deploy to mainnet
88+
```
89+
{{/useIcp}}
90+
{{^useIcp}}
7791
For local development:
7892
```bash
7993
# Get your canister ID
@@ -84,5 +98,6 @@ dfx ledger fabricate-cycles --canister "$CANISTER_ID" --amount 100000000000000
8498
```
8599

86100
For production deployment, you'll need to fund your canister with cycles through the NNS or cycles wallet.
101+
{{/useIcp}}
87102

88103
Each HTTP outcall typically costs around 20-50 million cycles depending on the request/response size.

modules/openapi-generator/src/main/resources/motoko/api.mustache

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ module {
2929
#get;
3030
#head;
3131
#post;
32-
// TODO: PUT and DELETE are now supported by the management canister in
33-
// non-replicated mode, but dfx doesn't expose these methods yet.
34-
// Uncomment once dfx support lands:
32+
// TODO: PUT and DELETE are supported in non-replicated mode but not yet
33+
// exposed via ic:aaaaa-aa imports. Uncomment once the interface is updated:
3534
// #put;
3635
// #delete;
3736
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# icp.yaml — generated by OpenAPI Generator (motoko)
2+
#
3+
# This file configures icp-cli (https://cli.internetcomputer.org) for a canister
4+
# that imports the {{artifactId}} generated client library.
5+
#
6+
# Usage:
7+
# icp network start -d # start local replica
8+
# icp deploy # build + deploy + sync
9+
# icp network stop # stop when done
10+
#
11+
# For mainnet: icp deploy -e ic
12+
13+
canisters:
14+
- name: {{#projectName}}{{projectName}}{{/projectName}}{{^projectName}}my_canister{{/projectName}}
15+
recipe:
16+
type: "@dfinity/motoko@v4.1.0"
17+
configuration:
18+
main: src/main.mo
19+
# Declare the candid interface once generated:
20+
# candid: {{#projectName}}{{projectName}}{{/projectName}}{{^projectName}}my_canister{{/projectName}}.did

0 commit comments

Comments
 (0)