def test_inherit_from_multiple_parents(self): api = Namespace('test') grand_parent = api.model('GrandParent', {}) parent = api.model('Parent', {}) api.inherit('Child', grand_parent, parent, {}) assert 'GrandParent' in api.models assert 'Parent' in api.models assert 'Child' in api.models
def test_inherit_from_multiple_parents(self): api = Namespace("test") grand_parent = api.model("GrandParent", {}) parent = api.model("Parent", {}) api.inherit("Child", grand_parent, parent, {}) assert "GrandParent" in api.models assert "Parent" in api.models assert "Child" in api.models
def test_inherit(self): authorizations = { "apikey": { "type": "apiKey", "in": "header", "name": "X-API-KEY" } } api = Namespace("test", authorizations=authorizations) parent = api.model("Parent", {}) api.inherit("Child", parent, {}) assert "Parent" in api.models assert "Child" in api.models assert api.authorizations == authorizations
def test_inherit(self): authorizations = { 'apikey': { 'type': 'apiKey', 'in': 'header', 'name': 'X-API-KEY' } } api = Namespace('test', authorizations=authorizations) parent = api.model('Parent', {}) api.inherit('Child', parent, {}) assert 'Parent' in api.models assert 'Child' in api.models assert api.authorizations == authorizations
}) meta_information_model = api.model( "Metadata Information", { "state": fields.String(), "deprecated": fields.Boolean(), "change_log": fields.List(fields.Nested(change_log)) }) study_model = api.model( "Study", { "entries": fields.List(fields.Nested(entry_model)), "meta_information": fields.Nested(meta_information_model), }) study_model_id = api.inherit("Study with id", study_model, {"id": fields.String()}) field_add_model = api.model( "Add Field", { "property": fields.String(example="Property Object Id"), "value": fields.Raw() }) study_add_model = api.model( "Add Study", { "form_name": fields.String(example="Form Object Id", required=True), "initial_state": fields.String(default="generic_state", required=True, description="The initial state name"),
patientDao = PatientDao() updateService = UpdateService() newAlleryDetail = api.model( 'NewAllergy', { 'allergicTo': fields.String(required=True, description='patient is allergic to'), 'onMedication': fields.Boolean( required=True, description=' true if patient is using medication, false otherwise' ) }) patientAllergies = api.inherit( 'PatientAllergy', newAlleryDetail, {'id': fields.Integer(required=True, description='unique identifier')}) newIllnessDetail = api.model( 'NewIllness', { 'illness': fields.String(required=True, description='patient having illness'), 'onMedication': fields.Boolean( required=True, description=' true if patient is using medication, false otherwise' ) }) patientIllness = api.inherit( 'PatientIllness', newIllnessDetail,
fields.String(required=True, description='patient last name'), 'email': fields.String(required=True, description='patient email address'), 'contactNumber': fields.Integer(required=True, description='patient contact Number'), 'consentToShare': fields.Boolean(required=True, description='patient consent to share information'), 'dob': fields.String(required=True, description='patient date of birth'), 'age': fields.Integer(required=True, description='patient age') }) updatedPatient = api.inherit('Update Patient', newPatient, { 'changedBy': fields.String(required=True, description='the updating user id') }) patient = api.inherit( 'Patient', newPatient, {'id': fields.String(required=True, description='unique patient id')}) @api.route('patient') class PatientList(Resource): @api.doc('list patients') @api.marshal_list_with(patient) def get(self): '''returns a list of all patients''' return patientDao.fetchAllPatients()
) auth_ns = Namespace("auth") auth_user = auth_ns.model( "auth_user", { "email": fields.String(required=True, example="*****@*****.**"), "user_name": fields.String(requried=True, example="some_user"), }, ) auth_password = auth_ns.inherit( "auth_password", auth_user, { "password": fields.String(required=True), }, ) auth_token = auth_ns.inherit( "auth_token", auth_user, { "access_token": fields.String, "token_type": fields.String(example="bearer"), "expires_in": fields.Integer(example=3600), }, ) auth_status = auth_ns.inherit(
"PageInfo", dict( current=fields.Integer(example=0, required=True), max_page=fields.Integer(example=1, required=True), ), ) api.models[SuccessModel.name] = SuccessModel api.models[ErrorModel.name] = ErrorModel ListMessagesModel = api.inherit( "ListMessagesModel", SuccessModel, data_wrap( api, "ListMessagesData", messages=fields.List(fields.Nested(MessageBriefModel, required=True), required=True), pageInfo=fields.Nested(PageInfoModel, required=True) ), ) ListMessagesFailModel = api.model( "ListMessagesFailModel", data_wrap( api, "ListMessagesFail", token=fields.String(example="malformed token"), page=fields.Integer(example="page out of bounds"), ), )
from project.api.users.services import get_user_by_email # noqa isort:skip from project.api.users.services import get_user_by_id # noqa isort:skip from project.api.users.services import add_user # noqa isort:skip auth_namespace = Namespace("auth") user = auth_namespace.model( "User", { "username": fields.String(required=True), "email": fields.String(required=True) }, ) full_user = auth_namespace.inherit("Full User", user, {"password": fields.String(required=True)}) login = auth_namespace.model( "User", { "email": fields.String(required=True), "password": fields.String(required=True) }, ) refresh = auth_namespace.model("Refresh", {"refresh_token": fields.String(required=True)}) tokens = auth_namespace.inherit("Access and refresh_tokens", refresh, {"access_token": fields.String(required=True)})
}, ) form_model_ni = api.clone( "Forms (no cv items)", form_model, { "fields": fields.List(fields.Nested(field_model_ni)), }, ) form_model_id = api.inherit( "Form with id", form_model, { "id": fields.String(attribute="pk", description="Unique identifier of the entry"), }, ) form_model_ni_id = api.inherit( "Form with id (no cv items)", form_model_ni, { "id": fields.String(attribute="pk", description="Unique identifier of the entry"), }, )
) ns = Namespace("Ingredients", description="Ingredient Operations") response_env = ns.model(response_envelope.get("name"), response_envelope.get("fields")) meta_env = ns.model(meta_envelope.get("name"), meta_envelope.get("fields")) links_env = ns.model(links_envelope.get("name"), links_envelope.get("fields")) get_ingredient_model = ns.clone( "get_ingredient_model", response_env, {"data": fields.Raw} ) get_ingredient_list_model = ns.inherit( "get_ingredient_list_model", response_env, { "data": fields.List(fields.Raw), "_meta": fields.Nested(meta_env), "_links": fields.Nested(links_env), }, ) @ns.route("", endpoint="list_ingredients") @ns.response(HTTPStatus.OK.value, HTTPStatus.OK.phrase, model=get_ingredient_list_model) @ns.response(HTTPStatus.BAD_REQUEST.value, HTTPStatus.BAD_REQUEST.phrase) @ns.response( HTTPStatus.SERVICE_UNAVAILABLE.value, HTTPStatus.SERVICE_UNAVAILABLE.phrase ) class IngredientListResource(Resource): """Ingredient List Resource"""
description="Internal representation of the entry (in snake_case)" ), "description": fields.String(description="Detailed description of the intended use", default=""), "items": fields.List(fields.Nested(cv_item_model, skip_none=True)), "deprecated": fields.Boolean( description="Indicator, if the entry is no longer used.", default=False) }) ctrl_voc_model_id = api.inherit( "Controlled Vocabulary with id", ctrl_voc_model, { "id": fields.String(attribute="pk", description="Unique identifier of the entry"), }) post_response_model = api.model( "Post response", { "message": fields.String(), "id": fields.String(description="Id of inserted entry") }) # Routes # ---------------------------------------------------------------------------------------------------------------------- @api.route("") class ApiControlledVocabulary(Resource):
}, ) property_model_ni = api.clone( "Property (no cv items)", property_model, { "value_type": fields.Nested(cv_model_ni), }, ) property_model_id = api.inherit( "Property with id", property_model, { "id": fields.String(attribute="id", description="The unique identifier of the entry"), }, ) property_model_ni_id = api.inherit( "Property with id (no cv items)", property_model_ni, { "id": fields.String(attribute="id", description="The unique identifier of the entry"), }, )
event_status_parser = token_parser.copy() event_all_parser = token_parser.copy() event_download_parser = token_parser.copy() event_add_parser = token_parser.copy() event_add_parser.add_argument('additionalNumberOfTickets', type=natural_num_type, required=True, location='json') # Models event_create_model = api.inherit( 'EventCreateData', status_message_model, { 'eventIdentifier': fields.String(required=True, description='The unique identifier of the event.') }) status_data_model = api.model( 'EventStatusData', { 'name': fields.String(required=True, description='Name of the event.'), 'date': fields.Date(required=True, description='Date of the event.'), 'number_of_tickets': fields.Integer( required=True, description='The total number of tickets of the event.'), 'number_of_redeemed_tickets': fields.Integer(
"Nested study entry (prop id)", { "entries": fields.List(fields.Nested(entry_model_prop_id)), "entry_format": fields.String( example="api", description="Format used for entries (api or form)" ), "form_name": fields.String(example="form_name", required=True), "manual_meta_information": fields.Raw(), }, ) study_add_model = api.inherit( "Add Study", nested_study_entry_model, { "initial_state": fields.String( default="GenericState", required=True, description="The initial state name" ), }, ) # Common parser params # ---------------------------------------------------------------------------------------------------------------------- entry_format_param = { "type": str, "location": "args", "choices": ("api", "form"), "default": "api", "help": "Format used for entries (api or form)", }
'NewCareProvider', { 'first_name': fields.String(required=True, description='CareProvider first name'), 'last_name': fields.String(required=True, description='CareProvider last name'), 'dob': fields.String(required=True, description='CareProvider date of birth'), 'email': fields.String(required=True, description='CareProvider email id') }) careProvider = api.inherit( 'CareProvider', newCareProvider, { 'id': fields.String(required=True, description='unique careProvider id'), 'per_visit_charges': fields.String(required=True, description='careProvider per_visit_charges'), 'status': fields.String(required=True, description='careProvider status') }) updateCareProvider = api.inherit( 'UpdateCareProvider', newCareProvider, { 'per_visit_charges': fields.String(required=True, description='careProvider per_visit_charges'), 'changedBy': fields.String(required=True, description='the updating user Id'), 'status': fields.String(required=True, description='admin status') })
address = api.model( 'Address', { 'address_line_1': fields.String(required=True, description='patient address line 1'), 'address_line_2': fields.String(description='patient address line 2'), 'city': fields.String(required=True, description='patient city'), 'postCode': fields.Integer(required=True, description='patient postCode'), 'country': fields.String(required=True, description='patient country') }) updateAddress = api.inherit('UpdateAddress', address, { 'changedBy': fields.String(required=True, description='the updating user id') }) patientAddress = api.inherit('PatientAddress', address, { 'patientId': fields.String(required=True, description='unique patient id') }) @api.route('patient/<id>/address') @api.param('id', 'patient identifier') @api.response(404, 'Resource Not found') class PatientAddress(Resource): @api.doc('get Patient address') @api.marshal_with(patientAddress) def get(self, id):
user_model = api.model( "User", { "firstname": fields.String(), "lastname": fields.String(), "email": fields.String(), "password": fields.String(), "is_active": fields.Boolean(default=True), }, ) user_model_id = api.inherit( "User with id", user_model, { "id": fields.String(attribute="pk", description="Unique identifier of the entry"), }, ) post_response_model = api.model( "Post response", { "message": fields.String(), "id": fields.String(description="Id of inserted entry"), }, ) login_model = api.model( "Login",
from flask_restx import Namespace, fields, Resource from flask import request from librusapi.token import get_token from librusapi.exceptions import AuthorizationError from api.api import ErrorResponse, SuccessResponse, ErrorModel, SuccessModel, data_wrap, DefaultModel api = Namespace("Authentication", path="/auth") api.models[DefaultModel.name] = DefaultModel api.models[ErrorModel.name] = ErrorModel api.models[SuccessModel.name] = SuccessModel TokenModel = api.inherit( "TokenModel", SuccessModel, data_wrap( api, "Token", token=fields.String(required=True), ), ) @api.route("/") class AuthorizeToken(Resource): @api.doc(security="Authorization Basic") @api.header("Authorization", "Authorization: Basic base64(username:password)", required=True) @api.response(200, "Success", TokenModel) @api.response(400, "Validation Error", ErrorModel) @api.response(401, "Authorization Error", ErrorModel)
api = Namespace('patientNote', description='Patients Note related operations') patientDao = PatientDao() updateService = UpdateService() newPatientNote = api.model( 'NewPatientNote', { 'note': fields.String(required=True, desctiption='note to be added'), 'writtenBy': fields.String(required=True, description='care Provider Id') }) patientNotes = api.inherit( 'PatientNotes', newPatientNote, { 'id': fields.Integer(description='note id'), 'patientId': fields.String(required=True, desctiption='patient id'), 'writtenOn': fields.String(description='date when the note was written') }) @api.route('patient/<id>/note') @api.param('id', 'patient identifier') @api.response(404, 'Resource Not found') class PatientNote(Resource): @api.doc('get Patient notes') @api.marshal_with(patientNotes) def get(self, id): '''returns the notes for a specific patient''' return patientDao.getPatientNotes(id), 200
"model": fields.Nested(machine_model_model), "telemetry": fields.List( fields.Nested(machine_telemetry_model, attribute=get_telemetry)), "errors": fields.List( fields.Nested(machine_errors_model, attribute=lambda x: MachineErrorsModel.objects( machine=x).order_by("+date").limit(64))), "maintenance": fields.List(fields.Nested(machine_maintenance_model)) }) machines_model = machine_ns.inherit( "Machines", pagination_model, {"machines": fields.List(fields.Nested(machine_model), attribute="items")}) # Resources @machine_ns.route("/") class Machines(Resource): @machine_ns.marshal_with(machines_model) def get(self): args = paging_parser.parse_args() return MachineModel.objects.paginate(page=args["page"], per_page=args["per_page"]) @machine_ns.marshal_with(machine_model) @machine_ns.expect(post_machine_parser)
"email": fields.String(required=True), "role": fields.String(required=True), "created_date": fields.DateTime, "failed_attempts": fields.Integer, "failed_attempt_timer": fields.DateTime, "get_points_alert": fields.Boolean, "get_order_alert": fields.Boolean, "get_problem_alert": fields.Boolean, "preferred_contact": fields.String(required=False), "sponsor_logo": fields.String(required=False), "sponsor_headline": fields.String(required=False), "sponsor_slug": fields.String(required=False) }, ) user_post = users_namespace.inherit("User post", user, {"password": fields.String(required=True)}) class UsersList(Resource): @users_namespace.marshal_with(user, as_list=True) @users_namespace.doc(params={ "username": "******", "email": "String", "role": "String" }) def get(self): """Returns all users.""" return get_all_users(), 200 @users_namespace.doc(params={ "username": "******",
"name": fields.String( description="Internal representation of the entry (in snake_case)" ), "description": fields.String( description="Detailed description of the intended use", default="" ), "deprecated": fields.Boolean( description="Indicator, if the entry is no longer used.", default=False ), }, ) ctrl_voc_model = api.inherit( "Controlled Vocabulary", ctrl_voc_model_no_items, { "items": fields.List(fields.Nested(cv_item_model, skip_none=True)), }, ) ctrl_voc_model_id_no_items = api.inherit( "Controlled Vocabulary (no items) with id", ctrl_voc_model_no_items, { "id": fields.String( attribute="pk", description="Unique identifier of the entry" ), }, ) ctrl_voc_model_id = api.inherit(
description="How much a night costs in the rental place"), "images": fields.List( fields.Nested(publication_image_model), required=True, description="List of images URLs", ), }, ) new_publication_model = api.inherit( "New Publication Model", base_publication_model, { "loc": fields.Nested( loc_model, required=True, description="Location of the rental place", ), }, ) publication_patch_model = api.model( 'Publication patch model', { "blockchain_status": fields.String( required=False, description="The status on the blockchain", enum=[x.value for x in BlockChainStatus], default=BlockChainStatus.UNSET.value,
ns = Namespace("Users", description="User Operations") response_env = ns.model(response_envelope.get("name"), response_envelope.get("fields")) meta_env = ns.model(meta_envelope.get("name"), meta_envelope.get("fields")) links_env = ns.model(links_envelope.get("name"), links_envelope.get("fields")) user_model = ns.model(UserSchema.get_restx_model().name, UserSchema.get_restx_model()) get_user_model = ns.clone( "get_user_model", response_env, {"data": fields.Nested(user_model)} ) get_user_list_model = ns.inherit( "get_user_list_model", response_env, { "data": fields.List(fields.Nested(user_model)), "_meta": fields.Nested(meta_env), "_links": fields.Nested(links_env), }, ) @ns.route("/<int:user_id>", endpoint="get_user") @ns.response(HTTPStatus.OK.value, HTTPStatus.OK.phrase) @ns.response(HTTPStatus.BAD_REQUEST.value, HTTPStatus.BAD_REQUEST.phrase) @ns.response( HTTPStatus.SERVICE_UNAVAILABLE.value, HTTPStatus.SERVICE_UNAVAILABLE.phrase ) @ns.response(HTTPStatus.UNAUTHORIZED.value, HTTPStatus.UNAUTHORIZED.phrase) @ns.doc(security="apiKey") class UserResource(Resource):
updateService = UpdateService() api = Namespace('admin', description='Admin related operations') newAdmin = api.model( 'NewAdmin', { 'first_name': fields.String(required=True, description='admin first name'), 'last_name': fields.String(required=True, description='admin last name'), 'dob': fields.String(required=True, description='admin date of birth'), 'email': fields.String(required=True, description='admin email id') }) admin = api.inherit( 'Admin', newAdmin, { 'id': fields.String(required=True, description='unique admin id'), 'status': fields.String(required=True, description='admin status') }) updateAdmin = api.inherit( 'UpdateAdmin', newAdmin, { 'status': fields.String(required=True, description='admin status'), 'changedBy': fields.String(required=True, description='userId of the user performing the update') }) @api.route('admin') class AdminList(Resource):
}, ) booking_model = api.inherit( "Created booking", new_booking_model, { "blockchain_status": fields.String( required=True, description="The status on the blockchain", enum=[x.value for x in BlockChainStatus], attribute='blockchain_status.value', ), "blockchain_transaction_hash": fields.String( required=False, description="The hash of the transaction on the blockchain"), "blockchain_id": fields.Integer(required=False, description="The id on the blockchain"), "booking_status": fields.String( required=True, description="The status of the booking", enum=[x.value for x in BookingStatus], attribute="booking_status.value", ), }, ) bookings_parser = reqparse.RequestParser() bookings_parser.add_argument(
delete_user, get_all_deliveries, get_delivery_by_id, add_delivery, update_delivery_status, delete_delivery, ) users_namespace = Namespace("users") user = users_namespace.model( "User", { "id": fields.Integer(readOnly=True), "username": fields.String(required=True), "email": fields.String(required=True), "created_date": fields.DateTime, }, ) user_post = users_namespace.inherit("User post", user, {"password": fields.String(required=True)}) class UsersList(Resource): @users_namespace.marshal_with(user, as_list=True) def get(self): """Returns all users.""" return get_all_users(), 200 @users_namespace.expect(user_post, validate=True) # updated @users_namespace.response(201, "<user_email> was added!") @users_namespace.response(400, "Sorry. That email already exists.") def post(self): """Creates a new user.""" post_data = request.get_json() username = post_data.get("username")
todos = {} count = 1 Todo = Namespace(name='Todo', description='desc - todo name space blablabla...') todo_fields = Todo.model( 'Todo', { 'data': fields.String( description='a Todo', required=True, example="What to do") }) todo_fields_with_id = Todo.inherit( 'Todo with ID', todo_fields, {'todo_id': fields.Integer(description='a Todo ID')}) @Todo.route('') class TodoPost(Resource): @Todo.expect(todo_fields) @Todo.response(201, 'Success', todo_fields_with_id) def post(self): """Todo 리스트에 할 일을 등록 합니다.""" global count global todos idx = count count += 1 todos[idx] = request.json.get('data')