export function getAllPropertiesIncludingDeeplyNestedProperties()

in packages/rulesets/src/spectral/functions/utils.ts [47:69]


export function getAllPropertiesIncludingDeeplyNestedProperties(schema: any, properties: any[]) {
  if (!schema) {
    return {}
  }
  if (schema.allOf && Array.isArray(schema.allOf)) {
    schema.allOf.forEach((base: any) => {
      getAllPropertiesIncludingDeeplyNestedProperties(base, properties)
    })
  }
  if (schema.properties) {
    const props = schema.properties
    //for each property check if it references other definition(basically, check for deeply nested properties)
    Object.entries(props).forEach(([key, value]: any) => {
      if (!value.properties) {
        properties.push(Object.fromEntries([[key, value]]))
      } else {
        getAllPropertiesIncludingDeeplyNestedProperties(props[key], properties)
      }
    })
  }

  return properties
}