Skip to content

Commit c5e8303

Browse files
committed
fix(crystal): class name should be in PascalCase
Fix: - class EnumAttributeValidatorFor_type < EnumAttributeValidator + class EnumAttributeValidatorForType < EnumAttributeValidator
1 parent d4a4d8f commit c5e8303

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
import org.openapitools.codegen.model.OperationMap;
3030
import org.openapitools.codegen.model.OperationsMap;
3131
import org.openapitools.codegen.templating.mustache.PrefixWithHashLambda;
32-
import org.openapitools.codegen.templating.mustache.UppercaseLambda;
33-
import org.openapitools.codegen.templating.mustache.TitlecaseLambda;
32+
import org.openapitools.codegen.templating.mustache.PascalCaseLambda;
3433
import org.openapitools.codegen.utils.ModelUtils;
3534
import org.slf4j.Logger;
3635
import org.slf4j.LoggerFactory;
@@ -305,8 +304,7 @@ public void processOpts() {
305304

306305
// add lambda for mustache templates
307306
additionalProperties.put("lambdaPrefixWithHash", new PrefixWithHashLambda());
308-
additionalProperties.put("lambdaUppercase", new UppercaseLambda());
309-
additionalProperties.put("lambdaTitlecase", new TitlecaseLambda());
307+
additionalProperties.put("lambdaPascalcase", new PascalCaseLambda());
310308
}
311309

312310
@Override
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
17+
package org.openapitools.codegen.templating.mustache;
18+
19+
import com.samskivert.mustache.Mustache;
20+
import com.samskivert.mustache.Template;
21+
import org.openapitools.codegen.utils.CamelizeOption;
22+
23+
import java.io.IOException;
24+
import java.io.Writer;
25+
26+
import static org.openapitools.codegen.utils.StringUtils.camelize;
27+
28+
/**
29+
* Converts text in a fragment to PascalCase.
30+
* <p>
31+
* Register:
32+
* <pre>
33+
* additionalProperties.put("pascalcase", new PascalCaseLambda());
34+
* </pre>
35+
* <p>
36+
* Use:
37+
* <pre>
38+
* {{#pascalcase}}{{name}}{{/pascalcase}}
39+
* </pre>
40+
*/
41+
public class PascalCaseLambda implements Mustache.Lambda {
42+
public PascalCaseLambda() {
43+
}
44+
45+
@Override
46+
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
47+
String text = fragment.execute();
48+
text = camelize(text);
49+
writer.write(text);
50+
}
51+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
{{#vars}}
5757
{{#isEnum}}
5858
{{^isContainer}}
59-
class EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}} < EnumAttributeValidator
59+
class EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}} < EnumAttributeValidator
6060
@attribute : String
6161
@allowable_values : Array(Int32 | Int64 | Float32 | Float64 | String)
6262

@@ -118,7 +118,7 @@
118118
{{#vars}}
119119
{{#isEnum}}
120120
{{^isContainer}}
121-
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
121+
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
122122
if !{{{name}}}_validator.valid?(@{{{name}}})
123123
message = {{{name}}}_validator.message
124124
invalid_properties.push(message)
@@ -181,7 +181,7 @@
181181
{{#vars}}
182182
{{#isEnum}}
183183
{{^isContainer}}
184-
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
184+
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
185185
return false unless {{{name}}}_validator.valid?(@{{{name}}})
186186
{{/isContainer}}
187187
{{/isEnum}}
@@ -234,7 +234,7 @@
234234
# Custom attribute writer method checking allowed values (enum).
235235
# @param [Object] {{{name}}} Object to be assigned
236236
def {{{name}}}=({{{name}}})
237-
validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
237+
validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
238238
unless validator.valid?({{{name}}})
239239
raise ArgumentError.new(validator.message)
240240
end

0 commit comments

Comments
 (0)