Skip to content

Share resolved request example values - #34

Merged
glenn-jocher merged 2 commits into
mainfrom
refactor/request-example-value
Aug 13, 2026
Merged

Share resolved request example values#34
glenn-jocher merged 2 commits into
mainfrom
refactor/request-example-value

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

  • let Python samples consume the existing resolved request value directly
  • remove the JSON serialization/parsing round trip and duplicated media-example precedence
  • avoid generating tuple prefix values that maxItems will discard

This is an output-preserving owner-level simplification identified during an independent Claude Code review of #33.

Validation

  • bun run test (19 tests, 358 assertions)
  • bun run typecheck
  • bun run lint
  • bun run knip
  • bun run build
  • regenerated all 80 live Platform Python samples; the corrected image-update sample is unchanged

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Python request samples now reuse resolved request example values directly, while shared example resolution avoids discarded tuple prefixes and duplicated precedence logic.

📊 Key Changes

  • Updated pythonCodeSample to use the resolved request body value instead of serializing and parsing a generated JSON string.
  • Added shared requestBodyExampleValue logic for resolving media examples, schemas, and authored examples; requestBodyExample now formats that value for string output.
  • Limited generated prefixItems examples to the array’s maxItems before filling remaining entries.
  • Added generator coverage for schema-based request body fallback when no media example is provided.

🎯 Purpose & Impact

  • Python sample generation follows one resolved request-value path and avoids unnecessary JSON round trips.
  • Generated array examples no longer create tuple prefix values that maxItems removes.
  • The PR context reports regenerated Platform Python samples with the corrected image-update sample unchanged; no broader user-facing behavior change is indicated.

@UltralyticsAssistant UltralyticsAssistant added the fixed Bug has been resolved label Aug 13, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @glenn-jocher, thank you for submitting a ultralytics/openapi 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/openapi main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed the 29-line change in lib/openapi.ts. The tuple-prefix fix is sound, and the shared resolved-value path is correct for JSON/multipart bodies. One bounded compatibility regression remains for generated non-string text/* request examples; otherwise the change is focused and low risk.

💬 Posted 1 inline comment
  • 📝 LOW lib/openapi.ts:540 This changes the fallback behavior for non-string text/* request bodies. Previously, requestBodyExample serialized generated object/array/null values to JSON text before Python samples passed them as body=...; now the resolved value is emitted directly, so a text body with an object/array schema becomes content=body with a dict/list, and a schema-less body becomes content=None. Preserve the text-media serialization for the fallback path while retaining direct values for JSON, multipar…

Comment thread lib/openapi.ts Outdated
Comment thread lib/openapi.ts Outdated

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review 2

Made with ❤️ by Ultralytics Actions

Since review 1, the text/* fallback regression is addressed by retaining requestBodyExample serialization and adding focused coverage. The direct resolved-value reuse and maxItems-bounded prefixItems change remain correct, with no new concrete regressions found. LGTM.

@glenn-jocher
glenn-jocher merged commit 1ef2620 into main Aug 13, 2026
4 checks passed
@glenn-jocher
glenn-jocher deleted the refactor/request-example-value branch August 13, 2026 07:24
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 PR #34 has been merged—thank you @glenn-jocher!

“The details are not the details. They make the design.” — Charles Eames

This focused update gives Python request samples a single resolved-value path, avoids unnecessary JSON round trips, centralizes example resolution, and keeps generated prefix items within maxItems. The added schema fallback coverage is a welcome improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed Bug has been resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants