Skip to content

AnyOf &schema.Reference{Path: ".."} is broken now #114

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

Closed
omani opened this issue Jul 12, 2017 · 9 comments
Closed

AnyOf &schema.Reference{Path: ".."} is broken now #114

omani opened this issue Jul 12, 2017 · 9 comments

Comments

@omani
Copy link
Contributor

omani commented Jul 12, 2017

Hi team,
something happened the last weeks. I've pulled the latest commits and something broke my AnyOf Paths. The code is the following:

var Login = schema.Schema{
	Fields: schema.Fields{
		"id": {
			Validator: &schema.AnyOf{
				&schema.Reference{
					Path: "users",
				},
				&schema.Reference{
					Path: "vents",
				},
			},
		},
		"type": {
			Validator: &schema.AnyOf{
				&schema.String{
					Allowed: []string{"user", "vent"},
				},
			},
			Required: true,
		},
		"password": {
			Validator: &schema.String{
				MinLen: 3,
				MaxLen: 32,
			},
		},
	},
}

"users" and "vents" is defined like always.
the error I get is the following:

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
Request-Id: b5j5opb047c06gn5pvjg
Vary: Origin
Date: Wed, 12 Jul 2017 17:29:09 GMT
Content-Length: 79

{
  "code": 422,
  "issues": {
    "id": [
      "invalid"
    ]
  },
  "message": "Document contains error(s)"
}

this worked for a long time before the latest pull. what happened? I see a commit mentioning schema.AnyOf treating as normal fields or something like that. but what happened here?

@smyrman
Copy link
Collaborator

smyrman commented Jul 13, 2017

Could be this one - 1e0b0e6

@smyrman
Copy link
Collaborator

smyrman commented Jul 13, 2017

However, probably more likely that it's related to - 5b33327.

@smyrman
Copy link
Collaborator

smyrman commented Jul 13, 2017

@omani, could you please share some details on which context you use this schema in. Do you use it with the rest and resources package, or do you rely only on the schema and resource package?

Does the Reference validators work when they are not inside an AnyOf? If not, what is the error?

AnyOf masks any original error, so to see which error is returned from just:

...
"id": {
    Validator: &schema.Reference{
         Path: "users",
    },
},
...

would be super useful. Thanks!

@smyrman
Copy link
Collaborator

smyrman commented Jul 13, 2017

As an FYI, if you use a resource.Index without passing it to rest.NewHandler(), you must manually call compile on it:

if cmp, ok := index.(resource.Compiler); ok {     // Used to be schema.Compiler!
    cmp.Compile()
}

This type-cast is necesarry until #109 is resolved.

@smyrman smyrman added the bug label Jul 13, 2017
@rs
Copy link
Owner

rs commented Jul 31, 2017

#115 might fix this.

@rs
Copy link
Owner

rs commented Aug 6, 2017

@omani is this still broken?

BTW, I never though about using anyof with a reference. I guess projections could not work with this kind of construct and you don't expect it to right?

@smyrman
Copy link
Collaborator

smyrman commented Aug 6, 2017

As a FYI, I never tried to reproduce it.

@smyrman
Copy link
Collaborator

smyrman commented Oct 17, 2017

Adding "help wanted" -- if someone have time to implement a demo-app to confirm this issue, or test if it's fixed, it would be helpful.

@smyrman
Copy link
Collaborator

smyrman commented Feb 28, 2018

Closing due to inactivity, please re-open if this issue is still valid.

@smyrman smyrman closed this as completed Feb 28, 2018
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