mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 12:07:34 +00:00
feat(api): add extra_body parameter support with shields example
Introduce ExtraBodyField annotation to enable parameters that arrive via extra_body in client SDKs but are accessible server-side with full typing. These parameters are documented in OpenAPI specs under x-llama-stack-extra-body-params but excluded from generated SDK signatures. Add shields parameter to create_openai_response as the first implementation using this pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ce77c27ff8
commit
79f889d3f0
12 changed files with 321 additions and 13 deletions
|
@ -50,6 +50,7 @@ from .specification import (
|
|||
Document,
|
||||
Example,
|
||||
ExampleRef,
|
||||
ExtraBodyParameter,
|
||||
MediaType,
|
||||
Operation,
|
||||
Parameter,
|
||||
|
@ -677,6 +678,27 @@ class Generator:
|
|||
# parameters passed anywhere
|
||||
parameters = path_parameters + query_parameters
|
||||
|
||||
# Build extra body parameters documentation
|
||||
extra_body_parameters = []
|
||||
for param_name, param_type, description in op.extra_body_params:
|
||||
if is_type_optional(param_type):
|
||||
inner_type: type = unwrap_optional_type(param_type)
|
||||
required = False
|
||||
else:
|
||||
inner_type = param_type
|
||||
required = True
|
||||
|
||||
# Use description from ExtraBodyField if available, otherwise from docstring
|
||||
param_description = description or doc_params.get(param_name)
|
||||
|
||||
extra_body_param = ExtraBodyParameter(
|
||||
name=param_name,
|
||||
schema=self.schema_builder.classdef_to_ref(inner_type),
|
||||
description=param_description,
|
||||
required=required,
|
||||
)
|
||||
extra_body_parameters.append(extra_body_param)
|
||||
|
||||
webmethod = getattr(op.func_ref, "__webmethod__", None)
|
||||
raw_bytes_request_body = False
|
||||
if webmethod:
|
||||
|
@ -898,6 +920,7 @@ class Generator:
|
|||
deprecated=getattr(op.webmethod, "deprecated", False)
|
||||
or "DEPRECATED" in op.func_name,
|
||||
security=[] if op.public else None,
|
||||
extraBodyParameters=extra_body_parameters if extra_body_parameters else None,
|
||||
)
|
||||
|
||||
def _get_api_stability_priority(self, api_level: str) -> int:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue