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

Support deserializing null value in enum array for nullable multi-types #135

Open
vegardgs-ksat opened this issue Nov 26, 2024 · 0 comments

Comments

@vegardgs-ksat
Copy link

According to the referenced JSON Schema Validation for OAS3.1, the enum property can be of any valid type (presumably matching the multi-valued type fields, including null.

This was observed in the wild when attempting to parse GitHub OpenAPI 3.1 specification, which includes schemas with multi-type, where one type is null.

This can be demonstrated with the following:

use oas3::spec::ObjectSchema;

fn main() {
    let json = serde_json::json!({
        "type": ["string", "null"],
        "enum": ["one", null]
    });

    let object: ObjectSchema = serde_json::from_value(json).unwrap();
}

produces

called `Result::unwrap()` on an `Err` value: Error("invalid type: null, expected a string", line: 0, column: 0)`

The same is true when done through the ObjectOrReference<ObjectSchema>, but with a more diffuse error message:

use oas3::spec::{ObjectOrReference, ObjectSchema};

fn main() {
    let json = serde_json::json!({
        "type": ["string", "null"],
        "enum": ["one", null]
    });

    let reference: ObjectOrReference<ObjectSchema> = serde_json::from_value(json).unwrap();
}

produces

called `Result::unwrap()` on an `Err` value: Error("data did not match any variant of untagged enum ObjectOrReference", line: 0, column: 0)
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

No branches or pull requests

1 participant