Skip to content

OpenAPIObjectContainer API weirdness, init validates value but then allows me to set anything into .value #782

Open
@weissi

Description

@weissi

Description

OpenAPIObjectContainer's API has a bug:

public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
// public
    public var value: [String: (any Sendable)?]
    public init() { self.init(validatedValue: [:]) }
    public init(unvalidatedValue: [String: (any Sendable)?]) throws {
        try self.init(validatedValue: Self.tryCast(unvalidatedValue))
    }

// internals
    init(validatedValue value: [String: (any Sendable)?]) { self.value = value }

Basically the public inits force me to go through validation (and throw) but the setter for self.value accepts anything. So I can write

struct BadGuy: Sendable {}

var c = OpenAPIObjectContainer()
c.value["bad"] = BadGuy()

which now gives me a "validated" OpenAPIObjectContainer without validation.

Reproduction

see above

Package version(s)

runtime 1.8.0

Expected behavior

won't let me set bad stuff

Environment

6.2

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/runtimeAffects: the runtime library.kind/bugFeature doesn't work as expected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions