Merge "Hardcode barbican order schema"

This commit is contained in:
Zuul 2025-02-26 18:54:40 +00:00 committed by Gerrit Code Review
commit 31fedb263d
2 changed files with 180 additions and 2 deletions

View File

@ -21,6 +21,7 @@ from codegenerator.common.schema import SpecSchema
from codegenerator.openapi.base import OpenStackServerSourceBase
from codegenerator.openapi.utils import merge_api_ref_doc
from codegenerator.openapi.barbican_schemas import container
from codegenerator.openapi.barbican_schemas import order
from codegenerator.openapi.barbican_schemas import secret
from codegenerator.openapi.barbican_schemas import secret_store
@ -30,7 +31,7 @@ from ruamel.yaml.scalarstring import LiteralScalarString
class BarbicanGenerator(OpenStackServerSourceBase):
URL_TAG_MAP = {}
RESOURCE_MODULES = [container, secret, secret_store]
RESOURCE_MODULES = [container, order, secret, secret_store]
def __init__(self):
pass
@ -428,7 +429,7 @@ class BarbicanGenerator(OpenStackServerSourceBase):
None,
"/v1/orders/{order_id}",
controller=orders.OrderController.on_get,
action="get",
action="show",
conditions={"method": ["GET"]},
)
mapper.connect(
@ -471,6 +472,12 @@ class BarbicanGenerator(OpenStackServerSourceBase):
)
for route in mapper.matchlist:
if route.routelist == [
"/v1/orders/",
{"type": ":", "name": "order_id"},
] and route.conditions.get("method", "GET") == ["PUT"]:
# update order is not supported
continue
self._process_route(route, openapi_spec, framework="pecan")
if args.api_ref_src:

View File

@ -0,0 +1,171 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from typing import Any
from codegenerator.common.schema import ParameterSchema
from codegenerator.common.schema import TypeSchema
ORDER_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"created": {
"type": "string",
"format": "date-time",
"description": "Date and time container was created",
},
"creator_id": {
"type": "string",
"description": "Keystone Id of the user who created the order",
},
"meta": {"type": "object", "additionalProperties": True},
"order_ref": {
"type": "string",
"description": "Order href associated with the order",
},
"secret_ref": {
"type": "string",
"description": "Secret href associated with the order",
},
"status": {
"type": "string",
"description": "Current status of the order",
},
"sub_status": {
"type": "string",
"description": "Metadata associated with the order",
},
"sub_status_message": {
"type": "string",
"description": "Metadata associated with the order",
},
"type": {"type": "string", "description": "Order type"},
"updated": {
"type": ["string", "null"],
"format": "date-time",
"description": "Date and time order was last updated",
},
},
"required": ["order_ref", "secret_ref"],
"additionalProperties": False,
}
ORDER_LIST_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"next": {
"type": "string",
"description": "A HATEOAS URL to retrieve the next set of orders based on the offset and limit parameters. This attribute is only available when the total number of orders is greater than offset and limit parameter combined.",
},
"previous": {
"type": "string",
"description": "A HATEOAS URL to retrieve the previous set of orders based on the offset and limit parameters. This attribute is only available when the request offset is greater than 0.",
},
"total": {
"type": "integer",
"description": "The total number of orders available to the user.",
},
"orders": {
"type": "array",
"items": ORDER_SCHEMA,
"description": "A list of order references",
},
},
"required": ["orders"],
"additionalProperties": False,
}
ORDER_CREATE_REQUEST: dict[str, Any] = {
"type": "object",
"properties": {
"meta": {
"type": "object",
"additionalProperties": True,
"description": "Dictionary containing the secret metadata used to generate the order.",
},
"type": {"type": "string", "description": "Order type"},
},
"required": ["type"],
"additionalProperties": False,
}
ORDER_CREATE_RESPONSE: dict[str, Any] = {
"type": "object",
"properties": {
"order_ref": {"type": "string", "description": "Order reference"}
},
"required": ["order_ref"],
"additionalProperties": False,
}
ORDER_LIST_PARAMETERS: dict[str, dict] = {
"orders_offset": {
"in": "query",
"name": "offset",
"description": "The starting index within the total list of the orders that you would like to retrieve.",
"schema": {"type": "integer"},
},
"orders_limit": {
"in": "query",
"name": "limit",
"description": "The maximum number of records to return (up to 100). The default limit is 10.",
"schema": {"type": "integer"},
},
}
def _post_process_operation_hook(
openapi_spec, operation_spec, path: str | None = None
):
"""Hook to allow service specific generator to modify details"""
operationId = operation_spec.operationId
if operationId == "orders:get":
for key, val in ORDER_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))
def _get_schema_ref(
openapi_spec, name, description=None, schema_def=None, action_name=None
) -> tuple[str | None, str | None, bool]:
mime_type: str = "application/json"
ref: str
if name == "OrdersListResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ORDER_LIST_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "OrderShowResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ORDER_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "OrdersCreateRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ORDER_CREATE_REQUEST)
)
ref = f"#/components/schemas/{name}"
elif name == "OrdersCreateResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**ORDER_CREATE_RESPONSE)
)
ref = f"#/components/schemas/{name}"
else:
return (None, None, False)
return (ref, mime_type, True)