You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When a data class that has a val not included in its constructor is referenced in documentation it causes an exception on startup:
io.bkbn.kompendium.json.schema.exception.UnknownSchemaException: An unknown type was encountered: class com.example.SomeClass.
This typically indicates that a complex scalar such as dates,
timestamps, or custom number representations such as BigInteger were not added as custom types when
configuring the NotarizedApplication plugin. If you are still seeing this error despite adding all
required custom types, this indicates a bug in Kompendium, please open an issue on GitHub.
at io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler$handle$required$3.invoke(SimpleObjectHandler.kt:75)
at io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler$handle$required$3.invoke(SimpleObjectHandler.kt:70)
at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:171)
at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
at kotlin.sequences.TransformingSequence$iterator$1.hasNext(Sequences.kt:214)
at kotlin.sequences.SequencesKt___SequencesKt.toSet(_Sequences.kt:849)
at io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler.handle(SimpleObjectHandler.kt:85)
This is because SimpleObjectHandler attempts to find the attribute in the constructor and - failing to do so - throws an exception.
To Reproduce
Steps to reproduce the behavior:
Example data class:
data class SomeVO(
val id: String,
val name: String,
val category: String,
) {
val slug: String = id.toSlug()
}
The point of this approach is that this attribute should always have the exact same value depending on the id, so it should not be possible to send it to the constructor.
Expected behavior
The most reasonable behaviour would be to mark this attribute as required, because this only ever makes sense for return values, and the attribute will always have a value.
Additional context
There are obviously workarounds for this. One possible solution is to include the attribute in the constructor, with a default value:
data class SomeVO(
val id: String,
val name: String,
val category: String,
val slug: String = id.toSlug()
)
While this works, it is misleading because it indicates that any slug can be supplied to this class. It will also make the attribute optional in the schema, which is not the intention.
The text was updated successfully, but these errors were encountered:
Yea... finding a good middle ground here is very tough... because for many classes, people will not want a variable exposed as part of the documentation.
I believe by default kotlinx serialization will omit vals that are not part of the constructor... but i'm not sure about that
I'm definitely up for attempts to implement a better solution here, but to be quite honest, Kompendium is very low priority for me personally, so will likely have to be a community member that takes charge here.
Describe the bug
When a data class that has a
val
not included in its constructor is referenced in documentation it causes an exception on startup:This is because
SimpleObjectHandler
attempts to find the attribute in the constructor and - failing to do so - throws an exception.To Reproduce
Steps to reproduce the behavior:
Example data class:
The point of this approach is that this attribute should always have the exact same value depending on the id, so it should not be possible to send it to the constructor.
Expected behavior
The most reasonable behaviour would be to mark this attribute as required, because this only ever makes sense for return values, and the attribute will always have a value.
Additional context
There are obviously workarounds for this. One possible solution is to include the attribute in the constructor, with a default value:
While this works, it is misleading because it indicates that any slug can be supplied to this class. It will also make the attribute optional in the schema, which is not the intention.
The text was updated successfully, but these errors were encountered: