refactor: Adjust the common and contrib schemas

1. adjust the common schemas
2. adjust the contrib schemas
3. just use schemas directly because all include in __init__.py
4. update swagger.json file

Change-Id: I4b8c366cbb439fbcb7c118329588eab1b31b9370
This commit is contained in:
zhu.boxiang 2022-07-12 17:23:26 +08:00
parent 1b17da1b2c
commit 7eaa53c9db
10 changed files with 145 additions and 184 deletions

View File

@ -152,7 +152,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OK"
"$ref": "#/components/schemas/Message"
}
}
}
@ -1427,7 +1427,7 @@
"title": "Response 200 List Keystone Endpoints Api V1 Contrib Keystone Endpoints Get",
"type": "array",
"items": {
"$ref": "#/components/schemas/ContribListKeystoneEndpointsResponseModel"
"$ref": "#/components/schemas/KeystoneEndpoints"
}
}
}
@ -1842,11 +1842,11 @@
}
},
"422": {
"description": "Unprocessable Entity",
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnprocessableEntityMessage"
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
@ -1898,25 +1898,8 @@
"properties": {
"detail": {
"title": "Detail",
"type": "string"
}
}
},
"ContribListKeystoneEndpointsResponseModel": {
"title": "ContribListKeystoneEndpointsResponseModel",
"required": [
"region_name",
"url"
],
"type": "object",
"properties": {
"region_name": {
"title": "Region Name",
"type": "string"
},
"url": {
"title": "Url",
"type": "string"
"type": "string",
"description": "Detail message"
}
}
},
@ -2873,7 +2856,8 @@
"properties": {
"detail": {
"title": "Detail",
"type": "string"
"type": "string",
"description": "Detail message"
}
}
},
@ -2899,7 +2883,54 @@
"properties": {
"detail": {
"title": "Detail",
"type": "string"
"type": "string",
"description": "Detail message"
}
}
},
"KeystoneEndpoints": {
"title": "KeystoneEndpoints",
"required": [
"region_name",
"url"
],
"type": "object",
"properties": {
"region_name": {
"title": "Region Name",
"type": "string",
"description": "Region name"
},
"url": {
"title": "Url",
"type": "string",
"description": "Endpoint URL"
}
}
},
"Message": {
"title": "Message",
"required": [
"message"
],
"type": "object",
"properties": {
"message": {
"title": "Message",
"type": "string",
"description": "Message"
},
"code": {
"title": "Code",
"type": "integer",
"description": "Code",
"default": 200
},
"title": {
"title": "Title",
"type": "string",
"description": "Title",
"default": "OK"
}
}
},
@ -2912,30 +2943,8 @@
"properties": {
"detail": {
"title": "Detail",
"type": "string"
}
}
},
"OK": {
"title": "OK",
"required": [
"message"
],
"type": "object",
"properties": {
"code": {
"title": "Code",
"type": "integer",
"default": 200
},
"message": {
"title": "Message",
"type": "string"
},
"title": {
"title": "Title",
"type": "string",
"default": "OK"
"description": "Detail message"
}
}
},
@ -3297,20 +3306,8 @@
"properties": {
"detail": {
"title": "Detail",
"type": "string"
}
}
},
"UnprocessableEntityMessage": {
"title": "UnprocessableEntityMessage",
"required": [
"detail"
],
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "string"
"type": "string",
"description": "Detail message"
}
}
},

View File

