feat(motoko): add Motoko client generator#23544
Draft
ggreif wants to merge 11 commits intoOpenAPITools:masterfrom
Draft
feat(motoko): add Motoko client generator#23544ggreif wants to merge 11 commits intoOpenAPITools:masterfrom
ggreif wants to merge 11 commits intoOpenAPITools:masterfrom
Conversation
Adds a Motoko OpenAPI client generator targeting the Internet Computer (IC) platform. Includes the codegen Java class, 6 Mustache templates, unit tests, service-loader registration, generators.md listing, and petstore sample configs for validation.
- Add Apache 2.0 license header - Add @OverRide on getTag/getName/getHelp - Add GeneratorMetadata with Stability.BETA - Add modifyFeatureSet() declaring supported features - Remove dead swagger-v1 imports (ArrayProperty, MapProperty, Property, Parameter) and unused StringUtils - Add missing meta/features imports - Move service-loader entry to correct alphabetical position (after MysqlSchemaCodegen, before N4jsClientCodegen) - Add docs/generators/motoko.md following standard generator doc format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
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>
Throw IllegalArgumentException in processOpts() when both flags are set. Update CLI option descriptions to document the constraint. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generated from motoko-petstore-nodfx.yaml using the petstore OpenAPI spec. Provides the committed reference output required by the new-generator checklist. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…motoko Drop the -nodfx suffix — it's the canonical Motoko petstore sample. Also rename the config from motoko-petstore-nodfx.yaml to motoko-petstore.yaml. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…unavailable) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…had -nodfx suffix) Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
This PR adds a Motoko client generator for OpenAPI Generator, targeting the Internet Computer (IC) platform.
Motoko is the native smart-contract language for the IC. The generated client makes HTTP outcalls from IC canisters using the Management Canister's
http_requestAPI, and uses the serde Mops package for JSON serialization/deserialization.Files included
Generator implementation
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MotokoClientCodegen.javaMustache templates (6 files)
modules/openapi-generator/src/main/resources/motoko/api.mustachemodules/openapi-generator/src/main/resources/motoko/model.mustachemodules/openapi-generator/src/main/resources/motoko/enum.mustachemodules/openapi-generator/src/main/resources/motoko/Config.mustachemodules/openapi-generator/src/main/resources/motoko/README.mustachemodules/openapi-generator/src/main/resources/motoko/mops.toml.mustacheTests
modules/openapi-generator/src/test/java/org/openapitools/codegen/motoko/MotokoClientCodegenTest.javamodules/openapi-generator/src/test/java/org/openapitools/codegen/motoko/MotokoClientCodegenModelTest.javamodules/openapi-generator/src/test/java/org/openapitools/codegen/motoko/MotokoClientCodegenOptionsTest.javamodules/openapi-generator/src/test/java/org/openapitools/codegen/options/MotokoClientCodegenOptionsProvider.javaRegistration & sample configs
modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig— single-line addition registeringMotokoClientCodegendocs/generators.md— single-line addition listingmotoko (beta)in the client generators sectionbin/configs/motoko-petstore-new.yaml— petstore sample config (with dfx)bin/configs/motoko-petstore-nodfx.yaml— petstore sample config (without dfx)Validation
Generation was tested against the standard petstore spec (
modules/openapi-generator/src/test/resources/3_0/petstore.yaml). The generator produced:src/Apis/PetApi.mo,StoreApi.mo,UserApi.mo— API client modulessrc/Models/Pet.mo,Order.mo,User.mo, etc. — model types with JSON serializationsrc/Config.mo— canister configurationmops.toml,README.md— project metadataThe generated
.mofiles include correct IC Management Canister HTTP outcall types, proper Motoko module structure, and serde-based JSON encoding/decoding.Generator features
useDfxoption to generate dfx deployment configuration🤖 Generated with Claude Code
Summary by cubic
Adds a new
motokoclient generator for Internet Computer canisters using Management Canisterhttp_requestandserdeJSON. Includes a committed Petstore sample andicp.yamlscaffolding via a newuseIcpoption alongsideuseDfx.New Features
MotokoClientCodegenwith templates:api,model,enum,Config,README,mops.toml,icp.yaml.Config; auth: bearer, API key, basic.useDfxanduseIcp; both enableuseImportedInterfaceto importic:aaaaa-aa(inline types when neither).serdeJSON for enums/oneOf, arrays, maps, optionals; auto‑convert non‑negativeInttoNat.docs/generators/motoko.md; Petstore sample atsamples/client/petstore/motoko; sample config atbin/configs/motoko-petstore.yaml; unit tests added.Bug Fixes
useDfxanduseIcp(throws if both); CLI help and docs updated.bin/configs/motoko-petstore.yamlto remove-nodfxsuffixes inoutputDirandartifactId.Written for commit cfc8e66. Summary will update on new commits.