https://kotlinlang.org logo
Title
m

Mikael Ståldal

05/24/2023, 9:23 AM
Is it possible to generate OpenAPI schema for path parameters? I can get the validation with
Path.regex("([0-9a-fA-F])")
now, but the generated schema is just:
{
            "schema": {
              "type": "string"
            },
            "in": "path",
            "name": "hexParam",
            "required": true,
            "description": "Hexadecimal value"
          },
I would like:
{
            "schema": {
              "type": "string",
              "pattern": "[0-9a-fA-F]"
            },
            "in": "path",
            "name": "hexParam",
            "required": true,
            "description": "Hexadecimal value"
          },
d

dave

05/24/2023, 9:33 AM
unfortunately all Path parameters are created without the pattern metadata. you can mapWithNewMeta to change the type though
(it's a limitation of the model used)
m

Mikael Ståldal

05/24/2023, 9:51 AM
Any plans to fix this?
d

dave

05/24/2023, 9:52 AM
"fix". no
it would require a significant rewrite of the existing system. So also no.
🙂
There are several limitations of the system in http4k, but they are categorically not bugs. They are limitations. 😉
m

Mikael Ståldal

05/24/2023, 12:22 PM
OK, fair enough.
But then it seems like
http4k-contract
is not sufficient for my OpenAPI generation needs.
Is advisable to use http4k-contract even if you don't make use of the generated OpenAPI docs, or would you be better of with using routes in that case?
d

dave

05/24/2023, 12:30 PM
Well there are nice tooling things you can do with the contracts, but if you really aren't going to use them then the standard routing is an excellent option tbh
m

Mikael Ståldal

05/24/2023, 12:32 PM
I don't have need for standard authentication, callbacks or webhooks either.
So I'll try standard routing instead.
a

Andrew O'Hara

05/24/2023, 1:57 PM
Even if I'm not using the OpenApi generator, it's still nice because: • you get the path parameter values injected into your server handlers • you can reuse the
ContractRouteSpecX.Binder
for your clients and fakes • Even if you don't expose the spec publicly, it's still incredibly useful for documenting internal APIs