def add_table_model(table_cls): global _mapping global _model_write_one, _model_write_multi global _model_read_one, _model_read_multi table_name = table_cls.__tablename__ columns = table_cls.__table__.columns read_fields = { key: _mapping[type(columns[key].type)](required=True) for key in columns.keys() if type(columns[key].type) in _mapping } write_fields = read_fields.copy() for col_name, column in columns.items(): if type(column.autoincrement) == bool and column.autoincrement is True: # print('removing autoincrement field ' + table_name + '.' + column.name) write_fields.pop(col_name) write_one = api.model(table_name + '_w', write_fields) _model_write_one[table_name] = write_one _model_write_multi = api.inherit( table_name + '_list_w', pagination, {'items': fields.List(fields.Nested(write_one), required=True)}) _model_read_one[table_name] = api.model(table_name, read_fields) _model_read_multi[table_name] = api.inherit( table_name + '_list', pagination, { 'items': fields.List(fields.Nested(_model_read_one[table_name]), required=True) })
}) dataset_kpis = api.model( 'Dataset stats', { 'number_lines': fields.Integer(readOnly=True, description='Number lines containt in datset'), 'number_bad_line': fields.Integer(readOnly=True, description='Number bad lines containt in datset'), 'bad_lines': fields.List(fields.Integer), }) dataset_response_succes = api.inherit( 'Dataset of results', dataset_head, {'kpis': fields.List(fields.Nested(dataset_kpis))}) pagination = api.model( 'A page of results', { 'page': fields.Integer(description='Number of this page of results'), 'pages': fields.Integer(description='Total number of pages of results'), 'per_page': fields.Integer(description='Number of items per page of results'), 'total': fields.Integer(description='Total number of results'), }) page_of_dataset = api.inherit('Page of dataset', pagination,
from flask_restplus import fields from api.restplus import api authors = api.model('authors', { 'literal': fields.String(readOnly=True, description='Literal name'), 'given': fields.String(readOnly=True, description='Given name'), 'family': fields.String(readOnly=True, description='Family anme'), }) works = api.model('works', { 'title': fields.String(readOnly=True, description='Article title'), 'authors': fields.List(fields.Nested(authors)), 'description': fields.String(readOnly=True, description='Description of the article'), 'year': fields.String(readOnly=True, description='Publication date of article'), 'doi': fields.String(readOnly=True, description='Doi reference'), 'access_constraints': fields.String(readOnly=True, description='Access constraints'), }) works_list = api.inherit('works list', works, { 'items': fields.List(fields.Nested(works)) })
from flask_restx import fields from api.restplus import api location = api.model('Resource Location', { 'location': fields.String(required=True) }) message = api.model('Message', { 'message': fields.String(required=True) }) bad_request = api.inherit('Bad request', message, { 'erorrs': fields.Wildcard(fields.String) }) category_output = api.model('Category Output', { 'id': fields.Integer(required=True), 'name': fields.String(required=True, description='Category name') }) category_input = api.model('Category Input', { 'name': fields.String(required=True, description='Category name') }) generic_file_output = api.model('Generic File Output', { 'id': fields.Integer(required=True), 'file_name': fields.String(required=True), 'link': fields.String(required=True), 'created_at': fields.String(required=True)
}) pagination = api.model( 'A page of results', { 'page': fields.Integer(description='Number of this page of results'), 'pages': fields.Integer(description='Total number of pages of results'), 'per_page': fields.Integer(description='Number of items per page of results'), 'total': fields.Integer(description='Total number of results'), }) page_of_blog_posts = api.inherit( 'Page of blog posts', pagination, {'items': fields.List(fields.Nested(blog_post))}) category = api.model( 'Blog category', { 'id': fields.Integer(readOnly=True, description='The unique identifier of a blog category'), 'name': fields.String(required=True, description='Category name'), }) category_with_posts = api.inherit( 'Blog category with posts', category, {'posts': fields.List(fields.Nested(blog_post))})
from api.restplus import api health = api.model('Health check', { 'status': fields.String(required=True, description='Overall status of application') }) new_listing = api.model('NewListing', { 'message': fields.String(required=True, description='Server response for a new listing') }) listing = api.model('Listing', { 'description': fields.String(required=True, description='Description of listing item'), 'title': fields.String(required=True, description='Title of the listing'), 'license': fields.String(required=True, description='Usage license'), 'listing': fields.String(required=True, description='The listing this upload belongs to'), 'file_upload': fields.String(required=False, description='File asset for a listing submitted as form-data'), 'file_type': fields.String(required=True, description='File content: video, image, audio, etc'), 'md5_sum': fields.String(required=True, description='md5 sum of the file being uploaded'), 'tags': fields.List(fields.String, required=False, description='Tags to categorize and describe the listing file') }) pagination = api.model('Page results descriptor', { 'page': fields.Integer(description='Number of this page of results'), 'pages': fields.Integer(description='Total number of pages of results'), 'per_page': fields.Integer(description='Number of items per page of results'), 'total': fields.Integer(description='Total number of results') }) list_of_listings = api.inherit('List of listings', { 'items': fields.List(fields.Nested(listing)) })
vul_record = api.model( 'vul record', { 'ID': fields.Integer( readOnly=True, description='The unique identifier of vulnerability record'), 'VULN_ID': fields.String(required=True, description='vulnerability id'), 'SERVICE_ID': fields.Integer(attribute='services.SERVICE_ID'), 'services': fields.String(attribute='services.SERVICE'), }) service_with_vulnerabilities = api.inherit( 'service with vulnerabilities', service, {'vulnerabilities': fields.List(fields.Nested(vul_record))}) domain_profile = api.model( 'domain profile', { 'DOMAIN_PROFILE_ID': fields.Integer(readOnly=True, description='Unique identifer of domain profile'), 'GBU_ID': fields.Integer(attribute='gbus.GBU_ID'), 'GBU': fields.String(attribute='gbus.GBU'), 'CONFIDENTIALITY_IMPACT': fields.Integer(required=True, description='confidentiality impact rating'), 'INTEGRITY_IMPACT':