Skip to content

Commit da778c4

Browse files
authored
add option to set params_encoder (#22484)
1 parent abea33c commit da778c4

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

bin/configs/crystal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ additionalProperties:
66
shardVersion: 1.0.0
77
moduleName: Petstore
88
shardName: petstore
9+
#paramsEncoder: Crest::EnumeratedFlatParamsEncoder
910
strictSpecBehavior: false
1011
modelNameMappings:
1112
PropertyNameMapping: AnotherPropertyNameMapping

docs/generators/crystal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2525
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
2626
|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|
2727
|moduleName|module name (e.g. TwitterClient| |OpenAPIClient|
28+
|paramsEncoder|params_encoder setting (e.g. Crest::NestedParamsEncoder, Crest::EnumeratedFlatParamsEncoder, Crest::ZeroEnumeratedFlatParamsEncoder| |Crest::NestedParamsEncoder|
2829
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
2930
|shardAuthor|shard author (only one is supported).| |null|
3031
|shardAuthorEmail|shard author email (only one is supported).| |null|

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
5757
@Setter protected String shardDescription = "This shard maps to a REST API";
5858
@Setter protected String shardAuthor = "";
5959
@Setter protected String shardAuthorEmail = "";
60+
@Setter protected String paramsEncoder = "Crest::NestedParamsEncoder";
6061
protected String apiDocPath = "docs/";
6162
protected String modelDocPath = "docs/";
6263
protected List<String> primitiveTypes = new ArrayList<String>();
@@ -70,6 +71,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
7071
public static final String SHARD_DESCRIPTION = "shardDescription";
7172
public static final String SHARD_AUTHOR = "shardAuthor";
7273
public static final String SHARD_AUTHOR_EMAIL = "shardAuthorEmail";
74+
public static final String PARAMS_ENCODER = "paramsEncoder";
7375

7476
public CrystalClientCodegen() {
7577
super();
@@ -197,15 +199,18 @@ public CrystalClientCodegen() {
197199

198200
cliOptions.add(new CliOption(SHARD_HOMEPAGE, "shard homepage.").defaultValue("http://org.openapitools"));
199201

200-
cliOptions.add(
201-
new CliOption(SHARD_DESCRIPTION, "shard description.").defaultValue("This shard maps to a REST API"));
202+
cliOptions.add(new CliOption(SHARD_DESCRIPTION, "shard description.").defaultValue("This shard maps to a REST API"));
202203

203204
cliOptions.add(new CliOption(SHARD_AUTHOR, "shard author (only one is supported)."));
204205

205206
cliOptions.add(new CliOption(SHARD_AUTHOR_EMAIL, "shard author email (only one is supported)."));
206207

207208
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
208209
CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).defaultValue(Boolean.TRUE.toString()));
210+
211+
cliOptions.add(new CliOption(PARAMS_ENCODER,
212+
"params_encoder setting (e.g. Crest::NestedParamsEncoder, Crest::EnumeratedFlatParamsEncoder, Crest::ZeroEnumeratedFlatParamsEncoder").
213+
defaultValue("Crest::NestedParamsEncoder"));
209214
}
210215

211216
@Override
@@ -260,6 +265,12 @@ public void processOpts() {
260265
setShardAuthorEmail((String) additionalProperties.get(SHARD_AUTHOR_EMAIL));
261266
}
262267

268+
if (additionalProperties.containsKey(PARAMS_ENCODER)) {
269+
setParamsEncoder((String) additionalProperties.get(PARAMS_ENCODER));
270+
} else {
271+
additionalProperties.put(PARAMS_ENCODER, paramsEncoder);
272+
}
273+
263274
// make api and model doc path available in mustache template
264275
additionalProperties.put("apiDocPath", apiDocPath);
265276
additionalProperties.put("modelDocPath", modelDocPath);

modules/openapi-generator/src/main/resources/crystal/api_client.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ module {{moduleName}}
147147
form: form_or_body,
148148
logging: @config.debugging,
149149
handle_errors: false,
150-
params_encoder: Crest::NestedParamsEncoder
150+
params_encoder: {{{paramsEncoder}}}
151151
)
152152

153153
response = request.execute

0 commit comments

Comments
 (0)