Comments (12)
I implemented a new decorator: jsonapi_rpc.
Can you try the following please?
from safrs.db import jsonapi_rpc
...
@classmethod
@jsonapi_rpc(http_methods = ['GET'])
def search(*args):
...
?
I am going to keep the jsonapi_rpc
name but the generated swagger schema will need to be improved.
from safrs.
OK, I will try this out. Thanks.
I will let you know if this fits.
from safrs.
An example is implemented here: https://github.com/thomaxxl/safrs/blob/master/examples/demo_relationship.py
from safrs.
solved
from safrs.
Hi my i am using Flask-Python for rest api creation,
i have my two different .py(i.e models.py,Init.py).
I have "EmployeeInfo" class in my "model.py" file and "get_dept_info" in my init.py file.
I cannot change the structure. Following Are my class and method declaration.
class EmployeeInfo(SAFRSBase,db.Model):
'''
description: EmployeeInfo
'''
tablename = 'employee_info'
employee_id = db.Column(db.String(45), primary_key=True, nullable=False)
first_name = db.Column(db.String(30), nullable=False)
@classmethod
@jsonapi_rpc(http_methods=['POST','GET'])
@login_required
def get_dept_info():
"""
Find different type of dept present in employee_info table
"""
try:
with get_session() as session:
# employee_info
dept_details_list = session.query(EmployeeInfo.dept_id, EmployeeInfo.dept_name).distinct().all()
if dept_details_list:
# Adding an option of 'Other' for 'dept_name'.
# This option will be used for scenarios where visitors does not know about
# department of employee (contact person)
dept_details_list.append({'dept_name': 'Other', 'dept_id': 999})
dept_details_schema_list = DeptDetailsSchema(many=True)
response = dept_details_schema_list.dump(dept_details_list) # python object [List, Dictionary]
# response = users_schema.dumps(all_users) # json encoded string object
return make_response(jsonify(response), 200)
else:
message = 'No departments found in EmployeeInfo table'
return make_400_response(message, 400)
except Exception as e:
print(e)
message = 'Exception Occurred : Failed to fetch department details'
message = utils.generate_exception_message(message, e)
return make_400_response(message, 400)
I want only methods created by me in the swaggerUI.
but by using following decorations on the method i am not able to the see the api endpoint in the swagger.
from safrs.
Hi,
can you open a new issue for new problems please?
The syntax of your get_dept_info is missing an argument, f.i.:
@classmethod
@jsonapi_rpc(http_methods=['POST','GET'])
def get_dept_info(cls):
return {1:1}
from safrs.
Hi my i am using Flask-Python for rest api creation,
i have my two different .py(i.e models.py,Init.py).
I have "EmployeeInfo" class in my "model.py" file and "get_dept_info" in my init.py file.
I cannot change the structure. Following Are my class and method declaration.
class EmployeeInfo(SAFRSBase,db.Model):
'''
description: EmployeeInfo
'''
tablename = 'employee_info'
employee_id = db.Column(db.String(45), primary_key=True, nullable=False)
first_name = db.Column(db.String(30), nullable=False)
@classmethod
@jsonapi_rpc(http_methods=['POST','GET'])
@login_required
def get_dept_info():
"""
Find different type of dept present in employee_info table
"""
try:
with get_session() as session:
# employee_info
dept_details_list = session.query(EmployeeInfo.dept_id, EmployeeInfo.dept_name).distinct().all()
if dept_details_list:
# Adding an option of 'Other' for 'dept_name'.
# This option will be used for scenarios where visitors does not know about
# department of employee (contact person)
dept_details_list.append({'dept_name': 'Other', 'dept_id': 999})
dept_details_schema_list = DeptDetailsSchema(many=True)
response = dept_details_schema_list.dump(dept_details_list) # python object [List, Dictionary]
# response = users_schema.dumps(all_users) # json encoded string object
return make_response(jsonify(response), 200)
else:
message = 'No departments found in EmployeeInfo table'
return make_400_response(message, 400)
except Exception as e:
print(e)
message = 'Exception Occurred : Failed to fetch department details'
message = utils.generate_exception_message(message, e)
return make_400_response(message, 400)
I want only methods created by me in the swaggerUI.
but by using following decorations on the method i am not able to the see the api endpoint in the swagger.
from safrs.
Hi,
Can you check if it works for you?
https://gist.github.com/thomaxxl/8558210e3064cc205f290259493292fb
from safrs.
@thomaxxl thank you for the quick reply i will try this solution, though i have some questions
-
I am using Flask core functionality and blueprint for creation of project, we are not using restful/restplus anywhere in the project. will this plugin support that architecture.
-
My model class and my method are are separate files how can this code will be able to handle that.
from safrs.
- Yes, safrs just registers a different blueprint at the
prefix
which can be provided as an arg to SAFRSAPI - Yes, you have you assign the method to the class before exposing it
from safrs.
@thomaxxl i tried those things but i have one main question to ask
I only want Methods that are exposed externally i don't want any automatically generated api endpoint i want following structure is it possible to get the same directly or do we need to change the code a bit.
from safrs.
Hi,
you'd have to modify the _api.Api class for that:
the endpoints are created with the Api.expose_*
methods (which call Api.add_resource()
)
so, if you add a return directly after expose_methods()
, that would be what you want.
...
# Expose the methods first
self.expose_methods(url_prefix, tags=tags)
return # << Add the return here
...
Safrs is mainly designed to provide crud operations though, so I'm not sure if this is the right framework for what you're trying to do.
from safrs.
Related Issues (20)
- Invalid swagger for "properties" under "definitions" breaks defintions display and validation HOT 7
- Patch method unreliable? HOT 2
- Read-only Columns HOT 2
- Flask-SQLAlchemy weakref KeyError
- in version 3.0 _s_count function does not apply filters to query HOT 1
- `count` property value is wrong for `GET` methods HOT 1
- Unable to delete entries HOT 5
- overriding methods does not work HOT 2
- extend API with custom classes HOT 1
- requirements.txt too restrictive HOT 1
- Duplicate definitions generated HOT 5
- safrs doesn't work in python 3.9 - TypeError HOT 4
- expose_existing starts but no swagger.json found HOT 1
- Run in example demo_relationship.py creating users or books in flask_admin returns Integrity Errors HOT 17
- Doubts about SAFRS HOT 2
- JSONAPI relationship missing in the swagger documentation HOT 4
- Swagger generation removing plurals HOT 1
- Flask 2.0 / Flask-restful "ImportError: cannot import name '_endpoint_from_view_func'" HOT 1
- Possible issue with BIGINT primary keys? HOT 5
- Make many to many relationship methods extendable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from safrs.