Arnab
12/11/2025, 10:15 AMdata class CustomerId(
val id: String = UUID.randomUUID().toString(),
)
How do I specify to the spec that this id is a string of type UUID? And maybe some description?Arnab
12/11/2025, 11:38 AMcontract {
routes += registerCustomerRoute()
renderer = OpenApi3(
ApiInfo("My API", "0.0.1"),
typeToMetadata = mapOf(
CustomerId::id.returnType to FieldMetadata(mapOf("format" to "uuid", "description" to "Customer identifier (UUID) from custom schema bla bla"))
)
)
this.descriptionPath = descriptionPath
}
But unfortunately this does not work:
"CustomerId": {
"properties": {
"id": {
"example": "5ba7358e-cf20-46d9-b8db-df9554e268b3",
"type": "string",
"nullable": false
}
},
"example": {
"id": "5ba7358e-cf20-46d9-b8db-df9554e268b3"
},
"type": "object",
"required": [
"id"
]
}
It seems it's not actually using these metadata types for anything?dave
12/11/2025, 11:45 AMdave
12/11/2025, 11:49 AMFieldMetadataRetrievalStrategy and inject it into the AutoJsonToJsonSchema instanceArnab
12/11/2025, 11:59 AMArnab
12/11/2025, 11:59 AMdave
12/11/2025, 11:59 AMArnab
12/11/2025, 12:00 PMmaskedPan in a CreditCard type:
CreditCard:
type: object
properties:
type:
type: string
enum:
- CREDIT_CARD
brand:
type: string
enum:
- VISA
- MASTERCARD
- AMEX
maskedPan:
type: string
description: Masked primary account number (e.g., "**** **** **** 1234")
example: "**** **** **** 1234"
pattern: "^\\*{4} \\*{4} \\*{4} \\d{4}$"Arnab
12/11/2025, 12:00 PMdave
12/11/2025, 12:01 PMArnab
12/11/2025, 12:30 PMcontract {
routes += registerCustomerRoute()
renderer = OpenApi3(
ApiInfo("My API", "0.0.1"),
typeToMetadata = mapOf(
CustomerId::id.returnType to FieldMetadata(mapOf("description" to "hello world"))
)
)
this.descriptionPath = descriptionPath
}
But that apparently isn't enough? I couldn't find any docs on this either and I can't find examples of usages of JacksonFieldMetadataRetrievalStrategy on github 😞Arnab
12/12/2025, 8:29 AMval myJsonSchemaCreator = AutoJsonToJsonSchema(
myJson,
FieldRetrieval.compose(
SimpleLookup(
metadataRetrievalStrategy =
JacksonFieldMetadataRetrievalStrategy
.then(PrimitivesFieldMetadataRetrievalStrategy)
.then(CreditCardFieldMetadataStrategy)
),
FieldRetrieval.compose(JacksonJsonPropertyAnnotated, JacksonJsonNamingAnnotated(myJson))
)
)
object CreditCardFieldMetadataStrategy : FieldMetadataRetrievalStrategy {
override fun invoke(target: Any, fieldName: String): FieldMetadata =
when (fieldName) {
"maskedPan" -> FieldMetadata(
"description" to "Masked primary account number (e.g., \"**** **** **** 1234\")",
"example" to "**** **** **** 1234",
"pattern" to "^\\*{4} \\*{4} \\*{4} \\d{4}$"
)
else -> FieldMetadata.empty
}
}
How do I plug this into my contract route?
contract {
routes += customerRoutes
renderer = OpenApi3(apiInfo = ApiInfo("my api", "0.0.1"))
this.descriptionPath = descriptionPath
}