Is it possible to somehow test the OpenAPI /docs e...
# http4k
v
Is it possible to somehow test the OpenAPI /docs endpoint? It happens to me that I get:
Copy code
org.http4k.contract.openapi.v3.NoFieldFound: Could not find XXX in YYY
	at org.http4k.contract.openapi.v3.FieldRetrieval$Companion$compose$1.invoke(FieldRetrieval.kt:17) ~[http4k-contract-3.249.0.jar:?]
	at org.http4k.contract.openapi.v3.FieldRetrieval$Companion$compose$1.invoke(FieldRetrieval.kt:9) ~[http4k-contract-3.249.0.jar:?]
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toObjectSchema(AutoJsonToJsonSchema.kt:64) ~[http4k-contract-3.249.0.jar:?]
	at org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toObjectOrMapSchema(AutoJsonToJsonSchema.kt:60) ~[http4k-contract-3.249.0.jar:?]
Getting this in runtime is a bit too late 🙂
s
@Vojtěch Knyttl our general approach is to have an approval test for the swagger endpoint
v
isn't that too complex to just test it doesn't fail? I am not sure, maybe I am understanding it wronly
s
That kind of test has three benefits: 1. It shows the endpoint works 2. It gives the opportunity to check that any future changes make sense 3. It’s low maintenance as it doesn’t require you to write tons of assertions If you already do any in-memory functional test, you should already have everything you need to test that endpoint. The approval approach is just a cheap way to get it checked.
v
Would you have some Swagger Approval test example?
d
here's an example of an approval test: https://www.http4k.org/guide/modules/approvaltests/
you can just call the swagger endpoint on your application and then check the result using the junit plugin