Yelp / bravado-core

Other
109 stars 98 forks source link

Increase resilience of is_model and is_object methods #343

Closed macisamuele closed 5 years ago

macisamuele commented 5 years ago

While testing the library, I've played a bit importint the kubernetes swagger specs (link). The specs were selected as a good example of very very big swagger specs. During the testing I've uncovered an issue related to is_models and is_object methods.

The method do assume that x-model and title properties of the object are string, but this is not something that we could actually assume as the specs do not prevent the presence of the attribute as valid object properties. For example

definitions:
  model:
    properties:
      title:
        type: string
      x-model:
        type: string

The goal of this PR is to better handle the condition of:

In order to prevent future regression I extracted a small test-case that is able to trigger the issue.

The script using while testing (that helped me discovering the bug) is the one listed below

import requests
from bravado_core.spec import Spec
spec_url = 'https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.15/api/openapi-spec/swagger.json'
Spec.from_dict(requests.get(spec_url).json())
coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.003%) to 97.385% when pulling 0e9e52d5e249a1432cfd73034126fb53f5d1709f on macisamuele:maci-ensure-kubernetes-Spec-import into 8d3c5f1a36dee3862669261ad4cbc019181946a3 on Yelp:master.

macisamuele commented 5 years ago

There are no specific performance differences as: