fastapi swagger 界面显示操作级别选项覆盖服务器选项

问题描述 投票:0回答:2

我最近发现一个弹出窗口,告诉我一些操作级别选项会覆盖全局服务器选项:

如图:

enter image description here

我不明白这是我的应用程序中的错误还是正常现象。我不想向用户显示该消息。

编辑:

这是我的

main.py
文件:

from fastapi import FastAPI,Depends
from ml.model_recommendation import predict_intention
from ml.training_ml import create_ml
import crud,models,schemas
from db import SessionLocal,engine
from sqlalchemy.orm import Session
from typing import Optional
from enum import Enum
import numpy as np

app = FastAPI(title="ML prediction",description="API to serve data used for prediction of intended remediation date (IRD)")

class Tags(Enum):
    ITEMS = "Retrieve ITSO and Software Versions"
    DELETE = "Delete Data"
    INSERT = "Get IRD predictions"
    DOWNLOAD = "Download Data"


@app.on_event("startup")
def on_startup():
    models.Base.metadata.create_all(bind=engine)

# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()


@app.get(
    "/service_owners/",
    response_model=list[schemas.Evergreen],
    tags=[Tags.ITEMS]
)
def read_owners(service_owner: str ,software_product_version_name: Optional[str] = None,db: Session = Depends(get_db),skip: int = 0, limit: int = 100):
    owners = crud.get_service_owners(db,service_owner=service_owner,software_product_version_name=software_product_version_name,skip=skip,limit=limit)
    return owners

这是我的

crud.py
功能:

import models
from sqlalchemy.orm import Session
from sqlalchemy import select
from typing import Optional

def get_service_owners(db: Session, service_owner: str,software_product_version_name: Optional[str] = None,skip: int = 0, limit: int = 100):
    if software_product_version_name:
        stmt = (select(models.Evergreen.service_owner,models.Evergreen.software_product_version_name)
                .where(models.Evergreen.service_owner.ilike(f'%{service_owner}%'))
                .where(models.Evergreen.software_product_version_name.ilike(f'%{software_product_version_name}%'))
                ).distinct().offset(skip).limit(limit)
            
        return db.execute(stmt).all()
    
    stmt = select(models.Evergreen.service_owner,models.Evergreen.software_product_version_name).where(models.Evergreen.service_owner.ilike(f'%{service_owner}%')).distinct().offset(skip).limit(limit)
    return db.execute(stmt).all()

这是我的

schema.py
用于验证:

from typing import Optional
from pydantic import BaseModel
from typing_extensions import TypedDict

class Evergreen(BaseModel):
    service_owner: Optional[str]
    software_product_version_name: Optional[str]

    class Config:
        from_attributes = True

class Items(TypedDict):
    service_owner: str 
    software_product_version_name: str 

class Pred(TypedDict):
    service_owner: str
    software_product_version_name: str 
    future_expectation: int 
python swagger fastapi
2个回答
0
投票

此选项似乎出现在 OAS 3.1 文档中。这肯定是 swagger-ui 中的一个错误。尽管服务器在操作级别上没有被覆盖,但 swagger-ui 默认为“/”并始终显示覆盖。


0
投票

如何纠正? 我也面临同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.