-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CaseFormatLambda has been added, params for Rest-assured client has b…
…een refactored (#91)
- Loading branch information
Showing
7 changed files
with
189 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
48 changes: 48 additions & 0 deletions
48
...s/openapi-generator/src/main/java/org/openapitools/codegen/mustache/CaseFormatLambda.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.openapitools.codegen.mustache; | ||
|
||
import com.google.common.base.CaseFormat; | ||
import com.samskivert.mustache.Mustache; | ||
import com.samskivert.mustache.Template; | ||
import org.openapitools.codegen.CodegenConfig; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* Converts text from CaseFormat to another CaseFormat | ||
* | ||
* Register: | ||
* <pre> | ||
* additionalProperties.put("convert", new CaseFormatLambda(LOWER_CAMEL, UPPER_UNDERSCORE)); | ||
* </pre> | ||
* | ||
* Use: | ||
* <pre> | ||
* {{#convert}}{{name}}{{/convert}} | ||
* </pre> | ||
*/ | ||
public class CaseFormatLambda implements Mustache.Lambda { | ||
private CodegenConfig generator = null; | ||
|
||
private CaseFormat initialFormat; | ||
private CaseFormat targetFormat; | ||
|
||
public CaseFormatLambda(CaseFormat target, CaseFormat targetFormat) { | ||
this.initialFormat = target; | ||
this.targetFormat = targetFormat; | ||
} | ||
|
||
public CaseFormatLambda generator(final CodegenConfig generator) { | ||
this.generator = generator; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void execute(Template.Fragment fragment, Writer writer) throws IOException { | ||
String text = initialFormat.converterTo(targetFormat).convert(fragment.execute()); | ||
if (generator != null && generator.reservedWords().contains(text)) { | ||
text = generator.escapeReservedWord(text); | ||
} | ||
writer.write(text); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.