从 JSON 方案创建虚假 JSON 文件
jsf
Use jsf along with fake data generators to provide consistent and meaningful fake data for your system.
from jsf import JSF
faker = JSF(
{
"type": "object",
"properties": {
"name": {"type": "string", "$provider": "faker.name"},
"email": {"type": "string", "$provider": "faker.email"},
},
"required": ["name", "email"],
}
)
fake_json = faker.generate()Results in ...
{
'name': 'Jesse Phillips',
'email': '[email protected]'
}from jsf import JSF
faker = JSF.from_json("demo-schema.json")
fake_json = faker.generate()Or run straight from the commandline...
pip install jsf[cli]
jsf --schema jsf/tests/data/custom.json --instance wow.jsondocker run -v $PWD:/data challisa/jsf jsf --schema /data/custom.json --instance /data/example.jsonCreate a file main.py with:
from jsf import JSF
from fastapi import FastAPI
app = FastAPI(docs_url="/")
generator = JSF.from_json("custom.json")
@app.get("/generate", response_model=generator.pydantic())
def read_root():
return generator.generate()
Run the server with:
contentMediaType - only a subset of these are supported, however they can be expanded within this file暂无开放 Issues,或尚未同步最近议题。