Skip to content

Commit

Permalink
Fixed "byte" serialization bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ctasada committed Mar 23, 2024
1 parent 2621d6c commit 1866a0a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.swagger.v3.core.converter.ModelConverter
import io.swagger.v3.core.converter.ModelConverterContext
import io.swagger.v3.core.util.RefUtils
import io.swagger.v3.oas.models.media.ArraySchema
import io.swagger.v3.oas.models.media.IntegerSchema
import io.swagger.v3.oas.models.media.MapSchema
import io.swagger.v3.oas.models.media.ObjectSchema
import io.swagger.v3.oas.models.media.Schema
Expand Down Expand Up @@ -85,10 +84,6 @@ class KotlinxSerializationModelConverter(private val useFqn: Boolean = false) :
propertySchema = MapSchema().additionalProperties(context.resolve(AnnotatedType(value)))
}

propertyType.isSubclassOf(Byte::class) -> {
propertySchema = IntegerSchema()
}

else -> {
propertySchema = resolveRefSchema(property.returnType.javaType, context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ void testClassWithListProperty() {
ModelConverters modelConverters = setUp();

var result = modelConverters.readAll(new AnnotatedType(ClassWithListProperty.class));
Schema schema = result.get(ClassWithListProperty.class.getSimpleName());
Schema<?> schema = result.get(ClassWithListProperty.class.getSimpleName());

final Schema<?> listField = (Schema<?>) schema.getProperties().get("list_field");
assertThat(listField).isNotNull();
assertThat(listField.getType()).isEqualTo("array");
assertThat(listField.getNullable()).isFalse();
assertThat(listField.getItems()).isNotNull();
assertThat(listField.getItems().getType()).isEqualTo("string");

}
}

Expand Down Expand Up @@ -156,21 +155,25 @@ private void assertBasicFieldNames(Schema<?> model) {
final Schema<?> intField = (Schema<?>) model.getProperties().get("int_field");
assertThat(intField).isNotNull();
assertThat(intField.getType()).isEqualTo("integer");
assertThat(intField.getFormat()).isEqualTo("int32");
assertThat(intField.getNullable()).isFalse();

final Schema<?> longField = (Schema<?>) model.getProperties().get("long_field");
assertThat(longField).isNotNull();
assertThat(longField.getType()).isEqualTo("integer");
assertThat(longField.getFormat()).isEqualTo("int64");
assertThat(longField.getNullable()).isFalse();

final Schema<?> floatField = (Schema<?>) model.getProperties().get("float_field");
assertThat(floatField).isNotNull();
assertThat(floatField.getType()).isEqualTo("number");
assertThat(floatField.getFormat()).isEqualTo("float");
assertThat(floatField.getNullable()).isFalse();

final Schema<?> doubleField = (Schema<?>) model.getProperties().get("double_field");
assertThat(doubleField).isNotNull();
assertThat(doubleField.getType()).isEqualTo("number");
assertThat(doubleField.getFormat()).isEqualTo("double");
assertThat(doubleField.getNullable()).isFalse();

final Schema<?> shortField = (Schema<?>) model.getProperties().get("short_field");
Expand All @@ -180,7 +183,8 @@ private void assertBasicFieldNames(Schema<?> model) {

final Schema<?> byteField = (Schema<?>) model.getProperties().get("byte_field");
assertThat(byteField).isNotNull();
assertThat(byteField.getType()).isEqualTo("integer");
assertThat(byteField.getType()).isEqualTo("string");
assertThat(byteField.getFormat()).isEqualTo("byte");
assertThat(byteField.getNullable()).isFalse();

final Schema<?> listField = (Schema<?>) model.getProperties().get("list_field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"type" : "boolean"
},
"byte_field" : {
"type" : "integer",
"format" : "int32"
"type" : "string",
"format" : "byte"
},
"date_field" : {
"type" : "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"type" : "boolean"
},
"byte_field" : {
"type" : "integer",
"format" : "int32"
"type" : "string",
"format" : "byte"
},
"date_field" : {
"type" : "string",
Expand Down

0 comments on commit 1866a0a

Please sign in to comment.