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

Schema validation fails for declarations omitting "template" since v3.20 #317

Closed
simonkowallik opened this issue Aug 5, 2020 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@simonkowallik
Copy link

Environment

  • Application Services Version: 3.20 & 3.21
  • BIG-IP Version: N/A

Summary

Since AS3.20 the template property is optional and defaults to generic.
This seems to break JSON Schema validation for multiple validation implementations.

Details

The template property in the AS3 Schema references a default of generic:

"template": {
"title": "Template Name",
"description": "Each application type has certain required and default elements and selects appropriate setup of various ADC/Security features",
"type": "string",
"default": "generic"
},

When a JSON Schema (draft7) validator tries to validate a declaration like the "quick start" declaration from the 3.21 docs, it seems to ignore the default and assume that the template property is either empty or unspecified.

This leads to a validation error as the tested JSON Schema validators due to the allOf keyword trying to apply if conditions based on the value of the template property (which either seems to not exist or is empty).

The validation failure for the different implementations differ.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Save "quick start" declaration from the 3.21 docs to $PWD/quick_start.json:

  2. Run https://github.com/simonkowallik/as3ninja (from docker for example):

docker run -it --rm \
  -v $PWD/quick_start.json:/as3.json \
  simonkowallik/as3ninja:latest \
  as3ninja validate -d /as3.json -v 3.21.0
  1. Observe Python exception/validation error:
as3ninja.exceptions.AS3ValidationError: AS3 Validation Error: 'serviceMain' is a required property

Failed validating 'required' in schema['properties']['declaration']['additionalProperties']['additionalProperties']['allOf'][0]['if']['then']:
    {'description': 'Declares an HTTPS application',
     'properties': {'serviceMain': {'$ref': '#/definitions/Service_HTTPS'}},
     'required': ['serviceMain'],
     'title': 'HTTPS application',
     'type': 'object'}

On instance['declaration']['Sample_01']['A1']:
    {'class': 'Application',
     'service': {'class': 'Service_HTTP',
                 'pool': 'web_pool',
                 'virtualAddresses': ['10.0.1.10']},
     'web_pool': {'class': 'Pool',
                  'members': [{'serverAddresses': ['192.0.1.10',
                                                   '192.0.1.11'],
                               'servicePort': 80}],
                  'monitors': ['http']}}

In this repro the python jsonschema library uses the first Schema $ref (Template_https) to validate the application A1, which fails due to the requirement of serviceMain.

https://www.jsonschemavalidator.net/ fails as well, as does ajv (tested with as3_schema_validator)

Expected Behavior

Schema validation does not fail.

Possible solution

I couldn't find what the expected behavior of a if condition against a non-existing property should be in the JSON Schema spec.

But specifically testing if "template": "generic" does NOT exist seems to work:

      "if": { "not": { "properties": { "template": { "const": "generic" } } } },
      "then": {
        "allOf": [ .. ]
      },
      "else": {
        "$ref": "#/definitions/Template_generic"
      },

replacing "allOf": [ .. ] with the existing definition (and probably remove the if/then for generic):

@simonkowallik simonkowallik added bug Something isn't working untriaged Issue needs to be reviewed for validity labels Aug 5, 2020
@dstokesf5
Copy link
Contributor

Added to the internal product backlog as AUTOTOOL-1776.

@dstokesf5 dstokesf5 removed the untriaged Issue needs to be reviewed for validity label Aug 6, 2020
@simonkowallik
Copy link
Author

This also applies to Schema version 3.22, another example for a schema validation failure from VS Code:

image

@dstokesf5
Copy link
Contributor

That is strange. The fix should have been available in 3.22.0.

Is it possible that VS Code has the old schema still cached? You could confirm that you are using the latest schema by trying to set the schemaVersion property to "3.22.0".

@simonkowallik
Copy link
Author

@dstokesf5 setting the schemaVersion to 3.22.0 did not resolve the problem. Validation also fails with the other Schema validation implementations previously listed.

@dstokesf5
Copy link
Contributor

Sorry for being unclear. I was not expecting changing the schemaVersion to fix the problem, I was suggesting it as a diagnostic step. If VS Code gave an error for a value of "3.22.0", then that would suggest that it is using an outdated schema. It sounds like that is not the case.

Marking as "untriaged" to take another look at this issue.

@dstokesf5
Copy link
Contributor

it appears we had an issue with the 3.22.0 release, and a couple of bug fixes (including this one), are missing from the release. We are working to resolve this issue, and should have an update early next week.

@dstokesf5 dstokesf5 added this to the v3.22.1 milestone Sep 14, 2020
@dstokesf5
Copy link
Contributor

This issue should be resolved in the 3.22.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants