-
Notifications
You must be signed in to change notification settings - Fork 16
BUG: nullable schema #91
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
Comments
It does not matter whether it is a Type Alias or an interface. I believe the essence of the issue is whether the problem is solved or not. By the way, do you mean that there is a problem with specifying |
When defined in openapi: 3.0.3
info:
version: 1.0.0
components:
schemas:
Author:
type: object
nullable: true # Not works
properties:
name:
type: string
NullableAuthor:
oneOf:
- $ref: "#/components/schemas/Author"
- type: "null"
responses:
Books:
description: Get Books
content:
application/json:
schema:
type: object
nullable: true # This works
properties:
author:
type: object
nullable: true # This works
properties:
name:
type: string
authorRef:
$ref: "#/components/schemas/Author"
author2:
oneOf:
- $ref: "#/components/schemas/Author"
- type: "null"
nullableAuthorRef:
$ref: "#/components/schemas/NullableAuthor"
paths:
/get/books:
get:
operationId: getBooks
responses:
200:
$ref: "#/components/responses/Books"
You can check the operation in Playground (https://openapi-typescript-code-generator.netlify.app/v0.19.1/index.html). |
And this is not what we talk about in the topic of Type Alias or Interface. What you really want to do with the issue is to put it in the title. Otherwise, I will close this issue. |
I think so too. I'm using OpenAPITools/openapi-generator to generate types and client. And I am considering where to migrate to. I have schemas like follows: components:
schemas:
member:
type: object
additionalProperties: false
required:
- child
properties:
child:
$ref: "#/components/schemas/child"
child:
type: object
nullable: true
additionalProperties: false
required:
- name
properties:
name:
type: string This generator generates like follows: export interface member {
child: Schemas.child;
}
export interface child {
name: string;
} I think it is not correct. export type member = {
child: Schemas.child;
};
export type child = {
name: string;
} | null; This is why I asked the previous question.
OK. I'll change title. |
Maybe no. |
I published v0.19.2. Thanks your bug report ! And, I could align everything to type alias, but that would be a disruptive change to existing users and I need to provide options to minimize that. However, I do not have the time to provide that option, so I will only release a patch to allow nullable. |
Uh oh!
There was an error while loading. Please reload this page.
Hi! I think this project is useful and so interesting.
I have a question. Why do generator use interface for schema definition?
I think type alias is more useful.
e.g.
https://swagger.io/specification/#:~:text=A%20true%20value%20adds%20%22null%22%20to%20the%20allowed%20type%20specified%20by%20the%20type%20keyword%2C%20only%20if%20type%20is%20explicitly%20defined%20within%20the%20same%20Schema%20Object.
The text was updated successfully, but these errors were encountered: