Skip to content

Commit b6fff64

Browse files
ggreifclaude
andcommitted
fix(motoko): useIcp also uses ic:aaaaa-aa imported interface
Introduce a computed `useImportedInterface` flag (true when useDfx OR useIcp) so that both toolchain paths import all types from ic:aaaaa-aa instead of re-declaring them inline. icp-cli's @dfinity/motoko recipe uses the full management canister interface (including PUT/DELETE). dfx lags behind — but that is dfx's issue, not something the generator template should paper over. The inline fallback (neither flag set) keeps the hand-written interface with full PUT/DELETE support. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 07d33fe commit b6fff64

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public void processOpts() {
175175
if (useIcp) {
176176
supportingFiles.add(new SupportingFile("icp.yaml.mustache", "", "icp.yaml"));
177177
}
178+
// useImportedInterface: true when either useDfx or useIcp — both use moc with ic:aaaaa-aa imports
179+
additionalProperties.put("useImportedInterface", useDfx || useIcp);
178180
}
179181

180182
@Override

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import Array "mo:core/Array";
1010
import Error "mo:core/Error";
1111
import Base64 "mo:core/Base64";
1212
import { JSON } "mo:serde";
13-
{{#useDfx}}
13+
{{#useImportedInterface}}
1414
// FIXME: destructuring on `actor` types is not implemented yet for shared functions
1515
// type error [M0114], object pattern cannot consume actor type
1616
import { type http_request_args; type http_request_result; type http_header } "ic:aaaaa-aa";
1717
import Mgnt__ = "ic:aaaaa-aa";
18-
{{/useDfx}}
18+
{{/useImportedInterface}}
1919
{{#imports}}
2020
{{#isMap}}import { type Map; fromIter } "mo:core/pure/Map";
2121
{{/isMap}}{{^isMappedType}}import { type {{classname}}; JSON = {{classname}} } "../Models/{{classname}}";
@@ -24,23 +24,13 @@ import Mgnt__ = "ic:aaaaa-aa";
2424
import { type Config } "../Config";
2525

2626
module {
27-
{{#useDfx}}
28-
type http_method = {
29-
#get;
30-
#head;
31-
#post;
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:
34-
// #put;
35-
// #delete;
36-
};
37-
27+
{{#useImportedInterface}}
3828
let http_request = Mgnt__.http_request;
3929

40-
{{/useDfx}}
41-
{{^useDfx}}
30+
{{/useImportedInterface}}
31+
{{^useImportedInterface}}
4232
// Management Canister interface for HTTP outcalls
43-
// Based on types in https://github.com/dfinity/sdk/blob/master/src/dfx/src/util/ic.did
33+
// Based on https://github.com/dfinity/interface-spec/blob/master/spec/ic.did
4434
type http_header = {
4535
name : Text;
4636
value : Text;
@@ -75,7 +65,7 @@ module {
7565

7666
let http_request = (actor "aaaaa-aa" : actor { http_request : (http_request_args) -> async http_request_result }).http_request;
7767

78-
{{/useDfx}}
68+
{{/useImportedInterface}}
7969

8070
{{#operations}}
8171
{{#operation}}

0 commit comments

Comments
 (0)