Skip to content

Commit 54bb2e8

Browse files
committed
update tests
1 parent 13e1f36 commit 54bb2e8

2 files changed

Lines changed: 33 additions & 29 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/scala/SttpCodegenTest.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void verifyApiKeyLocations() throws IOException {
111111
}
112112

113113
@Test
114-
public void circeSerdeWithMixedCaseFields() throws IOException {
114+
public void verifyCirceSerdeWithMixedCaseFields() throws IOException {
115115
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
116116
output.deleteOnExit();
117117
String outputPath = output.getAbsolutePath().replace('\\', '/');
@@ -136,40 +136,36 @@ public void circeSerdeWithMixedCaseFields() throws IOException {
136136
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "true");
137137
generator.opts(input).generate();
138138

139-
Path modelPath = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/model/MixedCaseModel.scala");
140-
Path jsonSupportPath = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/core/JsonSupport.scala");
139+
Path mixedCaseModelPath = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/model/MixedCaseModel.scala");
141140

142-
// Model should have camelCase Scala field names in the case class
143-
assertFileContains(modelPath, "firstName");
144-
assertFileContains(modelPath, "phoneNumber");
145-
assertFileContains(modelPath, "lastName");
146-
assertFileContains(modelPath, "zipCode");
147-
assertFileContains(modelPath, "address");
141+
assertFileContains(mixedCaseModelPath, "firstName");
142+
assertFileContains(mixedCaseModelPath, "phoneNumber");
143+
assertFileContains(mixedCaseModelPath, "lastName");
144+
assertFileContains(mixedCaseModelPath, "zipCode");
145+
assertFileContains(mixedCaseModelPath, "address");
148146

149-
// Encoder should use original baseName for JSON keys
150-
assertFileContains(modelPath, "\"first-name\""); // kebab-case preserved
151-
assertFileContains(modelPath, "\"phone_number\""); // snake_case preserved
152-
assertFileContains(modelPath, "\"lastName\""); // camelCase preserved
153-
assertFileContains(modelPath, "\"ZipCode\""); // PascalCase preserved
154-
assertFileContains(modelPath, "\"address\""); // lowercase preserved
147+
assertFileContains(mixedCaseModelPath, "\"first-name\"");
148+
assertFileContains(mixedCaseModelPath, "\"phone_number\"");
149+
assertFileContains(mixedCaseModelPath, "\"lastName\"");
150+
assertFileContains(mixedCaseModelPath, "\"ZipCode\"");
151+
assertFileContains(mixedCaseModelPath, "\"address\"");
155152

156-
// Decoder should use original baseName in downField
157-
assertFileContains(modelPath, "c.downField(\"first-name\")");
158-
assertFileContains(modelPath, "c.downField(\"phone_number\")");
159-
assertFileContains(modelPath, "c.downField(\"ZipCode\")");
153+
assertFileContains(mixedCaseModelPath, "c.downField(\"first-name\")");
154+
assertFileContains(mixedCaseModelPath, "c.downField(\"phone_number\")");
155+
assertFileContains(mixedCaseModelPath, "c.downField(\"ZipCode\")");
160156

161-
// Model should have explicit encoder/decoder companion object
162-
assertFileContains(modelPath, "object MixedCaseModel");
163-
assertFileContains(modelPath, "implicit val encoderMixedCaseModel");
164-
assertFileContains(modelPath, "implicit val decoderMixedCaseModel");
157+
assertFileContains(mixedCaseModelPath, "object MixedCaseModel");
158+
assertFileContains(mixedCaseModelPath, "implicit val encoderMixedCaseModel");
159+
assertFileContains(mixedCaseModelPath, "implicit val decoderMixedCaseModel");
165160

166-
// Model should import JsonSupport for enum implicits
167-
assertFileContains(modelPath, "import org.openapitools.client.core.JsonSupport._");
161+
Path binaryModelPath = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/model/BinaryPayload.scala");
162+
assertFileContains(binaryModelPath, "data: Option[java.io.File]");
163+
assertFileContains(binaryModelPath, "metadata: Option[Any]");
164+
assertFileContains(binaryModelPath, "c.downField(\"data\")");
165+
assertFileContains(binaryModelPath, "c.downField(\"metadata\")");
166+
assertFileContains(binaryModelPath, "implicit val encoderBinaryPayload");
167+
assertFileContains(binaryModelPath, "implicit val decoderBinaryPayload");
168168

169-
// JsonSupport should NOT use AutoDerivation (we have explicit instances now)
170-
assertFileNotContains(jsonSupportPath, "AutoDerivation");
171-
172-
// AdditionalTypeSerializers should have File and Any codecs for circe
173169
Path additionalSerializersPath = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala");
174170
assertFileContains(additionalSerializersPath, "FileDecoder");
175171
assertFileContains(additionalSerializersPath, "FileEncoder");

modules/openapi-generator/src/test/resources/3_0/scala/mixed-case-fields.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ components:
2828
type: string
2929
address:
3030
type: string
31+
BinaryPayload:
32+
type: object
33+
properties:
34+
data:
35+
type: string
36+
format: binary
37+
metadata:
38+
type: object

0 commit comments

Comments
 (0)