@ -24,7 +24,6 @@ from skyline_apiserver.client.openstack import system
from skyline_apiserver.client.openstack.system import get_endpoints
from skyline_apiserver.config import CONF
from skyline_apiserver.log import LOG
from skyline_apiserver.schemas import common
from skyline_apiserver.types import constants
router = APIRouter()
@ -34,14 +33,14 @@ router = APIRouter()
"/contrib/keystone_endpoints",
description="List Keystone Endpoints",
responses={
200: {"model": List[schemas.ContribListKeystoneEndpointsResponseModel]},
500: {"model": common.InternalServerErrorMessage},
200: {"model": List[schemas.KeystoneEndpoints]},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=List[schemas.ContribListKeystoneEndpointsResponseModel],
response_model=List[schemas.KeystoneEndpoints],
status_code=status.HTTP_200_OK,
response_description="OK",
)
async def list_keystone_endpoints() -> List[schemas.ContribListKeystoneEndpointsResponseModel]:
async def list_keystone_endpoints() -> List[schemas.KeystoneEndpoints]:
"""Contrib List Keystone Endpoints."""
try:
regions = await system.get_regions()
@ -64,7 +63,7 @@ async def list_keystone_endpoints() -> List[schemas.ContribListKeystoneEndpoints
description="List Domains",
responses={
200: {"model": List[str]},
500: {"model": common.InternalServerErrorMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=List[str],
status_code=status.HTTP_200_OK,
@ -102,7 +101,7 @@ async def list_domains(
description="List Regions",
responses={
200: {"model": List[str]},
500: {"model": common.InternalServerErrorMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=List[str],
status_code=status.HTTP_200_OK,

View File

@ -31,7 +31,6 @@ from skyline_apiserver.client import utils
from skyline_apiserver.client.openstack import cinder, glance, keystone, neutron, nova
from skyline_apiserver.client.utils import generate_session, get_system_session
from skyline_apiserver.config import CONF
from skyline_apiserver.schemas import common
from skyline_apiserver.types import constants
from skyline_apiserver.utils.roles import assert_system_admin_or_reader, is_system_reader_no_admin
@ -51,10 +50,10 @@ List Servers.
""",
responses={
200: {"model": schemas.ExtListServersResponse},
400: {"model": common.BadRequestMessage},
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
400: {"model": schemas.BadRequestMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListServersResponse,
status_code=status.HTTP_200_OK,
@ -282,10 +281,10 @@ List Recycle Servers.
""",
responses={
200: {"model": schemas.ExtListRecycleServersResponse},
400: {"model": common.BadRequestMessage},
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
400: {"model": schemas.BadRequestMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListRecycleServersResponse,
status_code=status.HTTP_200_OK,
@ -505,9 +504,9 @@ async def list_recycle_servers(
description="List Volumes.",
responses={
200: {"model": schemas.ExtListVolumesResponse},
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListVolumesResponse,
status_code=status.HTTP_200_OK,
@ -701,9 +700,9 @@ async def list_volumes(
description="List Volume Snapshots.",
responses={
200: {"model": schemas.ExtListVolumeSnapshotsResponse},
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListVolumeSnapshotsResponse,
status_code=status.HTTP_200_OK,
@ -874,9 +873,9 @@ async def list_volume_snapshots(
"/extension/ports",
description="List Ports.",
responses={
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListPortsResponse,
status_code=status.HTTP_200_OK,
@ -1064,8 +1063,8 @@ async def list_ports(
description="List compute services.",
responses={
200: {"model": schemas.ExtListComputeServicesResponse},
401: {"model": common.UnauthorizedMessage},
500: {"model": common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.ExtListComputeServicesResponse,
status_code=status.HTTP_200_OK,

View File

@ -63,7 +63,7 @@ async def _patch_profile(profile: schemas.Profile, global_request_id: str) -> sc
description="Login & get user profile.",
responses={
200: {"model": schemas.Profile},
401: {"model": schemas.common.UnauthorizedMessage},
401: {"model": schemas.UnauthorizedMessage},
},
response_model=schemas.Profile,
status_code=status.HTTP_200_OK,
@ -131,7 +131,7 @@ async def login(
description="Get user profile.",
responses={
200: {"model": schemas.Profile},
401: {"model": schemas.common.UnauthorizedMessage},
401: {"model": schemas.UnauthorizedMessage},
},
response_model=schemas.Profile,
status_code=status.HTTP_200_OK,
@ -152,9 +152,9 @@ async def get_profile(
"/logout",
description="Log out.",
responses={
200: {"model": schemas.common.OK},
200: {"model": schemas.Message},
},
response_model=schemas.common.OK,
response_model=schemas.Message,
status_code=status.HTTP_200_OK,
response_description="OK",
)
@ -178,7 +178,7 @@ async def logout(
except Exception as e:
LOG.debug(str(e))
response.delete_cookie(CONF.default.session_name)
return schemas.common.OK(message="Logout OK")
return schemas.Message(message="Logout OK")
@router.post(
@ -186,7 +186,7 @@ async def logout(
description="Switch project.",
responses={
200: {"model": schemas.Profile},
401: {"model": schemas.common.UnauthorizedMessage},
401: {"model": schemas.UnauthorizedMessage},
},
response_model=schemas.Profile,
status_code=status.HTTP_200_OK,

View File

@ -22,7 +22,6 @@ from skyline_apiserver import schemas
from skyline_apiserver.api import deps
from skyline_apiserver.client.utils import generate_session, get_access
from skyline_apiserver.policy import ENFORCER, UserContext
from skyline_apiserver.schemas import Policies, PoliciesRules, common
router = APIRouter()
@ -66,11 +65,11 @@ def _generate_target(profile: schemas.Profile) -> Dict[str, str]:
"/policies",
description="List policies and permissions",
responses={
200: {"model": Policies},
401: {"model": common.UnauthorizedMessage},
500: {"model": common.InternalServerErrorMessage},
200: {"model": schemas.Policies},
401: {"model": schemas.UnauthorizedMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=Policies,
response_model=schemas.Policies,
status_code=status.HTTP_200_OK,
response_description="OK",
)
@ -92,17 +91,17 @@ async def list_policies(
"/policies/check",
description="Check policies permissions",
responses={
200: {"model": Policies},
401: {"model": common.UnauthorizedMessage},
403: {"model": common.ForbiddenMessage},
500: {"model": common.InternalServerErrorMessage},
200: {"model": schemas.Policies},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=Policies,
response_model=schemas.Policies,
status_code=status.HTTP_200_OK,
response_description="OK",
)
async def check_policies(
policy_rules: PoliciesRules,
policy_rules: schemas.PoliciesRules,
profile: schemas.Profile = Depends(deps.get_profile_update_jwt),
):
session = await generate_session(profile)

View File

@ -84,8 +84,8 @@ def get_prometheus_query_range_response(
description="Prometheus query API.",
responses={
200: {"model": schemas.PrometheusQueryResponse},
401: {"model": schemas.common.UnauthorizedMessage},
500: {"model": schemas.common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.PrometheusQueryResponse,
status_code=status.HTTP_200_OK,
@ -129,8 +129,8 @@ async def prometheus_query(
description="Prometheus query_range API.",
responses={
200: {"model": schemas.PrometheusQueryRangeResponse},
401: {"model": schemas.common.UnauthorizedMessage},
500: {"model": schemas.common.InternalServerErrorMessage},
401: {"model": schemas.UnauthorizedMessage},
500: {"model": schemas.InternalServerErrorMessage},
},
response_model=schemas.PrometheusQueryRangeResponse,
status_code=status.HTTP_200_OK,

View File

@ -39,8 +39,8 @@ def assert_setting_key_exist(key: str):
description="Get a setting item.",
responses={
200: {"model": schemas.Setting},
401: {"model": schemas.common.UnauthorizedMessage},
404: {"model": schemas.common.NotFoundMessage},
401: {"model": schemas.UnauthorizedMessage},
404: {"model": schemas.NotFoundMessage},
},
response_model=schemas.Setting,
status_code=status.HTTP_200_OK,
@ -63,10 +63,9 @@ async def show_setting(
description="Update a setting item.",
responses={
200: {"model": schemas.Setting},
401: {"model": schemas.common.UnauthorizedMessage},
403: {"model": schemas.common.ForbiddenMessage},
404: {"model": schemas.common.NotFoundMessage},
422: {"model": schemas.common.UnprocessableEntityMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
404: {"model": schemas.NotFoundMessage},
},
response_model=schemas.Setting,
status_code=status.HTTP_200_OK,
@ -94,7 +93,7 @@ async def update_setting(
description="Get all settings.",
responses={
200: {"model": schemas.Settings},
401: {"model": schemas.common.UnauthorizedMessage},
401: {"model": schemas.UnauthorizedMessage},
},
response_model=schemas.Settings,
status_code=status.HTTP_200_OK,
@ -125,9 +124,9 @@ async def list_settings(
description="Reset a setting item to default",
responses={
204: {"model": None},
401: {"model": schemas.common.UnauthorizedMessage},
403: {"model": schemas.common.ForbiddenMessage},
404: {"model": schemas.common.NotFoundMessage},
401: {"model": schemas.UnauthorizedMessage},
403: {"model": schemas.ForbiddenMessage},
404: {"model": schemas.NotFoundMessage},
},
status_code=status.HTTP_204_NO_CONTENT,
response_description="No Content",

View File

@ -12,8 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from . import common
from .contrib import ContribListKeystoneEndpointsResponseModel
# flake8: noqa: F401
from .common import (
BadRequestMessage,
ForbiddenMessage,
InternalServerErrorMessage,
Message,
NotFoundMessage,
UnauthorizedMessage,
)
from .contrib import KeystoneEndpoints
from .extension import (
ExtListComputeServicesResponse,
ExtListPortsResponse,
@ -44,44 +53,3 @@ from .prometheus import (
PrometheusQueryResult,
)
from .setting import Setting, Settings, UpdateSetting
__all__ = (
"common",
"ContribListKeystoneEndpointsResponseModel",
"Credential",
"Domain",
"ExtListComputeServicesResponse",
"ExtListPortsResponse",
"ExtListRecycleServersResponse",
"ExtListServersResponse",
"ExtListVolumeSnapshotsResponse",
"ExtListVolumesResponse",
"ExtPortDeviceOwner",
"ExtPortSortKey",
"ExtPortStatus",
"ExtRecycleServerSortKey",
"ExtServerSortKey",
"ExtServerStatus",
"ExtSortDir",
"ExtVolumeSnapshotSortKey",
"ExtVolumeSnapshotStatus",
"ExtVolumeSortKey",
"ExtVolumeStatus",
"License",
"Payload",
"Policies",
"PoliciesRules",
"Profile",
"Project",
"Region",
"Role",
"Setting",
"Settings",
"UpdateSetting",
"PrometheusQueryResponse",
"PrometheusQueryData",
"PrometheusQueryResult",
"PrometheusQueryRangeResponse",
"PrometheusQueryRangeData",
"PrometheusQueryRangeResult",
)

View File

@ -12,34 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pydantic import BaseModel
from pydantic import BaseModel, Field
class OK(BaseModel):
code: int = 200
message: str
title: str = "OK"
class Message(BaseModel):
message: str = Field(..., description="Message")
code: int = Field(200, description="Code")
title: str = Field("OK", description="Title")
class BadRequestMessage(BaseModel):
detail: str
class ErrorMessageBase(BaseModel):
detail: str = Field(..., description="Detail message")
class UnprocessableEntityMessage(BaseModel):
detail: str
class BadRequestMessage(ErrorMessageBase):
""""""
class UnauthorizedMessage(BaseModel):
detail: str
class UnauthorizedMessage(ErrorMessageBase):
""""""
class ForbiddenMessage(BaseModel):
detail: str
class ForbiddenMessage(ErrorMessageBase):
""""""
class NotFoundMessage(BaseModel):
detail: str
class NotFoundMessage(ErrorMessageBase):
""""""
class InternalServerErrorMessage(BaseModel):
detail: str
class InternalServerErrorMessage(ErrorMessageBase):
""""""

View File

@ -14,9 +14,9 @@
from __future__ import annotations
from pydantic import BaseModel
from pydantic import BaseModel, Field
class ContribListKeystoneEndpointsResponseModel(BaseModel):
region_name: str
url: str
class KeystoneEndpoints(BaseModel):
region_name: str = Field(..., description="Region name")
url: str = Field(..., description="Endpoint URL")