Skip to content

Commit

Permalink
support strict discriminator properties
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed Feb 20, 2025
1 parent b2f82ea commit 7ea8b0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.smiley4.schemakenerator.core.data.TypeData
import io.github.smiley4.schemakenerator.core.data.TypeId
import io.github.smiley4.schemakenerator.core.data.find
import io.github.smiley4.schemakenerator.swagger.SwaggerSchemaUtils
import io.github.smiley4.schemakenerator.swagger.data.SwaggerSchema
import io.swagger.v3.oas.models.media.Schema
import java.math.BigDecimal

Expand All @@ -17,6 +18,7 @@ class DefaultSwaggerSchemaGenerationModule(
private val nullableAsNonRequired: Boolean,
private val allowSpecialFloatingPointValues: Boolean,
private val mapsWithStructuredKeysAsArrays: Boolean,
private val strictDiscriminatorProperty: Boolean,
) : SwaggerSchemaGenerationModule {

private val schema = SwaggerSchemaUtils()
Expand Down Expand Up @@ -181,6 +183,11 @@ class DefaultSwaggerSchemaGenerationModule(
if (member.nullable) {
it.nullable = member.nullable
}
if (strictDiscriminatorProperty) {
if (member.annotations.any { annotation -> annotation.name == AbstractAddDiscriminatorStep.MARKER_ANNOTATION_NAME }) {
(it as Schema<Any>).enum = listOf(context.typeData.descriptiveName.full)
}
}
}
val nullable = member.nullable && nullableAsNonRequired
val optional = member.optional && optionalAsNonRequired
Expand Down
Empty file.

0 comments on commit 7ea8b0f

Please sign in to comment.