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

Nullable response have a weird behavior right now #356

Open
timotheeguerin opened this issue Mar 23, 2022 · 5 comments
Open

Nullable response have a weird behavior right now #356

timotheeguerin opened this issue Mar 23, 2022 · 5 comments
Labels
design:needed A design request has been raised that needs a proposal
Milestone

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Mar 23, 2022

import "@typespec/http";

using TypeSpec.Http;

@error
model Error {
  message: string;
}

@route("/1") op read1(): string | null;
@route("/2") op read3(): string | null | Error;

Playground link

Resulting is a 204 no content before PR #355 which remove ignore null responses.

Feel like it should be making the string body nullable

@mikekistler
Copy link
Member

I agree with @timotheeguerin that a return type of string | null should result in a response schema:

    "schema": {
      "type": "string",
      "nullable": true
    }

@markcowl markcowl modified the milestones: [2022] May, [2022] July May 11, 2022
@markcowl markcowl modified the milestones: [2022] July, Backlog Jun 8, 2022
@timotheeguerin
Copy link
Member Author

  • null present in op return union means each response is nullable?

@nguerrera
Copy link
Contributor

nguerrera commented Oct 21, 2022

Asking for re-triaqge here. As soon as someone mentions the word "null" in a meeting, we go down a rabbit hole and it is harder to dig out of it when our own code doesn't actually interpret "null" as it should in some cases.

@timotheeguerin
Copy link
Member Author

Current state of this issue is we do produce the right(expected) responses but the body is not marked as nullable: true

@clhodapp
Copy link

clhodapp commented May 20, 2024

Currently, the OpenAPI emitter wraps trivial nullability in an unnecessary oneOf. That is to say, if you write a type of string | null, you'll get a nullable one-child oneOf, where the only child is string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design:needed A design request has been raised that needs a proposal
Projects
None yet
Development

No branches or pull requests

7 participants