cope-systems / bottle-swagger Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ampedandwired/bottle-swagger
A Bottle plugin for Swagger REST APIs
License: MIT License
This project forked from ampedandwired/bottle-swagger
A Bottle plugin for Swagger REST APIs
License: MIT License
I really like how express-openapi allows you to put your data structure definitions and security definitions in one place, and then place the swagger specification for the routes themselves together with the route implementation. It would be nice to do something similar with this (instead of having one massive Swagger file).
Items to do:
As a developer consuming this plugin, I would like to have an easy way to incorporate Swagger UI, so that I have ready to go API documentation without having to work too hard.
So, by default ignore_undefined_routes either filters everything that is not in the swagger spec (if it's set to true), or ignores everything if it is set to false. As a developer consuming this plugin, I want to be able to set one or more suburls to trigger the undefined route handler, so that I can potential use this plugin concurrently with other Swagger APIs or other non-Swagger routes, but have nice behavior for all sub-URLs known to belong to this specific Swagger instance.
As a developer consuming this plugin, I would like to be able to have relatively easy authentication support, similar to what Connexion or express-openapi provide, so that it's easy and intuitive to add authentication to an application using this plugin.
The single example application is a little rough, and I've now watched someone else (not naming names) look at it, and come away somewhat confused how to consume this library. Adding a few example applications with some diversity would be good, as well as fixing the one that's already there and adding some more documentation about how to consume the library.
From @ereboschi:
Looks like 2.0.6 fixes the exception. Much obliged.
Unfortunately, I just discovered that the SwaggerPlugin(serve_swagger_schema=False) doesn't work if serve_swagger_ui=True... Bottle still serves up /swagger.json (because self.serve_swagger_schema = serve_swagger_schema or serve_swagger_ui)... but I can open a second bug for that.
Thank you.
The fix should make swagger.json not be served when disabled (and frankly also check to make sure the built-in UI is not served when disabled), and provide some satisfactory tests to verify this behavior.
Problem:
Calling SwaggerPlugin with serve_swagger_schema=False
causes an exception due to a bug in SwaggerPlugin.__init__()
:
My Code:
bottle.install(SwaggerPlugin(
swagger_def=swagger_dict,
serve_swagger_ui=True,
swagger_ui_suburl='/swagger/',
serve_swagger_schema=False)) # We want to serve swagger.json ourselves, so we can set host dynamically
Exception: AttributeError: 'SwaggerPlugin' object has no attribute 'serve_swagger_ui'
Explanation:
SwaggerPlugin.__init__()
:
...
self.serve_swagger_schema = serve_swagger_schema or self.serve_swagger_ui
self.serve_swagger_ui = serve_swagger_ui
...
... self.serve_swagger_ui
is undefined on the first line, because that value isn't set until the second line. Apparently, this isn't a problem for most people, because the default value of serve_swagger_schema
is True
, so the second half of the or
statement is never evaluated (short-circuit).
This can be solved by changing the order of these lines. (Which would allow me to serve up swagger.json
myself.)
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.