У меня активная запись так:Использования Сваггера с Scala-ActiveRecord
case class Person(name: String) extends ActiveRecord
object Person extends ActiveRecordCompanion[Person]
Я добавил чванство аннотаций:
@ApiModel(value = "Person", description = "A person.")
case class Person(
@ApiModelProperty(value = "A person's name")
name: String) extends ActiveRecord
object Person extends ActiveRecordCompanion[Person]
Сформированная схема содержит много барахла делает его непригодным:
"Person": {
"id": "Person",
"description": "A person.",
"properties": {
"name": {
"type": "string"
},
"valid": {
"type": "boolean"
},
"errors": {
"$ref": "Errors"
},
"id": {
"type": "integer",
"format": "int64"
},
"persisted": {
"type": "boolean"
},
"_companion": {
"$ref": "com.github.aselab.activerecord.inner.ProductModelCompanion<com.github.aselab.activerecord.inner.ProductModel>"
},
"_isNewRecord": {
"type": "boolean"
},
"newRecord": {
"type": "boolean"
},
"com$github$aselab$activerecord$ActiveRecordBase$$_isDeleted": {
"type": "boolean"
},
"recordCompanion": {
"$ref": "com.github.aselab.activerecord.ActiveRecordBaseCompanion<java.lang.Object, com.github.aselab.activerecord.ActiveRecordBase>"
},
"com$github$aselab$activerecord$validations$Validatable$$_validated": {
"type": "boolean"
},
"deleted": {
"type": "boolean"
}
}
}
Я искал исходный код swagger-core
. Существует ModelPropertyParser
с методом parseRecursive
, который содержит:
for (field <- hostClass.getDeclaredFields) {
if (Modifier.isPublic(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()) && !ignoredProperties.contains(field.getName) && !field.isSynthetic()) {
if (ignoredProperties.contains(field.getName)) {
LOGGER.debug("ignoring property " + field.getName)
} else {
parseField(field)
}
}
}
Option(hostClass.getSuperclass).map(parseRecursive(_))
Когда я бегу:
> classOf[Person].getDeclaredFields
Array[java.lang.reflect.Field] = Array(private final java.lang.String sk.essentialdata.ress.search.db.Person.name)
Это правильно, потому что я объявил только одно поле.
Когда я бегу:
classOf[Person].getSuperclass.getDeclaredFields
res6: Array[java.lang.reflect.Field] = Array(private final long com.github.aselab.activerecord.ActiveRecord.id, private boolean com.github.aselab.activerecord.ActiveRecord.com$github$aselab$activerecord$ActiveRecordBase$$_isDeleted, private final com.github.aselab.activerecord.ActiveRecordBaseCompanion com.github.aselab.activerecord.ActiveRecord.recordCompanion, private final com.github.aselab.activerecord.validations.Errors com.github.aselab.activerecord.ActiveRecord.errors, private boolean com.github.aselab.activerecord.ActiveRecord.com$github$aselab$activerecord$validations$Validatable$$_validated, private final com.github.aselab.activerecord.inner.ProductModelCompanion com.github.aselab.activerecord.ActiveRecord._companion, private boolean com.github.aselab.activerecord.ActiveRecord...
Существует много внутренних полей ActiveRecord. Есть ли способ избавиться от этого мусора? Мне нужно только включить поля из fieldInfo
в описании развязности:
> Person.fieldInfo
scala> res0: Map[String,com.github.aselab.activerecord.reflections.FieldInfo] = Map(name -> FieldInfo(name,class java.lang.String,false,false,WrappedArray()), id -> FieldInfo(id,long,false,false,WrappedArray()))