openapi-enforcer icon indicating copy to clipboard operation
openapi-enforcer copied to clipboard

Ignore "Property not allowed"

Open AndrewChurchill opened this issue 2 years ago • 7 comments

Hello, is there a way to ignore "Property not found" errors during document validation? For example:

const [openapi, error, warning] = await Enforcer(path, {
    fullResult: true,
    componentOptions: {
        exceptionSkipCodes: [
            // Don't warn for non-standard format types
            'WSCH001',

            // Don't check "example" properties
            'WSCH006',
        ],
    },
});

When called, the error will be:

One or more errors exist in the OpenApi definition
  at: components > schemas > somethingV1 > properties
    at: somethingElseV1 > properties
      at: id
        Property not allowed: readonly
      at: myProperty
        Property not allowed: readonly
      at: myOtherProperty
        Property not allowed: readonly
    at: version > properties > someProperty
      Property not allowed: additionalProperties

We would like to allow properties like "readonly" and "additionalProperties" even though they don't quite conform to the spec. Is there a way to ignore this step of the document validation entirely?

Thank you for your help!

AndrewChurchill avatar May 12 '22 17:05 AndrewChurchill

You can now use properties that are not part of the actual spec by specifying the exception skip code EDEV001. If you are unfamiliar with the way skip codes work please see this documentation: https://openapi-enforcer.com/api/#enforcer

This has been published to NPM with version 1.21.0.

Have a great day!

Gi60s avatar May 18 '22 05:05 Gi60s

Thank you for taking care of this so quickly! It works great!

AndrewChurchill avatar May 18 '22 15:05 AndrewChurchill

I may have spoken too soon... I added the exception skip code, but I'm still seeing the same exception.

const [openapi, error, warning] = await Enforcer(path, {
    fullResult: true,
    componentOptions: {
        exceptionSkipCodes: [
            // Don't warn for non-standard format types
            'WSCH001',

            // Don't check "example" properties
            'WSCH006',

            // Allow additional properties (i.e., readonly: true)
            'EDEV001',
        ],
    },
});

It still produces the same errors:

One or more errors exist in the OpenApi definition
  at: components > schemas > somethingV1 > properties
    at: somethingElse > properties > somethingElseElse
      Property not allowed: something [EDEV001]

Am I specifying the code correctly? I'm using version 1.21.0.

AndrewChurchill avatar May 18 '22 18:05 AndrewChurchill

I believe you are specifying the code correctly. I'll check this out. Also, if you have an example openapi.yml or other file that I could run it against that will help to ensure that I've fixed the problem.

Gi60s avatar May 18 '22 22:05 Gi60s

@Gi60s I've run in this too: it seems as if the exceptionSkipCodes options are not respected.

The debugger pointed to https://github.com/Gi60s/openapi-enforcer/blob/fc78fe42b4cf2eba9200188cc8d45f8aaadf1577/src/definition-validator.js#L388 which in this case creates a new Schema(new ValidatorState(data)) using constructor helper https://github.com/Gi60s/openapi-enforcer/blob/fc78fe42b4cf2eba9200188cc8d45f8aaadf1577/src/super.js#L79

The user options are carried in the definition.options but not used and options is not set ...

plankthom avatar Oct 14 '22 10:10 plankthom

A test case:

openapi-enforcer-140.zip

plankthom avatar Oct 14 '22 11:10 plankthom

Nice troubleshooting @plankthom. I'll take a look at this and hopefully have it resolved in the next day or two.

Gi60s avatar Oct 26 '22 14:10 Gi60s

Thanks for your patience. This should be fixed now. Try version 1.22.1.

Gi60s avatar Nov 03 '22 07:11 Gi60s