Skip to content

Commit 97f535c

Browse files
lesebashwinb
andauthored
feat(openapi): switch to fastapi-based generator (#3944)
# What does this PR do? This replaces the legacy "pyopenapi + strong_typing" pipeline with a FastAPI-backed generator that has an explicit schema registry inside `llama_stack_api`. The key changes: 1. **New generator architecture.** FastAPI now builds the OpenAPI schema directly from the real routes, while helper modules (`schema_collection`, `endpoints`, `schema_transforms`, etc.) post-process the result. The old pyopenapi stack and its strong_typing helpers are removed entirely, so we no longer rely on fragile AST analysis or top-level import side effects. 2. **Schema registry in `llama_stack_api`.** `schema_utils.py` keeps a `SchemaInfo` record for every `@json_schema_type`, `register_schema`, and dynamically created request model. The OpenAPI generator and other tooling query this registry instead of scanning the package tree, producing deterministic names (e.g., `{MethodName}Request`), capturing all optional/nullable fields, and making schema discovery testable. A new unit test covers the registry behavior. 3. **Regenerated specs + CI alignment.** All docs/Stainless specs are regenerated from the new pipeline, so optional/nullable fields now match reality (expect the API Conformance workflow to report breaking changes—this PR establishes the new baseline). The workflow itself is back to the stock oasdiff invocation so future regressions surface normally. *Conformance will be RED on this PR; we choose to accept the deviations.* ## Test Plan - `uv run pytest tests/unit/server/test_schema_registry.py` - `uv run python -m scripts.openapi_generator.main docs/static` --------- Signed-off-by: Sébastien Han <[email protected]> Co-authored-by: Ashwin Bharambe <[email protected]>
1 parent cc88789 commit 97f535c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+47441
-30067
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ repos:
4242
hooks:
4343
- id: ruff
4444
args: [ --fix ]
45-
exclude: ^(src/llama_stack_api/strong_typing/.*)$
4645
- id: ruff-format
4746

4847
- repo: https://github.com/adamchainz/blacken-docs
@@ -106,16 +105,16 @@ repos:
106105
language: python
107106
pass_filenames: false
108107
require_serial: true
109-
files: ^src/llama_stack/providers/.*$
108+
files: ^src/llama_stack/providers/.*$|^scripts/run_openapi_generator.sh$
110109
- id: openapi-codegen
111110
name: API Spec Codegen
112111
additional_dependencies:
113112
- uv==0.7.8
114-
entry: sh -c './scripts/uv-run-with-index.sh run ./docs/openapi_generator/run_openapi_generator.sh > /dev/null'
113+
entry: sh -c './scripts/uv-run-with-index.sh run scripts/run_openapi_generator.sh'
115114
language: python
116115
pass_filenames: false
117116
require_serial: true
118-
files: ^src/llama_stack/apis/|^docs/openapi_generator/
117+
files: ^src/llama_stack_api/.*$
119118
- id: check-workflows-use-hashes
120119
name: Check GitHub Actions use SHA-pinned actions
121120
entry: ./scripts/check-workflows-use-hashes.sh

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ npm run serve
231231
If you modify or add new API endpoints, update the API documentation accordingly. You can do this by running the following command:
232232

233233
```bash
234-
uv run ./docs/openapi_generator/run_openapi_generator.sh
234+
uv run ./scripts/run_openapi_generator.sh
235235
```
236236

237237
The generated API schema will be available in `docs/static/`. Make sure to review the changes before committing.

client-sdks/stainless/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ These are the source-of-truth configuration files used to generate the Stainless
55

66
A small side note: notice the `.yml` suffixes since Stainless uses that suffix typically for its configuration files.
77

8-
These files go hand-in-hand. As of now, only the `openapi.yml` file is automatically generated using the `run_openapi_generator.sh` script.
8+
These files go hand-in-hand. As of now, only the `openapi.yml` file is automatically generated using the `scripts/run_openapi_generator.sh` script.

client-sdks/stainless/config.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ resources:
115115
sampling_params: SamplingParams
116116
scoring_result: ScoringResult
117117
system_message: SystemMessage
118-
query_result: RAGQueryResult
119-
document: RAGDocument
120-
query_config: RAGQueryConfig
121118
toolgroups:
122119
models:
123120
tool_group: ToolGroup
@@ -143,11 +140,6 @@ resources:
143140
endpoint: get /v1/tool-runtime/list-tools
144141
paginated: false
145142
invoke_tool: post /v1/tool-runtime/invoke
146-
subresources:
147-
rag_tool:
148-
methods:
149-
insert: post /v1/tool-runtime/rag-tool/insert
150-
query: post /v1/tool-runtime/rag-tool/query
151143

152144
responses:
153145
models:
@@ -173,6 +165,7 @@ resources:
173165
list:
174166
type: http
175167
endpoint: get /v1/responses/{response_id}/input_items
168+
paginated: false
176169

177170
prompts:
178171
models:
@@ -220,6 +213,9 @@ resources:
220213
create:
221214
type: http
222215
endpoint: post /v1/conversations/{conversation_id}/items
216+
delete:
217+
type: http
218+
endpoint: delete /v1/conversations/{conversation_id}/items/{item_id}
223219

224220
inspect:
225221
models:
@@ -252,6 +248,7 @@ resources:
252248
list:
253249
type: http
254250
endpoint: get /v1/chat/completions
251+
paginated: false
255252
retrieve:
256253
type: http
257254
endpoint: get /v1/chat/completions/{completion_id}
@@ -375,6 +372,7 @@ resources:
375372
endpoint: get /v1/scoring-functions
376373
paginated: false
377374
register: post /v1/scoring-functions
375+
unregister: delete /v1/scoring-functions/{scoring_fn_id}
378376
models:
379377
scoring_fn: ScoringFn
380378
scoring_fn_params: ScoringFnParams
@@ -392,6 +390,13 @@ resources:
392390
list_files_response: ListOpenAIFileResponse
393391
delete_file_response: OpenAIFileDeleteResponse
394392

393+
batches:
394+
methods:
395+
create: post /v1/batches
396+
list: get /v1/batches
397+
retrieve: get /v1/batches/{batch_id}
398+
cancel: post /v1/batches/{batch_id}/cancel
399+
395400
alpha:
396401
subresources:
397402
inference:
@@ -423,6 +428,7 @@ resources:
423428
endpoint: get /v1alpha/eval/benchmarks
424429
paginated: false
425430
register: post /v1alpha/eval/benchmarks
431+
unregister: delete /v1alpha/eval/benchmarks/{benchmark_id}
426432
models:
427433
benchmark: Benchmark
428434
list_benchmarks_response: ListBenchmarksResponse
@@ -519,7 +525,7 @@ readme:
519525
params: &ref_0 {}
520526
headline:
521527
type: request
522-
endpoint: post /v1/models
528+
endpoint: get /v1/models
523529
params: *ref_0
524530
pagination:
525531
type: request

0 commit comments

Comments
 (0)