def _get_path_parameters(self, path, method): """ Return a list of parameters from templated path variables. """ assert uritemplate, '`uritemplate` must be installed for OpenAPI schema support.' model = getattr(getattr(self.view, 'queryset', None), 'model', None) parameters = [] for variable in uritemplate.variables(path): description = '' if model is not None: # TODO: test this. # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.help_text: description = force_str(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) parameter = { "name": variable, "in": "path", "required": True, "description": description, 'schema': { 'type': 'string', # TODO: integer, pattern, ... }, } parameters.append(parameter) return parameters
def get_custom_path_parameters(self, path, method): """ Return a list of parameters from templated path variables. """ model = getattr(self.view.__class__, 'model_class', None) parameters = [] for variable in uritemplate.variables(path): description = '' if model is not None: # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.help_text: description = force_text(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) parameter = { "name": variable, "in": "path", "required": True, "description": description, 'schema': { 'type': 'string' }, } parameters.append(parameter) return parameters
def _get_path_parameters(self, path, method): """ Return a list of parameters from templated path variables. """ assert uritemplate, '`uritemplate` must be installed for OpenAPI schema support.' model = getattr(getattr(self.view, 'queryset', None), 'model', None) parameters = [] for variable in uritemplate.variables(path): description = '' if model is not None: # TODO: test this. # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.help_text: description = force_text(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) parameter = { "name": variable, "in": "path", "required": True, "description": description, 'schema': { 'type': 'string', # TODO: integer, pattern, ... }, } parameters.append(parameter) return parameters
def get_path_fields(self, path, method, view): """ Return a list of `coreapi.Field` instances corresponding to any templated path variables. """ fields = [] for variable in uritemplate.variables(path): field = coreapi.Field(name=variable, location='path', required=True) fields.append(field) return fields
def get_path_fields(self, path, method, view): """ Return a list of `coreapi.Field` instances corresponding to any templated path variables. """ fields = [] for variable in uritemplate.variables(path): field = coreapi.Field(name=variable, location='path', required=True) fields.append(field) return fields
def get_custom_path_parameters(self, path, method): """ Return a list of parameters from templated path variables. """ model = getattr(self.view.__class__, 'model_class', None) parameters = [] for variable in uritemplate.variables(path): if '/stats' in path: parameter = { "name": "var", "in": "path", "required": False, "description": ("Timestamp URL. Example:\n- \"/timestamp_start:" "1603801749.315451\"\n- \"/timestamp_start:1603801749." "315451-timestamp_end:1603801850.463\""), 'schema': { 'type': 'string' }, } parameters.append(parameter) continue description = '' if model is not None: # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.help_text: description = force_text(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) parameter = { "name": variable, "in": "path", "required": True, "description": description, 'schema': { 'type': 'string' }, } parameters.append(parameter) return parameters
def get_path_fields(self, path, method): """ Return a list of `coreapi.Field` instances corresponding to any templated path variables. """ view = self.view model = getattr(getattr(view, "queryset", None), "model", None) fields = [] for variable in uritemplate.variables(path): title = "" description = "" schema_cls = coreschema.String kwargs = {} if model is not None: # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.verbose_name: title = force_str(model_field.verbose_name) if model_field is not None and model_field.help_text: description = force_str(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) if (hasattr(view, "lookup_value_regex") and view.lookup_field == variable): kwargs["pattern"] = view.lookup_value_regex elif isinstance(model_field, models.AutoField): schema_cls = coreschema.Integer field = coreapi.Field( name=variable, location="path", required=True, schema=schema_cls(title=title, description=description, **kwargs), ) fields.append(field) return fields
def get_path_fields(self, path, method): """ Return a list of `coreapi.Field` instances corresponding to any templated path variables. """ view = self.view model = getattr(getattr(view, 'queryset', None), 'model', None) fields = [] for variable in uritemplate.variables(path): title = '' description = '' schema_cls = coreschema.String kwargs = {} if model is not None: # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except Exception: model_field = None if model_field is not None and model_field.verbose_name: title = force_text(model_field.verbose_name) if model_field is not None and model_field.help_text: description = force_text(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable: kwargs['pattern'] = view.lookup_value_regex elif isinstance(model_field, models.AutoField): schema_cls = coreschema.Integer field = coreapi.Field( name=variable, location='path', required=True, schema=schema_cls(title=title, description=description, **kwargs) ) fields.append(field) return fields
def get_path_fields(self): view = self.view path = self.path model = getattr(getattr(view, 'queryset', None), 'model', None) for variable in uritemplate.variables(path): schema_cls = schema.String kwargs = {} if model is not None: try: model_field = model._meta.get_field(variable) except FieldDoesNotExist: model_field = None # if model_field is not None: # if model_field.verbose_name: # title = force_text(model_field.verbose_name) # if model_field.help_text: # description = force_text(model_field.help_text) # elif model_field.primary_key: # description = get_pk_description(model, model_field) if hasattr(view, 'lookup_value_regex') and \ view.lookup_field == variable: kwargs['pattern'] = view.lookup_value_regex if isinstance(model_field, models.AutoField): schema_cls = schema.Integer # Check other field types ? It's mostly string though field = Field( title=variable, required=True, schema=schema_cls(**kwargs) ) self.path_fields.append(field)
def get_path_fields(self, path, method, view): """ Return a list of `coreapi.Field` instances corresponding to any templated path variables. """ model = getattr(getattr(view, 'queryset', None), 'model', None) fields = [] for variable in uritemplate.variables(path): title = '' description = '' schema_cls = coreschema.String if model is not None: model_field = None # Attempt to infer a field description if possible. try: model_field = model._meta.get_field(variable) except: pass if model_field is not None and model_field.verbose_name: title = force_text(model_field.verbose_name) if model_field is not None and model_field.help_text: description = force_text(model_field.help_text) elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) if isinstance(model_field, models.AutoField): schema_cls = coreschema.Integer field = coreapi.Field(name=variable, location='path', required=True, schema=schema_cls(title=title, description=description)) fields.append(field) return fields