ory / ory/sdk

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

Open
#293 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
178
Forks
96
Avg merge
6d 23h
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the OpenAPI session definition, where identity and id are required, with the generated Session type used by FrontendApi.toSession. Trace the client generation input and output to find where identity becomes optional. Done means the generated TypeScript type reflects the required spec and session.identity.id no longer produces the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.