Skip to content

Use authored request examples in Python samples - #33

Merged
glenn-jocher merged 2 commits into
mainfrom
fix/authored-request-examples
Aug 13, 2026
Merged

Use authored request examples in Python samples#33
glenn-jocher merged 2 commits into
mainfrom
fix/authored-request-examples

Conversation

@glenn-jocher

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

Copy link
Copy Markdown
Member

Summary

  • reuse the existing request-body example selection for generated Python SDK samples
  • support JSON Schema tuple arrays so generated examples respect prefixItems
  • cover authored union bodies and fixed-length tuple examples in the focused generator suite

Validation

  • bun run test (19 tests, 358 assertions)
  • bun run typecheck
  • bun run lint
  • bun run knip
  • bun run build
  • regenerated the live image-update sample locally and confirmed realistic bbox and keypoints values

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Python SDK samples now reuse authored request-body examples, including examples from union schemas, while supporting JSON Schema prefixItems for fixed-length tuple arrays.

📊 Key Changes

  • Updated pythonCodeSample to use requestBodyExample when no explicit media example is provided.
  • Preserved authored request examples from schema branches such as anyOf instead of generating fallback values.
  • Added prefixItems support to JsonSchema, including tuple-aware example generation and schema matching.
  • Updated generator tests to cover authored request bodies and four-element tuple examples.

🎯 Purpose & Impact

  • Generated Python samples now include realistic authored request data, such as image-update payloads with bbox and keypoints values.
  • Fixed-length tuple schemas generate values for each prefixItems entry and validate remaining elements against items.

@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working enhancement New feature or request labels 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 Python sample integration and tuple-schema matching changes. The authored-example reuse and tuple matching paths are otherwise coherent, but not is only enforced during matching and not during direct example construction, so newly supported schemas can still produce invalid request samples.

💬 Posted 1 inline comment
  • 💡 MEDIUM lib/openapi.ts:1269 The new not support only affects paths that already call schemaMatches; the direct schemaExample branches still return candidates without validating the enclosing schema. For example, { type: "object", properties: { secret: { type: "string" } }, not: { required: ["secret"] } } generates secret, and a tuple prefix item with not: { const: "example" } can generate the forbidden value "example". These invalid values flow into requestBodyExample and the Python samples. Validate const…

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 broader not handling has been removed as discussed. The current diff cleanly reuses requestBodyExample for Python samples and adds consistent prefixItems matching and example generation, with focused coverage for authored union bodies and tuple arrays. I found no remaining concrete defects. LGTM.

@glenn-jocher
glenn-jocher merged commit 3b56d79 into main Aug 13, 2026
4 checks passed
@glenn-jocher
glenn-jocher deleted the fix/authored-request-examples branch August 13, 2026 07:15
@UltralyticsAssistant

Copy link
Copy Markdown
Member

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

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

This update puts that principle into practice by preserving authored request-body examples, including union-schema examples, and adding prefixItems support for accurate fixed-length tuple samples.

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

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants