import requests from datetime import datetime from flask_pydantic_spec import FlaskPydanticSpec, Response from .models import db_wrapper, Build from .celery import make_celery BUILD_NAMESPACE = uuid.UUID('dc3606bb-8007-454f-8974-09cd2a517f14') app = Flask(__name__) app.config.from_object(config) db_wrapper.init_app(app) celery = make_celery(app) api = FlaskPydanticSpec('flask') api.register(app) @app.route('/', methods=['GET']) @api.validate(resp=Response('HTTP_203'), tags=['test', 'demo']) def with_code_header(): """ Esto no le des pelota que soy yo boludeando con pydantic """ return jsonify(language=request.context.headers.Lang), 203, {'X': 233} @app.route('/build', methods=['POST']) def create_build(): if not request.is_json: return jsonify(msg="Missing JSON in request"), 400
from itertools import count from typing import Optional from flask import Flask, request, jsonify from flask_pydantic_spec import (FlaskPydanticSpec, Response, Request) from pydantic import BaseModel, Field from tinydb import TinyDB, Query from tinydb.storages import MemoryStorage server = Flask(__name__) spec = FlaskPydanticSpec('flask', title='Live de Python') spec.register(server) database = TinyDB(storage=MemoryStorage) c = count() class QueryPessoa(BaseModel): id: Optional[int] nome: Optional[str] idade: Optional[int] class Pessoa(BaseModel): id: Optional[int] = Field(default_factory=lambda: next(c)) nome: str idade: int class Pessoas(BaseModel): pessoas: list[Pessoa] count: int
def test_register(name, app): api = FlaskPydanticSpec(name) api.register(app)