stoicperlman / falcon-openapi Goto Github PK
View Code? Open in Web Editor NEWAn OpenAPI first approach to Falcon APIs
License: MIT License
An OpenAPI first approach to Falcon APIs
License: MIT License
Falcon 2.0.0 brought breaking changes to the CompiledRouter.add_route() API. App launching fails with the error:
File "/home/tuohis/test/openapi_test.py", line 18, in <module>
router=OpenApiRouter(raw_json=json.dumps(spec))
File "/home/tuohis/test/.venv/lib/python3.5/site-packages/falcon_openapi/router.py", line 56, in __init__
self.add_route(path, method_map, Class)
File "falcon/routing/compiled.py", line 121, in falcon.routing.compiled.CompiledRouter.add_route
TypeError: add_route() takes exactly 3 positional arguments (4 given)
Hi,
Currently I wish to use OpenAPI schema as a contract between frontend and backend in my project.
However both js libs and falcon-openapi uses operationId and assumes different format (in js it is translated directly into method). Change of order of precedence would solve issue. Due to backward compatibility I propose to add parameter to OpenApiRouter
, which will switch from operationId first to x-falcon first if needed (for the sake of backward-compatibility).
Regards,
Adrian
This error occurs when:
test\
api\
controller.py
model\
model.py
app.py
api.yml
api.yaml
paths:
/controller:
get:
summary: summary
operationId: api.controller.controller1.on_get
app.py
import falcon
from falcon_openapi import OpenApiRouter
app = falcon.API(
router=OpenApiRouter(file_path='api.yml'),
)
model\ model.py
class model1:
pass
api\controller.py
from ..model.model import model1
class controller1(object):
def on_get(self, req, resp):
resp.body = 'test'
Traceback
Traceback (most recent call last):
...
...
...
File "/test/api/controller.py", line 1, in <module>
from ..model.model import model1
ValueError: attempted relative import beyond top-level package
I saw this in router.py. Look at the last line:
class OpenApiRouter(CompiledRouter):
def __init__(self, file_path='openapi-spec.yml', raw_json='', raw_yaml=''):
super().__init__()
if raw_json != '':
self.openapi = json.loads(raw_json)
elif raw_yaml != '':
self.openapi = yaml.load(raw_yaml)
else:
if not Path(file_path).exists() and file_path == 'openapi-spec.yml':
file_path = 'openapi-spec.yaml'
It seems that, if the user specified "openapi-spec.yml," they did not mean "openapi-spec.yaml."
I created a new example while testing out. As an aside, you are free to use this example for your project. I think it would be useful to show people that you need to qualify that the controllers are a part of the falcon-openapi module and importing from the users' own module to the falcon-openapi controllers need to be properly qualified on the import.
The problem I'm having is that the servers URI path is not being obeyed in the YAML file, e.g.:
---
info:
version: 0.0.0
title: Example
license:
name: MIT
servers:
- url: http://localhost/example/v1
paths:
"/health":
get:
summary: A simple health check.
responses:
200:
content:
application/json:
schema:
type: object
properties:
name: string
version: string
git_hash: string
x-falcon:
module: controllers.health
class: HealthCheck
method: on_get
I expect to need to access the controller with the URI: http://localhost:8000/example/v1/health
but only http://localhost:8000/health
works. Is this by design? I didn't have time to look at the implementation. You can see the sample project here.
โ High severity vulnerability found in pyyaml
Description: Arbitrary Code Execution
Info: https://snyk.io/vuln/SNYK-PYTHON-PYYAML-42159
Introduced through: [email protected]
From: [email protected] > [email protected]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.