Closed danigosa closed 6 years ago
see PR #561
from apistar import Route, App, types, validators
class ClientQueryType(types.Type):
sql = validators.String()
args = validators.Array(validators.Any(), allow_null=True, default=[])
class ModelQueryType(types.Type):
filters = validators.Object(allow_null=True, default={})
columns = validators.Array(validators.String(), allow_null=True, default=["*"])
def client(c: ClientQueryType):
pass
def model(m: ModelQueryType):
pass
routes = [
Route('/client/', method='POST', handler=client),
Route('/model/', method='POST', handler=model)
]
app = App(routes=routes)
app.serve('', 8000, debug=True)
generates this output:
$ curl http://localhost:8000/schema/
{
"openapi": "3.0.0",
"info": {
"title": "",
"description": "",
"version": ""
},
"paths": {
"/client/": {
"post": {
"operationId": "client",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ClientQueryType"
}
}
}
}
}
},
"/model/": {
"post": {
"operationId": "model",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ModelQueryType"
}
}
}
}
}
}
},
"components": {
"schemas": {
"ClientQueryType": {
"type": "object",
"properties": {
"sql": {
"type": "string"
},
"args": {
"default": [],
"nullable": true,
"type": "array",
"items": {}
}
},
"required": [
"sql"
]
},
"ModelQueryType": {
"type": "object",
"properties": {
"filters": {
"default": {},
"nullable": true,
"type": "object"
},
"columns": {
"default": [
"*"
],
"nullable": true,
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}
Ok then already referenced on #561
@danigosa that was my take on supporting Any
. I'm not sure yet if @tomchristie wanted to do it in this manner or he had other implementation ideas. I would recommend to keep this issue open until there are actual code changes and your tests verify functionality.
Not generating schema on
validators.Any
Type?apistar: 0.5.21 using ASYncApp
This is the piece of code (that works like a charm BTW):