Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Ignore "Property not allowed" #140

Closed AndrewChurchill closed 1 year ago

AndrewChurchill commented 2 years ago

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!

Gi60s commented 2 years ago

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!

AndrewChurchill commented 2 years ago

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

AndrewChurchill commented 2 years ago

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.

Gi60s commented 2 years ago

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.

plankthom commented 1 year ago

@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 commented 1 year ago

A test case:

openapi-enforcer-140.zip

Gi60s commented 1 year ago

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

Gi60s commented 1 year ago

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