question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contract is not truly type safe

See original GitHub issue

Hello, I wanted to leverage the ‘type safe’ contract http4k claims to provide to ensure (at compile time) that a handler for given route/method responds with correct response type. However, from the available documentation I was not able to figure out how to do that or whether that’s even possible.

Consider following example

data class City(
        val id: Long,
        val name: String,
)

fun getCity(): ContractRoute {
    val openApiSpec = "city/v1/get" meta {
        // type of the response is defined here to be City
        returning(Status.OK, Body.auto<City>().toLens() to City(id = 123, name = "Prague"))
    } bindContract Method.GET

    return openApiSpec to {
        // this is expected to fail at compile type because it does not conform to the spec above
        Response(Status.OK, "booya!")
    }
}

Can the expectation be fulfilled? If so, how?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daviddentoncommented, Apr 17, 2020

Yep - we’re aware of this and you are of course correct. There is a fine balance between making the API comprehensible (and avoiding magic), which is obviously a little out of whack here.

… that said - there is a bit of a side project that we’ve been playing with to come up with a completely typesafe routing module which can be bound to create both server and client bindings. It’s early days, but we’re quite hopeful it might be something that has legs… 😃

0reactions
daviddentoncommented, Aug 1, 2022

There is no news on this feature request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unenforceable Contracts: What to Watch Out For | Nolo
Contracts can be found unenforceable on grounds of public policy not only to protect one of the parties involved, but also because what...
Read more >
SAFE Agreement: How They Work, 5 Important Terms (2022)
SAFE agreements are legal contracts that startups use to raise seed financing ... The type of instrument you choose depends upon the startup...
Read more >
Type safety - Wikipedia
Type safety in object oriented languages​​ A class essentially defines the structure of the objects derived from it and an API as a...
Read more >
Runtime typesafety in typescript - angular - Stack Overflow
Back to the question about safety, yes TypeScript ensure safety during writing the code. You define the contract, write transformations of ...
Read more >
Advanced Topic - Agile Contracts - Scaled Agile Framework
The 'SAFe managed-investment contract' represents one such approach, as described below.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found