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

Add Nullable Utility Function to Support OpenAPI nullable Property #205

Open
2 tasks done
casantosmu opened this issue Jan 6, 2025 · 0 comments
Open
2 tasks done

Comments

@casantosmu
Copy link

casantosmu commented Jan 6, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Export a utility function Nullable that generates OpenAPI-compatible schemas with the nullable property.

Example:

const Nullable = <T extends TSchema>(schema: T) => Type.Unsafe<Static<T> | null>({ 
  ...schema, 
  nullable: true 
});

const T = Nullable(Type.String());  
// Output:
// {
//   type: 'string',
//   nullable: true
// }

I am happy to implement this feature if the proposal is approved.

Motivation

Improve developer experience.

Example

// ....
response: {
  201: Type.Object({
      name: Nullable(Type.String()),
  }),
}
// ....

Outputs:

      responses:
        "201":
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  displayName:
                    type: string
                    nullable: true
                required:
                  - displayName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant