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

Value error with nested type on interface{} #3

Closed
chrisk-petsure opened this issue Jun 27, 2024 · 2 comments
Closed

Value error with nested type on interface{} #3

chrisk-petsure opened this issue Jun 27, 2024 · 2 comments

Comments

@chrisk-petsure
Copy link

I'm getting a validation error when using a map[string]interface{} as the value.

Here's the example:

Json Schema

{
  "$id": "https://example.com/blog-post.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "A representation of a blog post",
  "type": "object",
  "required": ["title", "content", "author"],
  "properties": {
    "title": {
      "type": "string"
    },
    "content": {
      "type": "string"
    },
    "publishedDate": {
      "type": "string",
      "format": "date-time"
    },
    "author": {
      "$ref": "https://example.com/user-profile.schema.json"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}

The data

data := map[string]interface{}{
  "title":         "New Blog Post",
  "content":       "This is the content of the blog post...",
  "publishedDate": "2023-08-25T15:00:00Z",
  "author": map[string]interface{}{
	  "username": "authoruser",
	  "email":    "[email protected]",
  },
  "tags": []string{"Technology", "Programming"},
}

Error:
"/tags"
"Value is unknown but should be array"

@andreafalzetti
Copy link

andreafalzetti commented Nov 13, 2024

I am getting the same error, because my type is map[interface {}]interface {}.

Update: Using go-yaml/yaml#139 I was able to get my same YAML to be type map[string]interface{} but the library fails to work because it gives no errors in ToList, however I get from .Error() -> evaluation failed. :(

@GuoChengH
Copy link
Contributor

I am getting the same error, because my type is map[interface {}]interface {}.

Update: Using go-yaml/yaml#139 I was able to get my same YAML to be type map[string]interface{} but the library fails to work because it gives no errors in ToList, however I get from .Error() -> evaluation failed. :(

I'm sorry to see this message just now, can you submit the wrong code completely? There is no problem after my test. If yaml is parsed into map[interface{}]interface{}, his error is "type": "Value is unknown but should be object"

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

4 participants