Skip to content

feat(gemini): implement complete OpenAI to Gemini JSON Schema conversion#3860

Closed
ER-EPR wants to merge 4 commits into
router-for-me:devfrom
ER-EPR:feat/gemini-structured-output-conversion
Closed

feat(gemini): implement complete OpenAI to Gemini JSON Schema conversion#3860
ER-EPR wants to merge 4 commits into
router-for-me:devfrom
ER-EPR:feat/gemini-structured-output-conversion

Conversation

@ER-EPR

@ER-EPR ER-EPR commented Jun 15, 2026

Copy link
Copy Markdown

Implement comprehensive schema conversion from OpenAI structured output format to Gemini API format with full support for:
addressing issue #3721

  • Nullable types: convert ["string", "null"] to type + nullable field
  • allOf merging: combine multiple schemas into single object schema
  • oneOf conversion: transform to anyOf for Gemini compatibility
  • additionalProperties removal: Gemini rejects this field
  • Recursive normalization: handle nested objects, arrays, and complex schemas
  • Format validation: preserve date-time, date, time; remove unsupported formats
  • Type constraints: preserve min/max, enum, descriptions
  • Recursive schemas: support $ref for self-referential schemas

Includes helper functions:

  • normalizeSchemaForGemini: recursive schema normalization
  • mergeAllOf: merge allOf schemas with property and required field deduplication
  • normalizeJSONSchema: entry point for JSON string processing

This enables Firecrawl and other tools using OpenAI's structured output format to work seamlessly with Gemini models through the proxy.

Implement comprehensive schema conversion from OpenAI structured output format
to Gemini API format with full support for:

- Nullable types: convert ["string", "null"] to type + nullable field
- allOf merging: combine multiple schemas into single object schema
- oneOf conversion: transform to anyOf for Gemini compatibility
- additionalProperties removal: Gemini rejects this field
- Recursive normalization: handle nested objects, arrays, and complex schemas
- Format validation: preserve date-time, date, time; remove unsupported formats
- Type constraints: preserve min/max, enum, descriptions
- Recursive schemas: support $ref for self-referential schemas

Includes helper functions:
- normalizeSchemaForGemini: recursive schema normalization
- mergeAllOf: merge allOf schemas with property and required field deduplication
- normalizeJSONSchema: entry point for JSON string processing

This enables Firecrawl and other tools using OpenAI's structured output format
to work seamlessly with Gemini models through the proxy.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for OpenAI's JSON schema structured outputs by converting and normalizing them to Gemini's supported JSON Schema subset. The reviewer feedback identifies key areas for improvement: resolving non-deterministic behavior from Go's randomized map iteration by pre-merging allOf schemas, updating mergeAllOf to preserve metadata fields like description and title, and utilizing json.NewDecoder with UseNumber() to avoid precision loss when decoding numbers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d50806ea5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated
Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40310757ea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated
Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated
Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated
… precision, JSON Schema support

- Fix non-deterministic allOf merging by processing before main iteration
- Preserve all schema fields in mergeAllOf (description, title, enum, etc.)
- Use json.NewDecoder with UseNumber() to preserve number precision
- Change response_schema to responseJsonSchema for full JSON Schema support
- Preserve additionalProperties constraints instead of removing them
@ER-EPR ER-EPR force-pushed the feat/gemini-structured-output-conversion branch from 4031075 to 1cd0b6c Compare June 15, 2026 13:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1cd0b6c0b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/translator/gemini/openai/responses/gemini_openai-responses_request.go Outdated
ER-EPR added 2 commits June 15, 2026 22:19
…perties schemas

- Change response_mime_type to responseMimeType to match Gemini API camelCase
  and ensure aistudio_executor cleanup strips the correct field
- Normalize additionalProperties when it's a schema object, preserving
  booleans as-is, to remove unsupported keywords like pattern/default
Instead of converting type arrays with null (e.g., ["string", "null"])
to type + nullable:true, preserve them as-is. This allows:
- Gemini/Vertex paths to use native type array support
- CLI/Antigravity paths to use flattenTypeArrays which adds (nullable) hints

Also fixes non-null type array handling to only convert to anyOf when needed.
@luispater luispater closed this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants