ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
137 stars 85 forks source link

JS Client session identity is generated as optional even though it's marked as required in the spec #293

Open dnlsndr opened 10 months ago

dnlsndr commented 10 months ago

Preflight checklist

Ory Network Project

No response

Describe the bug

As far as I understood, every session always has a identity in it's response. This is also the case in the openapi spec under the session, where identity and id are set to be required fields. But apparently the javascript/typescript client does not generate it as such, and generates it as a optional field in the Session type. This causes issues in our project down the road, because we would either have to do unnecessary checks all over the place just to satisfy TypeScript in that reagard, or overwrite your internal Session type such that the identity is not optional.

Reproducing the bug

Create a typescript project,

  1. Call toSession({...}) on a FrontendApi client instance.
  2. Try accessing the session.identity.id attribute, which fails
  3. Note that typescript is telling you that the "identity might be undefined"

Relevant log output

'session.identity' is possibly 'undefined'.ts(18048)
(property) Session['identity']?: Identity | undefined

@type — {Identity}
@memberof — Session

Relevant configuration

No response

Version

Kratos 1.0.0 and the latest npm client

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Docker

Additional Context

No response