fix: update OpenAPI generator

This commit is contained in:
Alexey Rybak 2025-09-23 11:05:20 -07:00 committed by raghotham
parent 914c8cb605
commit f1c91f7161
2 changed files with 16 additions and 23 deletions

View file

@ -9,7 +9,9 @@ import ipaddress
import types import types
import typing import typing
from dataclasses import make_dataclass from dataclasses import make_dataclass
from typing import Any, Dict, Set, Union from typing import Annotated, Any, Dict, get_args, get_origin, Set, Union
from fastapi import UploadFile
from llama_stack.apis.datatypes import Error from llama_stack.apis.datatypes import Error
from llama_stack.strong_typing.core import JsonType from llama_stack.strong_typing.core import JsonType
@ -30,9 +32,6 @@ from llama_stack.strong_typing.schema import (
Schema, Schema,
SchemaOptions, SchemaOptions,
) )
from typing import get_origin, get_args
from typing import Annotated
from fastapi import UploadFile
from llama_stack.strong_typing.serialization import json_dump_string, object_to_json from llama_stack.strong_typing.serialization import json_dump_string, object_to_json
from .operations import ( from .operations import (
@ -624,11 +623,11 @@ class Generator:
# data passed in request body as multipart/form-data # data passed in request body as multipart/form-data
elif op.multipart_params: elif op.multipart_params:
builder = ContentBuilder(self.schema_builder) builder = ContentBuilder(self.schema_builder)
# Create schema properties for multipart form fields # Create schema properties for multipart form fields
properties = {} properties = {}
required_fields = [] required_fields = []
for name, param_type in op.multipart_params: for name, param_type in op.multipart_params:
if get_origin(param_type) is Annotated: if get_origin(param_type) is Annotated:
base_type = get_args(param_type)[0] base_type = get_args(param_type)[0]
@ -636,28 +635,21 @@ class Generator:
base_type = param_type base_type = param_type
if base_type is UploadFile: if base_type is UploadFile:
# File upload # File upload
properties[name] = { properties[name] = {"type": "string", "format": "binary"}
"type": "string",
"format": "binary"
}
else: else:
# Form field # Form field
properties[name] = self.schema_builder.classdef_to_ref(base_type) properties[name] = self.schema_builder.classdef_to_ref(base_type)
required_fields.append(name) required_fields.append(name)
multipart_schema = { multipart_schema = {
"type": "object", "type": "object",
"properties": properties, "properties": properties,
"required": required_fields "required": required_fields,
} }
requestBody = RequestBody( requestBody = RequestBody(
content={ content={"multipart/form-data": {"schema": multipart_schema}},
"multipart/form-data": {
"schema": multipart_schema
}
},
required=True, required=True,
) )
# data passed in payload as JSON and mapped to request parameters # data passed in payload as JSON and mapped to request parameters
@ -801,9 +793,10 @@ class Generator:
) )
return Operation( return Operation(
tags=[getattr(op.defining_class, "API_NAMESPACE", op.defining_class.__name__)], tags=[
summary=None, getattr(op.defining_class, "API_NAMESPACE", op.defining_class.__name__)
# summary=doc_string.short_description, ],
summary=doc_string.short_description,
description=description, description=description,
parameters=parameters, parameters=parameters,
requestBody=requestBody, requestBody=requestBody,

View file

@ -29,4 +29,4 @@ fi
stack_dir=$(dirname $(dirname $THIS_DIR)) stack_dir=$(dirname $(dirname $THIS_DIR))
PYTHONPATH=$PYTHONPATH:$stack_dir \ PYTHONPATH=$PYTHONPATH:$stack_dir \
python -m docs.openapi_generator.generate $(dirname $THIS_DIR)/_static python -m docs.openapi_generator.generate $(dirname $THIS_DIR)/static