Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

additionnal properties can be an object or a boolean #63

Closed LasneF closed 4 years ago

LasneF commented 4 years ago

when validating a swagger it raise an error about Property not allowed: additionalProperties

this issue is when the schema mention an additional properties to false additionalProperties: false

according to json draft 4 spec on which swagger is based it is mentionned "5.4.4. additionalProperties, properties and patternProperties 5.4.4.1. Valid values The value of "additionalProperties" MUST be a boolean or an object. If it is an object, it MUST also be a valid JSON Schema."

here is where it occurs

Links:
  type: object
  description: Links relevant to the payload
  properties:
    Self:
      type: string
      format: uri
    First:
      type: string
      format: uri
    Prev:
      type: string
      format: uri
    Next:
      type: string
      format: uri
    Last:
      type: string
      format: uri
  additionalProperties: false

for the full swagger you can use this one https://raw.githubusercontent.com/OpenBankingUK/read-write-api-specs/v3.1.2-RC1/dist/account-info-swagger.yaml

Gi60s commented 4 years ago

When I run the OpenAPI document you've provided in that link I do not see the error that you're seeing. I've even run the debugger and it is properly accepting the additionalProperties: false for the Links definition.

I am seeing a bunch of other errors though:

Error: One or more errors exist in the Swagger definition
  at: definitions > OBReadProduct2 > properties > Data > properties > Product > items > properties
    at: BCA > properties
      at: CreditInterest > properties > TierBandSet
        at: items > properties > TierBand
          Property not allowed: additionalProperties
        Property not allowed: additionalProperties
      at: Overdraft > properties > OverdraftTierBandSet
        at: items > properties
          at: OverdraftTierBand
            at: items > properties > OverdraftFeesCharges
              at: items > properties
                at: OverdraftFeeChargeCap
                  at: items > properties > OtherFeeType
                    Property not allowed: additionalProperties
                  Property not allowed: additionalProperties
                at: OverdraftFeeChargeDetail
                  at: items > properties > OverdraftFeeChargeCap
                    at: items > properties > OtherFeeType
                      Property not allowed: additionalProperties
                    Property not allowed: additionalProperties
                  Property not allowed: additionalProperties
              Property not allowed: additionalProperties
            Property not allowed: additionalProperties
          at: OverdraftFeesCharges
            at: items > properties
              at: OverdraftFeeChargeCap
                at: items > properties > OtherFeeType
                  Property not allowed: additionalProperties
                Property not allowed: additionalProperties
              at: OverdraftFeeChargeDetail
                at: items > properties > OverdraftFeeChargeCap
                  at: items > properties > OtherFeeType
                    Property not allowed: additionalProperties
                  Property not allowed: additionalProperties
                Property not allowed: additionalProperties
            Property not allowed: additionalProperties
        Property not allowed: additionalProperties
      at: OtherFeesCharges
        at: items > properties
          at: FeeChargeDetail
            at: items > properties > FeeChargeCap
              at: items > properties > OtherFeeType
                Property not allowed: additionalProperties
              Property not allowed: additionalProperties
            Property not allowed: additionalProperties
          at: FeeChargeCap
            at: items > properties > OtherFeeType
              Property not allowed: additionalProperties
            Property not allowed: additionalProperties
        Property not allowed: additionalProperties
    at: PCA > properties
      at: CreditInterest > properties > TierBandSet
        at: items > properties > TierBand
          Property not allowed: additionalProperties
        Property not allowed: additionalProperties
      at: Overdraft > properties > OverdraftTierBandSet
        at: items > properties
          at: OverdraftTierBand
            at: items > properties > OverdraftFeesCharges
              at: items > properties
                at: OverdraftFeeChargeCap
                  at: items > properties > OtherFeeType
                    Property not allowed: additionalProperties
                  Property not allowed: additionalProperties
                at: OverdraftFeeChargeDetail
                  at: items > properties > OverdraftFeeChargeCap > properties > OtherFeeType
                    Property not allowed: additionalProperties
                  Property not allowed: additionalProperties
              Property not allowed: additionalProperties
            Property not allowed: additionalProperties
          at: OverdraftFeesCharges
            at: items > properties
              at: OverdraftFeeChargeCap
                at: items > properties > OtherFeeType
                  Property not allowed: additionalProperties
                Property not allowed: additionalProperties
              at: OverdraftFeeChargeDetail
                at: items > properties > OverdraftFeeChargeCap > properties > OtherFeeType
                  Property not allowed: additionalProperties
                Property not allowed: additionalProperties
            Property not allowed: additionalProperties
        Property not allowed: additionalProperties
      at: OtherFeesCharges > properties
        at: FeeChargeDetail
          at: items > properties > FeeChargeCap
            at: items > properties > OtherFeeType
              Property not allowed: additionalProperties
            Property not allowed: additionalProperties
          Property not allowed: additionalProperties
        at: FeeChargeCap
          at: items > properties > OtherFeeType
            Property not allowed: additionalProperties
          Property not allowed: additionalProperties

I dug into the first error...

Error: One or more errors exist in the Swagger definition
  at: definitions > OBReadProduct2 > properties > Data > properties > Product > items > properties
    at: BCA > properties
      at: CreditInterest > properties > TierBandSet
        at: items > properties > TierBand
          Property not allowed: additionalProperties

and I found this definition (items properties hidden for brevity):

TierBand:
  description: Tier Band Details
  type: array
  title: TierBand
  items: ...
  additionalProperties: false
  minItems: 1

The additionalProperties is not allowed here because type: array.

Will you please take another look at what you're seeing and let me know if there are any errors with the enforcer? My initial research here suggests that it's operating correctly in regards to additionalProperties.

Also, I must say that is a truly magnificently large OpenAPI document. It must have taken a lot of work and I am impressed.

Gi60s commented 4 years ago

I believe this is operating as expected. Please feel free to reach out if you're still having problems.