class StackAnalysisResponse(JSLSchemaBase): """Class with the schema definition based on JSL domain specific language.""" class Options: """A container for options.""" description = "Stack analysis" definition_id = "stack_analysis" with jsl.Scope(lambda v: v < ROLE_v2_0_1) as before_v2_0_1: before_v2_0_1.status = jsl.StringField( enum=["FINISHED", "FAILED", "INPROGRESS"], required=True) with jsl.Scope(lambda v: v >= ROLE_v2_0_1) as since_v2_0_1: since_v2_0_1.status = jsl.StringField(enum=["success"], required=True) submitted_at = jsl.DateTimeField(required=True) started_at = jsl.DateTimeField(required=True) finished_at = jsl.DateTimeField(required=True) request_id = jsl.StringField(required=True) with jsl.Scope(lambda v: v < ROLE_v2_1_0) as removed_in_v2_1_0: removed_in_v2_1_0.analyses_result = jsl.ArrayField(jsl.StringField(), required=True) with jsl.Scope(lambda v: v == ROLE_v1_0_0 or v == ROLE_v1_1_0 or v == ROLE_v1_2_0) as upto_v1_2_0: upto_v1_2_0.result = jsl.DocumentField(StackAnalysisResult, required=True) with jsl.Scope(lambda v: v >= ROLE_v2_0_0) as added_in_v2_0_0: added_in_v2_0_0.result = jsl.ArrayField(jsl.DocumentField( StackAnalysisReport, as_ref=True), required=True)
class ComponentAnalysis(JSLSchemaBaseWithRelease): class Options(object): definition_id = "component_analysis" description = "Software component analysis" ecosystem = jsl.StringField( description="Language ecosystem providing the component", required=True) package = jsl.StringField(description="Component name", required=True) version = jsl.StringField(description="Component version", required=True) latest_version = jsl.OneOfField( [jsl.StringField(), jsl.NullField()], description= "Latest version available of this component (null if unknown)", required=True) started_at = jsl.DateTimeField( description="Date/time component analysis was started", required=True) finished_at = jsl.DateTimeField( description="Date/time component analysis was finished", required=True) access_count = jsl.NumberField( description="Number of times this component has been queried", required=True) dependents_count = jsl.Var({ lambda v: v >= ROLE_v1_1_0: jsl.NumberField(description="Number of dependent GitHub projects", required=True) }) analyses = jsl.DocumentField(AnalysisSet, as_ref=True, required=True) package_info = jsl.DictField( description="Additional information related to the package", additional_properties=True, required=False)
class PageSchema(jsl.Document): uuid = jsl.StringField(required=False, default='') title = jsl.StringField(required=True, default='') body = jsl.StringField(required=True, default='') footer = jsl.StringField(required=False, default='') created = jsl.DateTimeField(required=False) last_modified = jsl.DateTimeField(required=False) state = jsl.StringField(required=False)
def dataclass_field_to_jsl_field(prop: dataclasses.Field, nullable=False) -> jsl.BaseField: t = dataclass_check_type(prop, date) if t: return jsl.DateTimeField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, datetime) if t: return jsl.DateTimeField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, str) if t: return jsl.StringField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, int) if t: return jsl.IntField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, float) if t: return jsl.NumberField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, bool) if t: return jsl.BooleanField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, dict) if t: return jsl.DictField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, ISchema) if t: subtype = jsonobject_to_jsl(t['schema'], nullable=nullable) return jsl.DocumentField(name=prop.name, document_cls=subtype, required=t['required']) t = dataclass_check_type(prop, list) if t: return jsl.ArrayField(name=prop.name, required=t['required']) t = dataclass_check_type(prop, typing.List) if t: if 'schema' not in t.keys(): return jsl.ArrayField(name=prop.name, required=t['required']) if issubclass(t['schema'], ISchema): subtype = jsl.DocumentField( document_cls=jsonobject_to_jsl(t['schema'], nullable=nullable)) elif t['schema'] == str: subtype = jsl.StringField(name=prop.name) elif t['schema'] == int: subtype = jsl.IntField(name=prop.name) elif t['schema'] == float: subtype = jsl.NumberField(name=prop.name) elif t['schema'] == dict: subtype = jsl.DictField(name=prop.name) else: raise KeyError(t['schema']) return jsl.ArrayField(items=subtype, required=t['required']) raise KeyError(prop)
def jsonobject_property_to_jsl_field(prop: jsonobject.JsonProperty, nullable=False) -> jsl.BaseField: if isinstance(prop, jsonobject.DateProperty): return jsl.DateTimeField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.DateTimeProperty): return jsl.DateTimeField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.StringProperty): return jsl.StringField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.IntegerProperty): return jsl.IntField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.FloatProperty): return jsl.NumberField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.BooleanProperty): return jsl.BooleanField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.DictProperty): if prop.item_wrapper: subtype = jsonobject_to_jsl(prop.item_wrapper.item_type, nullable=nullable) return jsl.DocumentField(name=prop.name, document_cls=subtype, required=prop.required) return jsl.DictField(name=prop.name, required=prop.required) if isinstance(prop, jsonobject.ListProperty): if prop.item_wrapper: if isinstance(prop.item_wrapper, jsonobject.ObjectProperty): if issubclass(prop.item_wrapper.item_type, jsonobject.JsonObject): subtype = jsl.DocumentField(document_cls=jsonobject_to_jsl( prop.item_wrapper.item_type), nullable=nullable) elif isinstance(prop.item_wrapper.item_type, jsonobject.JsonProperty): subtype = jsonobject_property_to_jsl_field( prop.item_wrapper.item_type) else: raise KeyError(prop.item_wrapper.item_type) elif isinstance(prop.item_wrapper, jsonobject.StringProperty): subtype = jsl.StringField(name=prop.name) elif isinstance(prop.item_wrapper, jsonobject.IntegerProperty): subtype = jsl.IntField(name=prop.name) elif isinstance(prop.item_wrapper, jsonobject.FloatProperty): subtype = jsl.NumberField(name=prop.name) elif isinstance(prop.item_wrapper, jsonobject.DictProperty): subtype = jsl.DictField(name=prop.name) else: raise KeyError(prop.item_wrapper) return jsl.ArrayField(items=subtype, required=prop.required) return jsl.ArrayField(name=prop.name, required=prop.required) raise KeyError(prop)
class VersionRangeResolver(JSLSchemaBase): class Options: description = "Version range resolver" definition_id = "version_range_resolver" resolved_at = jsl.DateTimeField(required=True) query = jsl.StringField(required=True) detail = jsl.DocumentField(VersionResolutionDetail, required=True)
class VersionRangeResolver(JSLSchemaBase): """Class with the schema definition based on JSL domain specific language.""" class Options: """A container for options.""" description = "Version range resolver" definition_id = "version_range_resolver" resolved_at = jsl.DateTimeField(required=True) query = jsl.StringField(required=True) detail = jsl.DocumentField(VersionResolutionDetail, required=True)
class TodoActionSchema(jsl.Document): """ A todo action schema Attributes: action (str): Specify the action taken by the worker on the given todo. Examples: skip, unskip, complete, incomplete datetime (datetime): The time the action was taken. step_slug (str): Unique identifier for the workflow step that the task represents. """ action = jsl.StringField(required=True) datetime = jsl.DateTimeField(required=True) step_slug = jsl.StringField(required=True)
class Metadata(jsl.Document): class Options(object): definition_id = 'metadata' description = 'Metadata definition' additional_properties = True authors = jsl.ArrayField(jsl.EmailField(), min_items=1, unique_items=True, required=True) last_modified = jsl.DateTimeField(name='last-modified', required=True) version = jsl.StringField( required=True, pattern= r"^v?((0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*)))((-([0-9A-Za-z\-]+))(\.([0-9A-Za-z\-]+))*((\+([0-9A-Za-z\-]+))(\.([0-9A-Za-z\-]+))*)?)?$" ) comment = jsl.StringField(required=False, max_length=1024)
class CRUDSchema(jsl.Document): uuid = jsl.StringField(required=False) created = jsl.DateTimeField(required=False) last_modified = jsl.DateTimeField(required=False)
def dataclass_field_to_jsl_field(prop: dataclasses.Field, nullable=False, mode="default") -> jsl.BaseField: if mode in ["edit", "edit-process"]: update_mode = True else: update_mode = False t = dataclass_check_type(prop, date) if t: if update_mode: t["required"] = False return jsl.DateTimeField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, datetime) if t: if update_mode: t["required"] = False return jsl.DateTimeField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, str) if t: if update_mode: t["required"] = False return jsl.StringField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, int) if t: if update_mode: t["required"] = False return jsl.IntField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, float) if t: if update_mode: t["required"] = False return jsl.NumberField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, bool) if t: if update_mode: t["required"] = False return jsl.BooleanField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, dict) if t: if update_mode: t["required"] = False return jsl.DictField(name=prop.name, required=t["required"]) t = is_dataclass_field(prop) if t: if update_mode: t["required"] = False subtype = dc2jsl(t["schema"], nullable=nullable) return jsl.DocumentField(name=prop.name, document_cls=subtype, required=t["required"]) t = dataclass_check_type(prop, list) if t: if update_mode: t["required"] = False return jsl.ArrayField(name=prop.name, required=t["required"]) t = dataclass_check_type(prop, typing.List) if t: if update_mode: t["required"] = False if "schema" not in t.keys(): return jsl.ArrayField(name=prop.name, required=t["required"]) if dataclasses.is_dataclass(t["schema"]): subtype = jsl.DocumentField( document_cls=dc2jsl(t["schema"], nullable=nullable)) elif t["schema"] == str: subtype = jsl.StringField(name=prop.name) elif t["schema"] == int: subtype = jsl.IntField(name=prop.name) elif t["schema"] == float: subtype = jsl.NumberField(name=prop.name) elif t["schema"] == dict: subtype = jsl.DictField(name=prop.name) else: raise KeyError(t["schema"]) return jsl.ArrayField(items=subtype, required=t["required"]) raise KeyError(prop)