Skip to content

Commit 10afe76

Browse files
ggreifclaude
andcommitted
chore(motoko): adopt upstream generator conventions
- 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>
1 parent 03d5154 commit 10afe76

3 files changed

Lines changed: 303 additions & 9 deletions

File tree

docs/generators/motoko.md

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
---
2+
title: Documentation for the motoko Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | motoko | pass this to the generate command after -g |
10+
| generator stability | BETA | |
11+
| generator type | CLIENT | |
12+
| generator language | Motoko | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a Motoko OpenAPI client module. | |
15+
16+
## CONFIG OPTIONS
17+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
18+
19+
| Option | Description | Values | Default |
20+
| ------ | ----------- | ------ | ------- |
21+
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
23+
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
24+
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response. With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enums are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
25+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
26+
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
27+
|projectName|Project name for generated code| |null|
28+
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
29+
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
30+
|useDfx|Generate code for dfx with ic:aaaaa-aa imports| |false|
31+
32+
## IMPORT MAPPING
33+
34+
| Type/Alias | Imports |
35+
| ---------- | ------- |
36+
37+
38+
## INSTANTIATION TYPES
39+
40+
| Type/Alias | Instantiated By |
41+
| ---------- | --------------- |
42+
43+
44+
## LANGUAGE PRIMITIVES
45+
46+
<ul class="column-ul">
47+
<li>Any</li>
48+
<li>Blob</li>
49+
<li>Bool</li>
50+
<li>Char</li>
51+
<li>Error</li>
52+
<li>Float</li>
53+
<li>Int</li>
54+
<li>Int16</li>
55+
<li>Int32</li>
56+
<li>Int64</li>
57+
<li>Int8</li>
58+
<li>Nat</li>
59+
<li>Nat16</li>
60+
<li>Nat32</li>
61+
<li>Nat64</li>
62+
<li>Nat8</li>
63+
<li>None</li>
64+
<li>Null</li>
65+
<li>Principal</li>
66+
<li>Region</li>
67+
<li>Text</li>
68+
</ul>
69+
70+
## RESERVED WORDS
71+
72+
<ul class="column-ul">
73+
<li>actor</li>
74+
<li>and</li>
75+
<li>any</li>
76+
<li>assert</li>
77+
<li>async</li>
78+
<li>await</li>
79+
<li>blob</li>
80+
<li>bool</li>
81+
<li>break</li>
82+
<li>case</li>
83+
<li>catch</li>
84+
<li>char</li>
85+
<li>class</li>
86+
<li>continue</li>
87+
<li>debug</li>
88+
<li>do</li>
89+
<li>else</li>
90+
<li>error</li>
91+
<li>false</li>
92+
<li>float</li>
93+
<li>for</li>
94+
<li>func</li>
95+
<li>if</li>
96+
<li>import</li>
97+
<li>in</li>
98+
<li>int</li>
99+
<li>int16</li>
100+
<li>int32</li>
101+
<li>int64</li>
102+
<li>int8</li>
103+
<li>label</li>
104+
<li>let</li>
105+
<li>loop</li>
106+
<li>map</li>
107+
<li>module</li>
108+
<li>nat</li>
109+
<li>nat16</li>
110+
<li>nat32</li>
111+
<li>nat64</li>
112+
<li>nat8</li>
113+
<li>none</li>
114+
<li>not</li>
115+
<li>null</li>
116+
<li>object</li>
117+
<li>or</li>
118+
<li>principal</li>
119+
<li>private</li>
120+
<li>public</li>
121+
<li>query</li>
122+
<li>region</li>
123+
<li>return</li>
124+
<li>shared</li>
125+
<li>switch</li>
126+
<li>system</li>
127+
<li>text</li>
128+
<li>throw</li>
129+
<li>true</li>
130+
<li>try</li>
131+
<li>type</li>
132+
<li>var</li>
133+
<li>while</li>
134+
<li>with</li>
135+
</ul>
136+
137+
## FEATURE SET
138+
139+
140+
### Client Modification Feature
141+
| Name | Supported | Defined By |
142+
| ---- | --------- | ---------- |
143+
|BasePath|✓|ToolingExtension
144+
|Authorizations|✗|ToolingExtension
145+
|UserAgent|✗|ToolingExtension
146+
|MockServer|✗|ToolingExtension
147+
148+
### Data Type Feature
149+
| Name | Supported | Defined By |
150+
| ---- | --------- | ---------- |
151+
|Custom|✗|OAS2,OAS3
152+
|Int32|✓|OAS2,OAS3
153+
|Int64|✓|OAS2,OAS3
154+
|Float|✓|OAS2,OAS3
155+
|Double|✓|OAS2,OAS3
156+
|Decimal|✗|ToolingExtension
157+
|String|✓|OAS2,OAS3
158+
|Byte|✓|OAS2,OAS3
159+
|Binary|✓|OAS2,OAS3
160+
|Boolean|✓|OAS2,OAS3
161+
|Date|✓|OAS2,OAS3
162+
|DateTime|✓|OAS2,OAS3
163+
|Password|✓|OAS2,OAS3
164+
|File|✓|OAS2
165+
|Uuid||
166+
|Array|✓|OAS2,OAS3
167+
|Null|✗|OAS3
168+
|AnyType|✗|OAS2,OAS3
169+
|Object|✓|OAS2,OAS3
170+
|Maps|✓|ToolingExtension
171+
|CollectionFormat|✓|OAS2
172+
|CollectionFormatMulti|✓|OAS2
173+
|Enum|✓|OAS2,OAS3
174+
|ArrayOfEnum|✓|ToolingExtension
175+
|ArrayOfModel|✓|ToolingExtension
176+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
177+
|ArrayOfCollectionOfModel|✓|ToolingExtension
178+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
179+
|MapOfEnum|✓|ToolingExtension
180+
|MapOfModel|✓|ToolingExtension
181+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
182+
|MapOfCollectionOfModel|✓|ToolingExtension
183+
|MapOfCollectionOfEnum|✓|ToolingExtension
184+
185+
### Documentation Feature
186+
| Name | Supported | Defined By |
187+
| ---- | --------- | ---------- |
188+
|Readme|✓|ToolingExtension
189+
|Model|✓|ToolingExtension
190+
|Api|✓|ToolingExtension
191+
192+
### Global Feature
193+
| Name | Supported | Defined By |
194+
| ---- | --------- | ---------- |
195+
|Host|✓|OAS2,OAS3
196+
|BasePath|✓|OAS2,OAS3
197+
|Info|✓|OAS2,OAS3
198+
|Schemes|✗|OAS2,OAS3
199+
|PartialSchemes|✓|OAS2,OAS3
200+
|Consumes|✓|OAS2
201+
|Produces|✓|OAS2
202+
|ExternalDocumentation|✓|OAS2,OAS3
203+
|Examples|✓|OAS2,OAS3
204+
|XMLStructureDefinitions|✗|OAS2,OAS3
205+
|MultiServer|✗|OAS3
206+
|ParameterizedServer|✗|OAS3
207+
|ParameterStyling|✗|OAS3
208+
|Callbacks|✗|OAS3
209+
|LinkObjects|✗|OAS3
210+
211+
### Parameter Feature
212+
| Name | Supported | Defined By |
213+
| ---- | --------- | ---------- |
214+
|Path|✓|OAS2,OAS3
215+
|Query|✓|OAS2,OAS3
216+
|Header|✓|OAS2,OAS3
217+
|Body|✓|OAS2
218+
|FormUnencoded|✗|OAS2
219+
|FormMultipart|✗|OAS2
220+
|Cookie|✗|OAS3
221+
222+
### Schema Support Feature
223+
| Name | Supported | Defined By |
224+
| ---- | --------- | ---------- |
225+
|Simple|✓|OAS2,OAS3
226+
|Composite|✓|OAS2,OAS3
227+
|Polymorphism|✗|OAS2,OAS3
228+
|Union|✗|OAS3
229+
|allOf|✗|OAS2,OAS3
230+
|anyOf|✓|OAS3
231+
|oneOf|✓|OAS3
232+
|not|✗|OAS3
233+
234+
### Security Feature
235+
| Name | Supported | Defined By |
236+
| ---- | --------- | ---------- |
237+
|BasicAuth|✓|OAS2,OAS3
238+
|ApiKey|✓|OAS2,OAS3
239+
|OpenIDConnect|✗|OAS3
240+
|BearerToken|✓|OAS3
241+
|OAuth2_Implicit|✗|OAS2,OAS3
242+
|OAuth2_Password|✗|OAS2,OAS3
243+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
244+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
245+
|SignatureAuth|✗|OAS3
246+
|AWSV4Signature|✗|ToolingExtension
247+
248+
### Wire Format Feature
249+
| Name | Supported | Defined By |
250+
| ---- | --------- | ---------- |
251+
|JSON|✓|OAS2,OAS3
252+
|XML|✗|OAS2,OAS3
253+
|PROTOBUF|✗|ToolingExtension
254+
|Custom|✗|OAS2,OAS3

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,84 @@
1+
/*
2+
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.openapitools.codegen.languages;
218

319
import org.openapitools.codegen.*;
20+
import org.openapitools.codegen.meta.GeneratorMetadata;
21+
import org.openapitools.codegen.meta.Stability;
22+
import org.openapitools.codegen.meta.features.*;
423
import org.openapitools.codegen.model.ModelMap;
524
import org.openapitools.codegen.model.ModelsMap;
625
import org.openapitools.codegen.model.OperationsMap;
726
import org.openapitools.codegen.utils.ModelUtils;
8-
import io.swagger.models.properties.ArrayProperty;
9-
import io.swagger.models.properties.MapProperty;
10-
import io.swagger.models.properties.Property;
11-
import io.swagger.models.parameters.Parameter;
1227
import io.swagger.v3.oas.models.media.Schema;
1328

1429
import java.io.File;
1530
import java.util.*;
1631

17-
import org.apache.commons.lang3.StringUtils;
18-
1932
public class MotokoClientCodegen extends DefaultCodegen implements CodegenConfig {
2033
public static final String PROJECT_NAME = "projectName";
2134
public static final String USE_DFX = "useDfx";
2235

2336
protected String projectName = "OpenAPI";
2437
protected boolean useDfx = false;
2538

39+
@Override
2640
public CodegenType getTag() {
2741
return CodegenType.CLIENT;
2842
}
2943

44+
@Override
3045
public String getName() {
3146
return "motoko";
3247
}
3348

49+
@Override
3450
public String getHelp() {
35-
return "Generates a Motoko OpenAPI client module.";
51+
return "Generates a Motoko client (beta).";
3652
}
3753

3854
public MotokoClientCodegen() {
3955
super();
4056

57+
modifyFeatureSet(features -> features
58+
.includeDocumentationFeatures(DocumentationFeature.Readme)
59+
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON))
60+
.securityFeatures(EnumSet.noneOf(SecurityFeature.class))
61+
.excludeGlobalFeatures(
62+
GlobalFeature.XMLStructureDefinitions,
63+
GlobalFeature.Callbacks,
64+
GlobalFeature.LinkObjects,
65+
GlobalFeature.ParameterStyling
66+
)
67+
.excludeSchemaSupportFeatures(
68+
SchemaSupportFeature.Polymorphism
69+
)
70+
.excludeParameterFeatures(
71+
ParameterFeature.Cookie
72+
)
73+
.includeClientModificationFeatures(
74+
ClientModificationFeature.BasePath
75+
)
76+
);
77+
78+
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
79+
.stability(Stability.BETA)
80+
.build();
81+
4182
outputFolder = "generated-code" + File.separator + "motoko";
4283
modelTemplateFiles.put("model.mustache", ".mo");
4384
apiTemplateFiles.put("api.mustache", ".mo");

modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ org.openapitools.codegen.languages.KotlinWiremockServerCodegen
9090
org.openapitools.codegen.languages.KtormSchemaCodegen
9191
org.openapitools.codegen.languages.LuaClientCodegen
9292
org.openapitools.codegen.languages.MarkdownDocumentationCodegen
93+
org.openapitools.codegen.languages.MotokoClientCodegen
9394
org.openapitools.codegen.languages.MysqlSchemaCodegen
9495
org.openapitools.codegen.languages.N4jsClientCodegen
9596
org.openapitools.codegen.languages.NimClientCodegen
@@ -165,5 +166,3 @@ org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
165166
org.openapitools.codegen.languages.WsdlSchemaCodegen
166167
org.openapitools.codegen.languages.XojoClientCodegen
167168
org.openapitools.codegen.languages.ZapierClientCodegen
168-
169-
org.openapitools.codegen.languages.MotokoClientCodegen

0 commit comments

Comments
 (0)