class S2AssociateAccount(APIView): schema = AutoSchema(manual_fields=[ coreapi.Field(name='Authorization', required=True, location='header', description='', type='string'), coreapi.Field(name='account_id', required=True, location='form', schema=coreschema.Anything()), coreapi.Field(name='rw_flag', required=True, location='form', schema=coreschema.Anything()), coreapi.Field(name='s2_group', required=True, location='query', description='', type='string'), ]) @method_decorator(token_certify_decorator) def put(self, request): s2_group = request.GET.get('s2_group') s2_accounts = json.loads(request.body) S2 = conn.associate_s2_account_group(s2_group=s2_group, s2_accounts=s2_accounts) return JsonResponse(S2)
class S2DescribeAccounts(APIView): """ get: 获取NAS账号 """ schema = AutoSchema(manual_fields=[ coreapi.Field(name='Authorization', required=True, location='header', description='', type='string'), coreapi.Field(name='s2_accounts', required=False, location='query', schema=coreschema.Anything()), # coreapi.Field (name='account_types', required=False, location='query', description='', type='string'), # coreapi.Field (name='account_name', required=False, location='query', description='', type='string'), ]) @method_decorator(token_certify_decorator) def get(self, request): accounts = request.GET.get('s2_accounts') s2_accounts = accounts.split() S2_SAN = conn.describe_s2_accounts( s2_accounts=s2_accounts ) #,account_types=account_types,account_name=account_name) return JsonResponse(S2_SAN, status=200)
def __init__( self, name: str, query_filter: str, schema: coreschema = None, required: bool = False, ): self.name, self.filter, self.required = name, query_filter, required self.core_schema = schema or coreschema.Anything( title=name, description=f"Filter by {name}.")
def load_jsonschema(data): schemas = get_typed_schemas(data) if len(schemas) > 1: schemas = [coreschema.Union(schemas)] schemas += get_composite_schemas(data) if not schemas: schema = coreschema.Anything() elif len(schemas) == 1: schema = schemas[0] else: schema = coreschema.Intersection(schemas) if "enum" in data: # Restrict enum values by any existing type constraints, # and then use an Enum type. enum_values = [ value for value in data["enum"] if schema.validate(value) == [] ] return coreschema.Enum(enum_values) return schema
jsonschema = coreschema.RefSpace( { "Schema": coreschema.Object( properties={ # Meta "id": coreschema.String(format="uri"), "$schema": coreschema.String(format="uri"), "title": coreschema.String(), "description": coreschema.String(), "default": coreschema.Anything(), "definitions": coreschema.Ref("SchemaMap"), # Type "type": coreschema.Ref("SimpleTypes") | coreschema.Array(items=coreschema.Ref("SimpleTypes"), min_items=1, unique_items=True), # Number validators "minimum": coreschema.Number(), "maximum": coreschema.Number(), "exclusiveMinimum": coreschema.Boolean(default=False),
from coreschema.compat import text_types import coreschema import re jsonschema = coreschema.RefSpace({ 'Schema': coreschema.Object( properties={ # Meta 'id': coreschema.String(format='uri'), '$schema': coreschema.String(format='uri'), 'title': coreschema.String(), 'description': coreschema.String(), 'default': coreschema.Anything(), 'definitions': coreschema.Ref('SchemaMap'), # Type 'type': coreschema.Ref('SimpleTypes') | coreschema.Array(items=coreschema.Ref('SimpleTypes'), min_items=1, unique_items=True), # Number validators 'minimum': coreschema.Number(), 'maximum': coreschema.Number(), 'exclusiveMinimum': coreschema.Boolean(default=False), 'exclusiveMaximum': coreschema.Boolean(default=False), 'multipleOf': coreschema.Number(minimum=0, exclusive_minimum=True), # String validators 'minLength': coreschema.Integer(minimum=0, default=0), 'maxLength': coreschema.Integer(minimum=0), 'pattern': coreschema.String(format='regex'), 'format': coreschema.String(), # Array validators 'items': coreschema.Ref('Schema') | coreschema.Ref('SchemaArray'), # TODO: default={} 'additionalItems': coreschema.Boolean() | coreschema.Ref('Schema'), # TODO: default={}