Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_schema_global_state_untouched_2parameters(self):
assert RunSchema._declared_fields['sample']._Nested__schema is None
data = swagger.schema2parameters(RunSchema)
json.dumps(data)
assert RunSchema._declared_fields['sample']._Nested__schema is None
def _endpoint_schemas2swagger_parameters(self, endpoint_schemas):
parameters = []
if 'path' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['path'], default_in="path")
if 'query' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['query'], default_in="query")
if 'header' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['header'], default_in="header")
if 'body' in endpoint_schemas:
parameters += [{
'in' : 'body',
'name': 'body',
'required': True,
'schema' : {'$ref': "#/definitions/" + endpoint_schemas['body'].__name__ }
}]
return parameters
def _generate_swagger_definitions_tree(self):
definitions = {}
for schema in self.swagger_definition_schemas:
definitions[schema.__name__] = schema2parameters(schema)[0]['schema']
return definitions
def parameters_for(self, doc):
schema = doc['params']
if not schema:
return []
if isinstance(schema, list):
return schema
if isinstance(schema, dict) and all(isinstance(field, dict) for field in schema.values()):
return list(schema.values())
if 'in' in schema.context and 'json' in schema.context['in']:
default_location = 'body'
else:
default_location = 'query'
return schema2parameters(schema, default_in=default_location, required=True)
def _endpoint_schemas2swagger_parameters(self, endpoint_schemas):
parameters = []
if 'path' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['path'], default_in="path")
if 'query' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['query'], default_in="query")
if 'header' in endpoint_schemas:
parameters += schema2parameters(endpoint_schemas['header'], default_in="header")
if 'body' in endpoint_schemas:
parameters += [{
'in' : 'body',
'name': 'body',
'required': True,
'schema' : {'$ref': "#/definitions/" + endpoint_schemas['body'].__name__ }
}]
return parameters
def parameters_for(self, doc):
schema = doc['params']
if not schema:
return []
if isinstance(schema, list):
return schema
if isinstance(schema, dict) and all(isinstance(field, dict) for field in schema.values()):
return list(schema.values())
if 'in' in schema.context and 'json' in schema.context['in']:
default_location = 'body'
else:
default_location = 'query'
return schema2parameters(schema, default_in=default_location, required=True)