Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add support for nullable<T> #5601

Merged
merged 8 commits into from
Jan 14, 2025
Merged

feat(cli): Add support for nullable<T> #5601

merged 8 commits into from
Jan 14, 2025

Conversation

amckinney
Copy link
Member

This adds support for a new Fern definition keyword, nullable. With this, users can explicitly specify whether or not a type is allowed to be serialized as null, which is valid for both required and optional properties.

With this, users can specify APIs like the following:

types:
  User:
    properties:
      name: string
      email: nullable<string>
      createdAt: optional<string>
      updatedAt: optional<string>

service:
  auth: false
  base-path: /
  endpoints:
    createUser:
      method: POST
      path: /users
      request:
        name: CreateUserRequest
        body:
          properties:
            name: string
            email: nullable<string>
      response: User

A few things to note:

  1. The nullable type is migrated to optional whenever the target generator doesn't support the latest IR.
  2. A follow-up will introduce an opt-in OpenAPI setting that converts nullable OpenAPI properties to nullable.
    • By default, these properties are converted to optional.
  3. In another follow-up the dynamic snippet generators will be updated to allow for explicit null values.

@amckinney amckinney requested a review from dsinghvi as a code owner January 14, 2025 00:23
Copy link

github-actions bot commented Jan 14, 2025

@amckinney amckinney merged commit 6970850 into main Jan 14, 2025
50 of 54 checks passed
@amckinney amckinney deleted the amckinney/nullable branch January 14, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants