Skip to content

[BUG][SWIFT6] generator doesn't respect x-nullable swagger 2.0 property for $ref attributes #21201

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

Open
4 of 6 tasks
bogdan opened this issue May 2, 2025 · 5 comments
Open
4 of 6 tasks

Comments

@bogdan
Copy link

bogdan commented May 2, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

x-nullable is ignored when $ref is used on an object property by swift6 generator

openapi-generator version
$ yarn openapi-generator-cli version
7.13.0
OpenAPI declaration file content or url

https://gist.github.com/bogdan/f5fbf0f5940d5540b60ca086beef3fea

Steps to reproduce
openapi-generator-cli generate -i spec.json -g swift6 -o .

Open Source/API/Models/Item.swift.

Actual:

    public var activeListing: Listing

Expected:

    public var activeListing: Listing?

Note that it is only reproducable when x-nullable and $ref are used together:

{
        "active_listing": {
          "x-nullable": true,
          "$ref": "#/definitions/Listing"
        }
}
@4brunu
Copy link
Contributor

4brunu commented May 12, 2025

Hi @bogdan, do you know if this bug is also present in the Swift 5 generator? Thanks

@bogdan
Copy link
Author

bogdan commented May 13, 2025

Just checked swift5 - no, it is not reproduced.

@4brunu
Copy link
Contributor

4brunu commented May 13, 2025

Interesting, I was not expecting this, I was expecting for this bug to be present in the swift 5 generator also. If you want to create a PR with the fix, I can help with the review and merge, otherwise, I will try to look at this when I have some, but I'm not sure when

@wing328
Copy link
Member

wing328 commented May 15, 2025

@bogdan
Copy link
Author

bogdan commented May 15, 2025

The solution I found is to not include nullable property in required attributes, like so:

    "TokenWithListingEntity": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int32"
        },
        "token": {
          "$ref": "#/definitions/TokenEntity"
        },
        "active_listing": {
          "$ref": "#/definitions/ListingEntity",
          "x-nullable": true
        }
      },
      "required": [
        "id",
        "token"
      ]
    },

It is a little bad semantics as not required suppose to be the one that can be absent in schema completelly (honestly, I hate APIs that work this way), but null and undefined are treated absolutelly the same by generator, so I can use it now because I don't care about non-generator usages of my spec yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants