It seems like `http4k-contract` generates `descrip...
# http4k
m
It seems like
http4k-contract
generates
description
fields with
null
value if you leave out description. I think this is not according to the spec, the
description
field should be left out if there is no value for it.
a
This shouldn't happen if you're using the provided
OpenApiJackson
, which excludes
null
values from generated json. How are you defining your
ContractRenderer
? The minimal version should look like this:
Copy code
contract {
  renderer = OpenApi3(
    ApiInfo("My Service", "v1.0")
  )

  routes += TODO()
}
m
Copy code
contract {
    renderer = OpenApi3(
        ApiInfo("Nice service", "1.0"),
        org.http4k.format.Gson
    )

    routes += TODO()
}
I tried with
org.http4k.format.Jackson
, but then I get:
Copy code
java.lang.IllegalArgumentException: Don't know how to translate "pYG4MIG1pWswaaEiBCADmKHnsPh3Ca/RTNGCHqqvtBkxqAl/+i2D5f4Q2n5N1aUaMBilFjAUog4MDG15X29wZXJhdGlvbqUCMAClJzAloSMEIQMr8Pz4Oih/texx5NrqXeiSgEpbu+1hMNvN24cQFcNOoKVGMEShQgRAS0JXeb+L1e1QODcze74QK3AT95HzvPuBJybqk+B2oyZ2Vux3OqEGF+Gr2yXperHPKZLNs+BZ1mjJC9pruR/oNg=="
	at org.http4k.format.ConfigurableJackson.typeOf(ConfigurableJackson.kt:52)
	at org.http4k.format.ConfigurableJackson.typeOf(ConfigurableJackson.kt:37)
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.makePropertySchemaFor(AutoJsonToJsonSchema.kt:184)
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toObjectSchema(AutoJsonToJsonSchema.kt:123)
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toObjectOrMapSchema(AutoJsonToJsonSchema.kt:110)
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toSchema(AutoJsonToJsonSchema.kt:45)
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toSchema(AutoJsonToJsonSchema.kt:29)
	at org.http4k.contract.openapi.ApiRenderer$Companion$Auto$fallbackSchema$1.toSchema(ApiRenderer.kt:30)
	at org.http4k.contract.openapi.ApiRenderer$Companion$Auto$1.toSchema(ApiRenderer.kt)
	at org.http4k.contract.openapi.v3.OpenApi3.toSchemaContent(OpenApi3.kt:288)
	at org.http4k.contract.openapi.v3.OpenApi3.requestBody(OpenApi3.kt:261)
	at org.http4k.contract.openapi.v3.OpenApi3.apiPath(OpenApi3.kt:141)
	at org.http4k.contract.openapi.v3.OpenApi3.apiPath(OpenApi3.kt:126)
	at org.http4k.contract.openapi.v3.OpenApi3.asPath(OpenApi3.kt:123)
	at org.http4k.contract.openapi.v3.OpenApi3.description(OpenApi3.kt:88)
	at org.http4k.contract.ContractRoutingHttpHandler$descriptionRoute$2$1.invoke(ContractRoutingHttpHandler.kt:79)
	at org.http4k.contract.ContractRoutingHttpHandler$descriptionRoute$2$1.invoke(ContractRoutingHttpHandler.kt:78)
	at org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:54)
	at org.http4k.routing.RouterMatch$MatchingHandler.invoke(Router.kt:53)
That seems to be due to I used a class which Jackson couldn't serialize. I fixed that, but still get:
Copy code
"info": {
    "title": "Test API",
    "version": "1.0",
    "description": null
  },
a
Gson
is known to not be supported by the auto renderer; in fact only
Jackson
and
OpenApiJackson
are supported. Now that you've fixed the Jackson incompatibility, you can switch from
Jackson
to
OpenApiJackson
, and the nulls won't be rendered. In fact, the only difference between the two is that one doesn't render nulls.