Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Ignore "example" properties #139

Closed AndrewChurchill closed 2 years ago

AndrewChurchill commented 2 years ago

Hello, I am seeing the following validation error when I try to call:

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

Result:

One or more errors exist in the OpenApi definition
  at: paths
    at: /path/{id}
      at: get > responses > 200 > content > application/json > examples
        at: Something
          Unable to deserialize value
            Expected an object. Received: "{ \"id\": \"aaaaaaaa-1111-2222-3333-ffffffff\", ... }"

My question is: is there a way to ignore "example" properties? Meaning if the validator encounters a property called "examples" it just excepts whatever's in there and moves on (even if it's a string and it expects an object)? We give our examples as JSON strings like they'd appear in the request body. I don't want any validation to take place on these entries at the moment.

Is there a way to ignore validation on examples?

Alternatively, if examples are given as a JSON string, is there a way to tell the validator to parse it as a JSON string? If not, I'd rather disable the validator trying to load examples for the moment.

Thanks for your help!

Gi60s commented 2 years ago

I don't believe this functionality currently exists, but it shouldn't be hard to add in. I'll try to make this update before Monday.

Gi60s commented 2 years ago

I was able to add this functionality to release 1.19.0. The skip code is WSCH006.

AndrewChurchill commented 2 years ago

Thank you so much for adding this!