- 授权协议: BSD
- 开发语言: Python
- 操作系统: 未知
- 软件首页: https://github.com/strongbugman/starchart
- 官方下载: https://github.com/strongbugman/starchart/release
软件介绍
Python Starlette WEB框架的OpenAPI扩展插件
功能
继承自
starlette.schemas.BaseSchemaGenerator支持OpenAPI 2和3版本
提供可配置的 SwaggerUI
安装
pip install -U starchart
例子
"""OpenAPI2(Swagger) example
"""
from functools import partial
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.endpoints import HTTPEndpoint
from uvicorn import run
from starchart.generators import SchemaGenerator
from starchart.endpoints import SwaggerUI, RedocUI, Schema
app = Starlette(debug=True)
app.schema_generator = SchemaGenerator(
title="Cat store",
description="Cat store api document",
version="0.1",
openapi_version="2.0",
)
# define data
CATS = {
1: {"id": 1, "name": "DangDang", "age": 2},
2: {"id": 2, "name": "DingDing", "age": 1},
}
# add schema definition
app.schema_generator.add_schema(
"Cat",
{
"properties": {
"id": {"description": "global unique", "type": "integer"},
"name": {"type": "string"},
"age": {"type": "integer"},
},
"type": "object",
},
)
# define routes and schema(in doc string)
@app.route("/cat/")
class Cat(HTTPEndpoint):
def get(self, req: Request):
"""
summary: Get single cat
tags:
- cat
parameters:
- name: id
type: integer
in: query
required: True
responses:
"200":
description: OK
schema:
$ref: '#/definitions/Cat'
"404":
description: Not found
"""
return JSONResponse(CATS[1])
def delete(self, req: Request):
"""
summary: Delete single cat
tags:
- cat
parameters:
- name: id
type: integer
in: query
required: True
responses:
"204":
description: OK
schema:
$ref: '#/definitions/Cat'
"404":
description: Not found
"""
cat = CATS.pop(1)
return JSONResponse(cat)
# define doc by yaml or json file
@app.route("/cats/", methods=["GET"])
@app.schema_generator.schema_from("./examples/docs/cats_get.yml")
def list_cats(req: Request):
return JSONResponse(list(CATS.values()))
@app.route("/cats/", methods=["POST"])
@app.schema_generator.schema_from("./examples/docs/cats_post.json")
async def list_cats(req: Request):
cat = await req.json()
CATS[cat["id"]] = cat
return JSONResponse(cat)
# add document's endpoints
schema_path = "/docs/schema/"
app.add_route(
"/docs/swagger/",
SwaggerUI,
methods=["GET"],
name="SwaggerUI",
include_in_schema=False,
)
app.add_route(
"/docs/redoc/", RedocUI, methods=["GET"], name="SwaggerUI", include_in_schema=False
)
app.add_route(
schema_path, Schema, methods=["GET"], name="SwaggerSchema", include_in_schema=False
)
# config endpoints
SwaggerUI.set_schema_url(schema_path)
RedocUI.set_schema_url(schema_path)
Schema.set_schema_loader(partial(app.schema_generator.get_schema, app.routes))
run(app)
Java常用算法手册
2012-5 / 59.00元
《Java常用算法手册》分三篇,共13章,分别介绍了算法基础、算法应用和算法面试题。首先介绍了算法概述,然后重点分析了数据结构和基本算法思想;接着,详细讲解了算法在排序、查找、数学计算、数论、历史趣题、游戏、密码学等领域中的应用;最后,列举了算法的一些常见面试题。书中知识点覆盖全面,结构安排紧凑,讲解详细,实例丰富。全书对每一个知识点都给出了相应的算法及应用实例,虽然这些例子都是以Java语言来编......一起来看看 《Java常用算法手册》 这本书的介绍吧!
