https://kotlinlang.org logo
#http4k
Title
# http4k
v

Vojtěch Knyttl

11/08/2020, 8:38 PM
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

s4nchez

11/08/2020, 8:40 PM
@Vojtěch Knyttl our general approach is to have an approval test for the swagger endpoint
v

Vojtěch Knyttl

11/08/2020, 8:43 PM
isn't that too complex to just test it doesn't fail? I am not sure, maybe I am understanding it wronly
s

s4nchez

11/08/2020, 9:34 PM
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

Vojtěch Knyttl

11/09/2020, 2:21 PM
Would you have some Swagger Approval test example?
d

dave

11/09/2020, 2:30 PM
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
3 Views