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

Model validation incorrectly fails on responses with null fields #198

Closed
jhendrixMSFT opened this issue Jan 25, 2018 · 3 comments
Closed

Comments

@jhendrixMSFT
Copy link
Member

Regarding PR Azure/azure-rest-api-specs#2094.

{ code: 'RESPONSE_VALIDATION_ERROR',
  id: 'OAV108',
  message: 'Found errors in validating the response with statusCode "200" for x-ms-example "GetManagementGroup" in operation "ManagementGroups_Get".',
  innerErrors: 
   [ { code: 'INVALID_RESPONSE_BODY',
       errors: 
        [ { code: 'ONE_OF_MISSING',
            params: [],
            message: 'Data does not match any schemas from \'oneOf\'',
            path: [ 'properties' ],
            inner: 
             [ { code: 'ONE_OF_MISSING',
                 params: [],
                 message: 'Data does not match any schemas from \'oneOf\'',
                 path: [ 'properties', 'details' ],
                 inner: 
                  [ { code: 'ONE_OF_MULTIPLE',
                      params: [],
                      message: 'Data is valid against more than one schema from \'oneOf\'',
                      path: [ 'details', 'parent' ] },
                    { code: 'INVALID_TYPE',
                      params: [ 'null', 'object' ],
                      message: 'Expected type null but found type object',
                      path: [ 'details' ] } ] },
               { code: 'INVALID_TYPE',
                 params: [ 'null', 'object' ],
                 message: 'Expected type null but found type object',
                 path: [ 'properties' ] } ] } ],
       message: 'Invalid body: Data does not match any schemas from \'oneOf\'',
       path: [] } ] }

Here's the response.

    "responses": {
        "200": {
            "body": {
                "id": "/providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000001",
                "type": "/providers/Microsoft.Management/managementGroups",
                "name": "00000000-0000-0000-0000-000000000001",
                "properties": {
                    "tenantId": "00000000-0000-0000-0000-000000000000",
                    "displayName": "Group Name 1",
                    "details": {
                        "version": 1,
                        "updatedTime": "2017-01-01T00:00:00.00Z",
                        "updatedBy": "Test",
                        "parent": null
                    }
                }
            }
        }
    }

Note the null parent field. How should this be modeled?
Seems related to #155

@amarzavery
Copy link
Contributor

I was looking at this issue last night. This is a slightly complex problem to solve. Have sort of figured out the problematic part which has raised doubts in my mind about "oneOf". I need to improve my understanding of "oneOf" in json schema. Will have to talk to folks in the team and then come to a conclusion.

I would say please do not block on merging the PRs in the azure-rest-api-specs repo. We should definitely fix this issue in the upcoming sprint with more tests that have complicated scenarios.
/cc @salameer

@mcardosos
Copy link
Contributor

Closing issue here as it is a linter issue, not model validator.

@amarzavery
Copy link
Contributor

This StackOverflow link provides good explanation about requiredness type in a json document.

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

3 participants