forked from loafle/openapi-generator-original
[scala-sttp] fix enumeration operator constant name collision (#10596)
* fix enumeration operator onstant name collision * test to verify OperatorName
This commit is contained in:
parent
e37400554c
commit
417d69425a
@ -166,6 +166,13 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
dateLibrary.setEnum(dateOptions);
|
dateLibrary.setEnum(dateOptions);
|
||||||
cliOptions.add(dateLibrary);
|
cliOptions.add(dateLibrary);
|
||||||
|
|
||||||
|
specialCharReplacements.put("=", "Equal");
|
||||||
|
specialCharReplacements.put("!=", "Not_Equal");
|
||||||
|
specialCharReplacements.put(">", "Greater_Than");
|
||||||
|
specialCharReplacements.put("<", "Less_Than");
|
||||||
|
specialCharReplacements.put(">=", "Greater_Than_Or_Equal_To");
|
||||||
|
specialCharReplacements.put("<=", "Less_Than_Or_Equal_To");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -454,6 +461,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
prop.containerType = "set";
|
prop.containerType = "set";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,6 +516,9 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String formatIdentifier(String name, boolean capitalized) {
|
protected String formatIdentifier(String name, boolean capitalized) {
|
||||||
|
if (specialCharReplacements.containsKey(name)) {
|
||||||
|
name = specialCharReplacements.get(name);
|
||||||
|
}
|
||||||
String identifier = camelize(sanitizeName(name), true);
|
String identifier = camelize(sanitizeName(name), true);
|
||||||
if (capitalized) {
|
if (capitalized) {
|
||||||
identifier = StringUtils.capitalize(identifier);
|
identifier = StringUtils.capitalize(identifier);
|
||||||
|
@ -1,10 +1,26 @@
|
|||||||
package org.openapitools.codegen.scala;
|
package org.openapitools.codegen.scala;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||||
|
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.ClientOptInput;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.DefaultGenerator;
|
||||||
import org.openapitools.codegen.languages.ScalaSttpClientCodegen;
|
import org.openapitools.codegen.languages.ScalaSttpClientCodegen;
|
||||||
|
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
|
|
||||||
public class SttpCodegenTest {
|
public class SttpCodegenTest {
|
||||||
|
|
||||||
@ -29,4 +45,38 @@ public class SttpCodegenTest {
|
|||||||
Assert.assertEquals(type, "Array[Byte]");
|
Assert.assertEquals(type, "Array[Byte]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyOperatorName() throws IOException {
|
||||||
|
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||||
|
|
||||||
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
|
.readLocation("src/test/resources/3_0/scala/issue_10187_operatorName.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
|
ScalaSttpClientCodegen codegen = new ScalaSttpClientCodegen();
|
||||||
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput();
|
||||||
|
input.openAPI(openAPI);
|
||||||
|
input.config(codegen);
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
|
||||||
|
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
|
||||||
|
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
|
||||||
|
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
|
||||||
|
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
|
||||||
|
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
|
||||||
|
generator.opts(input).generate();
|
||||||
|
|
||||||
|
Path path = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/model/Condition.scala");
|
||||||
|
assertFileContains(path, "object ConditionEnums");
|
||||||
|
assertFileContains(path, "val Equal = Value(\"=\")");
|
||||||
|
assertFileContains(path, "val NotEqual = Value(\"!=\")");
|
||||||
|
assertFileNotContains(path, "val X3D = Value(\"=\")");
|
||||||
|
assertFileNotContains(path, "val X3D = Value(\"!=\")");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Example - The comparison operator
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
servers:
|
||||||
|
- url: http://api.example.xyz/v1
|
||||||
|
paths:
|
||||||
|
/report:
|
||||||
|
get:
|
||||||
|
operationId: getReport
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: get Report
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Reports'
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Reports:
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
expression:
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Condition'
|
||||||
|
type: array
|
||||||
|
Condition:
|
||||||
|
example:
|
||||||
|
variable: variable
|
||||||
|
operator: =
|
||||||
|
comparison_value: comparison_value
|
||||||
|
properties:
|
||||||
|
variable:
|
||||||
|
type: string
|
||||||
|
comparison_value:
|
||||||
|
type: string
|
||||||
|
operator:
|
||||||
|
description: The comparison operator.
|
||||||
|
enum:
|
||||||
|
- =
|
||||||
|
- '!='
|
||||||
|
- >
|
||||||
|
- <
|
||||||
|
- '>='
|
||||||
|
- <=
|
||||||
|
type: string
|
||||||
|
type: object
|
Loading…
x
Reference in New Issue
Block a user