text
stringlengths
0
828
3716,"def to_document(self):
""""""
Serialize this specification to a JSON-compatible object representing a
Swagger specification.
""""""
return dict(
info=thaw(self.info),
paths=thaw(self.paths),
definitions=thaw(self.definitions),
securityDefinitions=thaw(self.securityDefinitions),
security=thaw(self.security),
swagger=thaw(self.swagger),
)"
3717,"def pclass_for_definition(self, name):
""""""
Get a ``pyrsistent.PClass`` subclass representing the Swagger definition
in this specification which corresponds to the given name.
:param unicode name: The name of the definition to use.
:return: A Python class which can be used to represent the Swagger
definition of the given name.
""""""
while True:
try:
cls = self._pclasses[name]
except KeyError:
try:
original_definition = self.definitions[name]
except KeyError:
raise NoSuchDefinition(name)
if ""$ref"" in original_definition:
# Identify definitions that are merely a reference to
# another and restart processing. There is some
# duplication of logic between this and the $ref handling
# in _ClassModel. It would be nice to eliminate this
# duplication.
name = original_definition[u""$ref""]
assert name.startswith(u""#/definitions/"")
name = name[len(u""#/definitions/""):]
continue
definition = self.transform_definition(name, original_definition)
kind = self._identify_kind(definition)
if kind is None:
raise NotClassLike(name, definition)
generator = getattr(self, ""_model_for_{}"".format(kind))
model = generator(name, definition)
bases = tuple(self._behaviors.get(name, []))
cls = model.pclass(bases)
self._pclasses[name] = cls
return cls"
3718,"def _model_for_CLASS(self, name, definition):
""""""
Model a Swagger definition that is like a Python class.
:param unicode name: The name of the definition from the
specification.
:param pyrsistent.PMap definition: A Swagger definition to categorize.
This will be a value like the one found at
``spec[""definitions""][name]``.
""""""
return _ClassModel.from_swagger(
self.pclass_for_definition,
name,
definition,
)"
3719,"def pclass_field_for_attribute(self):
""""""
:return: A pyrsistent field reflecting this attribute and its type model.
""""""
return self.type_model.pclass_field_for_type(
required=self.required,
default=self.default,
)"
3720,"def from_swagger(cls, pclass_for_definition, name, definition):
""""""
Create a new ``_ClassModel`` from a single Swagger definition.
:param pclass_for_definition: A callable like
``Swagger.pclass_for_definition`` which can be used to resolve
type references encountered in the definition.
:param unicode name: The name of the definition.
:param definition: The Swagger definition to model. This will be a
value like the one found at ``spec[""definitions""][name]``.
:return: A new model for the given definition.
""""""
return cls(
name=name,
doc=definition.get(u""description"", name),
attributes=cls._attributes_for_definition(
pclass_for_definition,
definition,
),
)"