def fhir_field_from_schema( schema: Interface, resource_type: str = None ) -> Union[FhirField, None]: """ """ index_fields: dict if resource_type: index_fields = directives.merged_tagged_value_dict(schema, directives.index.key) for name, field in get_fields_in_order(schema): if IFhirField.providedBy(field): if resource_type: catalog_info = index_fields.get(name, None) if catalog_info is None: continue if catalog_info.get("resource_type", None) is None: continue if catalog_info["resource_type"] != resource_type: continue return field return None
def serialize(self): for name, field in get_fields_in_order(self.schema): serializer = get_multi_adapter((field, self.schema, self.request), ISchemaFieldSerializeToJson) self.schema_json['properties'][name] = serializer.serialize() if field.required: self.schema_json['required'].append(name) self.schema_json['invariants'] = self.invariants return self.schema_json
def serialize(self): for name, field in get_fields_in_order(self.schema): serializer = get_multi_adapter( (field, self.schema, self.request), ISchemaFieldSerializeToJson) self.schema_json['properties'][name] = serializer.serialize() if field.required: self.schema_json['required'].append(name) self.schema_json['invariants'] = self.invariants return self.schema_json
async def __call__(self): factory = self.factory result = { "title": factory.type_name, "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": [], "definitions": {}, "properties": {}, } # Base object class serialized for name, field in get_fields_in_order(factory.schema): if field.required: result["required"].append(name) serializer = get_multi_adapter( (field, factory.schema, self.request), ISchemaFieldSerializeToJson) result["properties"][name] = await serializer() invariants = [] for i in factory.schema.queryTaggedValue("invariants", []): invariants.append("%s.%s" % (i.__module__, i.__name__)) result["invariants"] = invariants # Behavior serialization for schema in factory.behaviors or (): schema_serializer = get_multi_adapter((schema, self.request), ISchemaSerializeToJson) serialization = await schema_serializer() result["properties"][schema_serializer.name] = ({ "$ref": "#/components/schemas/" + schema_serializer.name }, ) result["definitions"][schema_serializer.name] = serialization behavior = get_utility(IBehavior, name=schema_serializer.name) definition = result["definitions"][schema_serializer.name] definition[ "title"] = behavior.title or schema_serializer.short_name definition["description"] = behavior.description return result
async def __call__(self): factory = self.factory result = { 'title': factory.type_name, '$schema': 'http://json-schema.org/draft-04/schema#', 'type': 'object', 'required': [], 'definitions': {}, 'properties': {} } # Base object class serialized for name, field in get_fields_in_order(factory.schema): if field.required: result['required'].append(name) serializer = get_multi_adapter( (field, factory.schema, self.request), ISchemaFieldSerializeToJson) result['properties'][name] = await serializer() invariants = [] for i in factory.schema.queryTaggedValue('invariants', []): invariants.append("%s.%s" % (i.__module__, i.__name__)) result['invariants'] = invariants # Behavior serialization for schema in factory.behaviors or (): schema_serializer = get_multi_adapter((schema, self.request), ISchemaSerializeToJson) serialization = await schema_serializer() result['properties'][schema_serializer.name] = \ {'$ref': '#/definitions/' + schema_serializer.name}, result['definitions'][schema_serializer.name] = serialization behavior = get_utility(IBehavior, name=schema_serializer.name) definition = result['definitions'][schema_serializer.name] definition[ 'title'] = behavior.title or schema_serializer.short_name definition['description'] = behavior.description return result
async def __call__(self): factory = self.factory result = { 'title': factory.type_name, '$schema': 'http://json-schema.org/draft-04/schema#', 'type': 'object', 'required': [], 'definitions': {}, 'properties': {} } # Base object class serialized for name, field in get_fields_in_order(factory.schema): if field.required: result['required'].append(name) serializer = get_multi_adapter( (field, factory.schema, self.request), ISchemaFieldSerializeToJson) result['properties'][name] = await serializer() invariants = [] for i in factory.schema.queryTaggedValue('invariants', []): invariants.append("%s.%s" % (i.__module__, i.__name__)) result['invariants'] = invariants # Behavior serialization for schema in factory.behaviors or (): schema_serializer = get_multi_adapter( (schema, self.request), ISchemaSerializeToJson) serialization = await schema_serializer() result['properties'][schema_serializer.name] = \ {'$ref': '#/definitions/' + schema_serializer.name}, result['definitions'][schema_serializer.name] = serialization behavior = get_utility(IBehavior, name=schema_serializer.name) definition = result['definitions'][schema_serializer.name] definition['title'] = behavior.title or schema_serializer.short_name definition['description'] = behavior.description return result
async def controlpanel_element(context, request): url = getMultiAdapter((context, request), IAbsoluteURL)() type_id = request.matchdict["type_id"] registry = await get_registry() result = { "@id": f"{url}/@controlpanels/{type_id}", "group": "General", "title": "Validations Settings", "data": {}, } controlpanels = app_settings.get("controlpanels", {}) if type_id in controlpanels: schema = controlpanels[type_id].get("schema", None) if schema is None: return schemaObj = resolve_dotted_name(schema) config = registry.for_interface(schemaObj) schema = {"properties": {}, "fieldsets": [], "required": []} data = {} fields = [] for name, field in get_fields_in_order(schemaObj): if field.required: result["required"].append(name) serializer = get_multi_adapter((field, schemaObj, request), ISchemaFieldSerializeToJson) schema["properties"][name] = await serializer() data[name] = config.__getitem__(name) fields.append(name) schema["fieldsets"] = [{ "fields": fields, "id": "default", "title": "default" }] result["schema"] = schema result["data"] = data return result
def _callFUT(self, schema): from guillotina.schema import get_fields_in_order return get_fields_in_order(schema)