Skip to content

Conversation

@hactar
Copy link
Contributor

@hactar hactar commented Oct 20, 2025

An object passed to swift-mustache may contain something of the type: [String: Any?], which is good, as this is what libraries such as swift-openapi-generator return for things like their "additionalProperties" property, which contains a "catch all" of properties that are available, but were not actually specified in the openapi schema file.

swift-mustache accepts these objects, but doesn't handle them well: swift-mustache needs to unwrap the optionals before passing them to String(describing: ) so that String(describing: ) doesn't output "Optional("foobar") - and this it does already correctly. But when you unwrap an Any?, you get anAny - in swift, an Any can still contain a wrapped optional. So if you take this code

    func testTypeErasedOptionalContext() throws {
        let object = ["name" : "Test" as Any?]

        let template = try MustacheTemplate(string: "{{name}}")
        let result = template.render(object)

        XCTAssertEqual(result, "Test")
    }

Then the test will fail, because String(describing: ) will return Optional("Test") and not Test, because what is describing is still a wrapped value, and not the actual value itself.

Screenshot 2025-10-20 at 15 08 27

This PR addresses the problem by checking if a value is still wrapped and unwrapping it before passing it to String( describing: ) and adds a test for this isue.

Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine
Thanks for this

@adam-fowler
Copy link
Member

You need to run swift format on your code

@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.90%. Comparing base (999fda1) to head (204b0c2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
+ Coverage   89.86%   89.90%   +0.03%     
==========================================
  Files          18       19       +1     
  Lines        1382     1387       +5     
==========================================
+ Hits         1242     1247       +5     
  Misses        140      140              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hactar
Copy link
Contributor Author

hactar commented Oct 21, 2025

swift format modified code that I didn't change - so I changed those parts back for clarity - I can rerun it full if you want - I'm assuming the swift format version got bumped and now wants "return" removed in certain cases...

@adam-fowler
Copy link
Member

swift format modified code that I didn't change - so I changed those parts back for clarity - I can rerun it full if you want - I'm assuming the swift format version got bumped and now wants "return" removed in certain cases...

oh ok. Something must have got merged without the formatting done. Are you happy adding those changes back in even if they are unrelated

@hactar
Copy link
Contributor Author

hactar commented Oct 21, 2025

Done - see: 204b0c2

@hactar hactar requested a review from adam-fowler October 21, 2025 18:54
@adam-fowler adam-fowler merged commit 2e2a846 into hummingbird-project:main Oct 22, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

2 participants