diff options
author | John Estabrook <jestabro@vyos.io> | 2024-09-23 12:53:20 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-09-29 22:21:21 -0500 |
commit | 3ad911a20620a67b6a019e86da815e2a25047de7 (patch) | |
tree | 64c1933a5997023bbe78ad677ede3a6223173e5a /src/services/vyos-http-api-server | |
parent | 00cafcbdd87bcdcc1a08ecba026f4df619e4582e (diff) | |
download | vyos-1x-3ad911a20620a67b6a019e86da815e2a25047de7.tar.gz vyos-1x-3ad911a20620a67b6a019e86da815e2a25047de7.zip |
http-api: T6736: update for deprecated/renamed in Pydantic V2
Diffstat (limited to 'src/services/vyos-http-api-server')
-rwxr-xr-x | src/services/vyos-http-api-server | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index 91100410c..42c4cf387 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -33,7 +33,7 @@ from fastapi import BackgroundTasks from fastapi.responses import HTMLResponse from fastapi.exceptions import RequestValidationError from fastapi.routing import APIRoute -from pydantic import BaseModel, StrictStr, validator, model_validator +from pydantic import BaseModel, StrictStr, field_validator, model_validator from starlette.middleware.cors import CORSMiddleware from starlette.datastructures import FormData from starlette.formparsers import FormParser, MultiPartParser @@ -91,9 +91,9 @@ def success(data): return HTMLResponse(resp) # Pydantic models for validation -# Pydantic will cast when possible, so use StrictStr -# validators added as needed for additional constraints -# schema_extra adds anotations to OpenAPI, to add examples +# Pydantic will cast when possible, so use StrictStr validators added as +# needed for additional constraints +# json_schema_extra adds anotations to OpenAPI to add examples class ApiModel(BaseModel): key: StrictStr @@ -102,8 +102,9 @@ class BasePathModel(BaseModel): op: StrictStr path: List[StrictStr] - @validator("path") - def check_non_empty(cls, path): + @field_validator("path") + @classmethod + def check_non_empty(cls, path: str) -> str: if not len(path) > 0: raise ValueError('path must be non-empty') return path @@ -113,7 +114,7 @@ class BaseConfigureModel(BasePathModel): class ConfigureModel(ApiModel, BaseConfigureModel): class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "set | delete | comment", @@ -125,7 +126,7 @@ class ConfigureListModel(ApiModel): commands: List[BaseConfigureModel] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "commands": "list of commands", @@ -155,7 +156,7 @@ class RetrieveModel(ApiModel): configFormat: StrictStr = None class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "returnValue | returnValues | exists | showConfig", @@ -170,7 +171,7 @@ class ConfigFileModel(ApiModel): file: StrictStr = None class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "save | load", @@ -203,7 +204,7 @@ class ImageModel(ApiModel): return self class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "add | delete | show | set_default", @@ -218,7 +219,7 @@ class ImportPkiModel(ApiModel): passphrase: StrictStr = None class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "import_pki", @@ -233,7 +234,7 @@ class ContainerImageModel(ApiModel): name: StrictStr = None class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "add | delete | show", @@ -246,7 +247,7 @@ class GenerateModel(ApiModel): path: List[StrictStr] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "generate", @@ -259,7 +260,7 @@ class ShowModel(ApiModel): path: List[StrictStr] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "show", @@ -272,7 +273,7 @@ class RebootModel(ApiModel): path: List[StrictStr] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "reboot", @@ -285,7 +286,7 @@ class ResetModel(ApiModel): path: List[StrictStr] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "reset", @@ -298,7 +299,7 @@ class PoweroffModel(ApiModel): path: List[StrictStr] class Config: - schema_extra = { + json_schema_extra = { "example": { "key": "id_key", "op": "poweroff", |