Skip to content

Commit 341c335

Browse files
ggreifclaude
andcommitted
samples(motoko): add generated petstore client (nodfx)
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>
1 parent 1eb2f72 commit 341c335

18 files changed

Lines changed: 2273 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.openapi-generator-ignore
2+
README.md
3+
mops.toml
4+
src/Apis/PetApi.mo
5+
src/Apis/StoreApi.mo
6+
src/Apis/UserApi.mo
7+
src/Config.mo
8+
src/Models/ApiResponse.mo
9+
src/Models/Category.mo
10+
src/Models/FindPetsByStatusStatusParameterInner.mo
11+
src/Models/Order.mo
12+
src/Models/OrderStatus.mo
13+
src/Models/Pet.mo
14+
src/Models/PetStatus.mo
15+
src/Models/Tag.mo
16+
src/Models/User.mo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.22.0-SNAPSHOT
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# OpenAPI Petstore
2+
3+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
5+
This Motoko client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
6+
7+
- API version: 1.0.0
8+
- Generator version: 7.22.0-SNAPSHOT
9+
- Build package: org.openapitools.codegen.languages.MotokoClientCodegen
10+
11+
## Models
12+
13+
- ApiResponse
14+
- Category
15+
- FindPetsByStatusStatusParameterInner
16+
- Order
17+
- OrderStatus
18+
- Pet
19+
- PetStatus
20+
- Tag
21+
- User
22+
23+
## APIs
24+
25+
- PetApi
26+
- StoreApi
27+
- UserApi
28+
29+
## Installation
30+
31+
This is a Motoko module that can be used in your Internet Computer project.
32+
33+
## Usage
34+
35+
Import the generated API modules in your Motoko code:
36+
37+
```motoko
38+
import SomeApi "mo:petstore-client-nodfx/Apis/SomeApi";
39+
// or using destructuring for specific functions
40+
import { someFunction } "mo:petstore-client-nodfx/Apis/SomeApi";
41+
```
42+
43+
Configure and call the API:
44+
45+
```motoko
46+
import { defaultConfig } "mo:petstore-client-nodfx/Config";
47+
48+
// Use the default config as-is, or customize specific fields:
49+
let config = { defaultConfig with auth = ?#bearer "my-token" };
50+
51+
let result = await* SomeApi.someFunction(config, ...);
52+
```
53+
54+
The `defaultConfig` has `baseUrl` pre-set to the API's base URL, `cycles = 30_000_000_000`, and all optional fields set to `null`.
55+
56+
Alternatively, use the suite-based API to bind config once and call multiple functions without threading it through each call:
57+
58+
```motoko
59+
import { SomeApi } "mo:petstore-client-nodfx/Apis/SomeApi";
60+
61+
let api = SomeApi(config);
62+
let result = await api.someFunction(...);
63+
let other = await api.anotherFunction(...);
64+
```
65+
66+
### HTTP Outcalls and Cycles
67+
68+
The generated API client makes HTTP outcalls using the Internet Computer's management canister. HTTP outcalls require cycles to execute.
69+
70+
**Important:** Before calling any API endpoints, ensure your canister has sufficient cycles:
71+
72+
For local development:
73+
```bash
74+
# Get your canister ID
75+
CANISTER_ID=$(dfx canister id your_canister_name)
76+
77+
# Add cycles (100 trillion cycles for testing)
78+
dfx ledger fabricate-cycles --canister "$CANISTER_ID" --amount 100000000000000
79+
```
80+
81+
For production deployment, you'll need to fund your canister with cycles through the NNS or cycles wallet.
82+
83+
Each HTTP outcall typically costs around 20-50 million cycles depending on the request/response size.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[toolchain]
2+
moc = "1.4.1"
3+
4+
[package]
5+
name = "petstore-client-nodfx"
6+
version = "1.0.0"
7+
description = "Generated Motoko client for OpenAPI Petstore"
8+
license = "Apache-2.0"
9+
files = ["src/Config.mo", "src/Apis/**/*.mo", "src/Models/**/*.mo"]
10+
11+
[dependencies]
12+
core = "2.4.0"
13+
serde = "3.5.0"
14+
"cbor@4.1.0" = "4.1.0"
15+
"itertools@0.2.2" = "0.2.2" # because for serde
16+
base = "0.16.0" # because serde uses json.mo submodule
17+
xtended-numbers = "2.3.0"
18+
"sha2@0.1.6" = "0.1.6"

0 commit comments

Comments
 (0)