[fix] Apply REMOVE_X_INTERNAL normalizer to nested inline properties#22097
Conversation
When REMOVE_X_INTERNAL=true is set, the normalizer removes the x-internal extension from top-level schemas in components/schemas but fails to remove it from inline object properties within those schemas. This causes issues when: 1. A schema is imported cross-file (e.g., admin.yaml imports from chat.yaml) 2. That schema has an inline object property with x-internal: true 3. The inline property has type: object with nested properties Result: TypeScript generator creates a type reference but no interface definition, causing compilation errors. This fix applies the same x-internal removal logic to normalizeProperties() that already exists in normalizeComponentsSchemas(), ensuring inline properties are handled consistently. Fixes behavior for inline schemas with x-internal in cross-file imports.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where the REMOVE_X_INTERNAL=true normalizer fails to remove the x-internal extension from inline object properties within schemas, causing TypeScript generation issues when schemas are imported cross-file.
- Applies consistent
x-internalremoval logic to inline properties - Prevents TypeScript compilation errors from missing interface definitions
- Ensures cross-file schema imports work correctly with inline object properties
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…en/OpenAPINormalizer.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds test to verify that REMOVE_X_INTERNAL normalizer correctly removes x-internal extension from inline object properties, not just top-level schemas.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@rc-glean thanks for the PR can you please review the build failure when you've time? |
This reverts commit c899e9e.
|
That's ok. Did you test the fix locally with the last commit in this branch to confirm it works for your use cases? |
|
Thank you. Confirmed the latest commit in this PR: 60cf734, fixes the issue. Ran the following verification: ## ✅ Fix Verified Against Production Schema
I've tested this fix against Glean's production OpenAPI schema where we encountered this exact bug.
### Test Setup
1. **Schema**: Glean Admin API with cross-file import (`admin.yaml` → `chat.yaml`)
2. **Trigger Condition**: Inline object property with `x-internal: true` inside a cross-file imported schema
3. **Generator Config**: `typescript-fetch` with `--openapi-normalizer REMOVE_X_INTERNAL=true`
### Reproduction
In `chat.yaml`, `AgentConfig` has an inline `clientCapabilities` property marked `x-internal: true`:
```yaml
AgentConfig:
properties:
clientCapabilities:
x-internal: true
type: object
properties:
canRenderImages:
type: boolean
artifacts:
$ref: "#/components/schemas/ArtifactsClientCapability"When Results❌ Before (v7.16.0 stable) // AgentConfig references the type...
clientCapabilities?: AgentConfigClientCapabilities;
// ...but the interface is NEVER generated (compilation error)✅ After (this PR - commit 60cf734) // Interface is properly generated as AgentConfig_clientCapabilities
export interface AgentConfigClientCapabilities {
canRenderImages?: boolean;
artifacts?: ArtifactsClientCapability;
paper?: PaperConfig;
}Generator logs confirm proper handling: ImpactThis bug forced us to extract inline schemas into separate top-level schemas as a workaround. With this fix, we can use natural inline object definitions with |
|
👌 let's give it a try i think ideally the logic should be done in normalizeSchema. i'll try to do the refactoring later if I can find the time. thanks again for the contribution. |
…penAPITools#22097) * fix: Apply REMOVE_X_INTERNAL normalizer to nested inline properties When REMOVE_X_INTERNAL=true is set, the normalizer removes the x-internal extension from top-level schemas in components/schemas but fails to remove it from inline object properties within those schemas. This causes issues when: 1. A schema is imported cross-file (e.g., admin.yaml imports from chat.yaml) 2. That schema has an inline object property with x-internal: true 3. The inline property has type: object with nested properties Result: TypeScript generator creates a type reference but no interface definition, causing compilation errors. This fix applies the same x-internal removal logic to normalizeProperties() that already exists in normalizeComponentsSchemas(), ensuring inline properties are handled consistently. Fixes behavior for inline schemas with x-internal in cross-file imports. * Update modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * test: Add test case for REMOVE_X_INTERNAL with inline properties Adds test to verify that REMOVE_X_INTERNAL normalizer correctly removes x-internal extension from inline object properties, not just top-level schemas. * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert "Apply suggestion from @Copilot" This reverts commit c899e9e. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
This PR fixes a bug where the
REMOVE_X_INTERNAL=truenormalizer fails to remove thex-internalextension from inline object properties within schemas.Problem
When
REMOVE_X_INTERNAL=trueis set, the normalizer correctly removesx-internalfrom top-level schemas incomponents/schemas, but fails to process inline object properties.This causes issues when:
admin.yamlimports fromchat.yaml)x-internal: truetype: objectwith nested propertiesResult: TypeScript generator creates a type reference but no interface definition, causing compilation errors.
Solution
Apply the same
x-internalremoval logic tonormalizeProperties()that already exists innormalizeComponentsSchemas(), ensuring inline properties are handled consistently.Bug Trigger Conditions
x-internal: trueTesting
Example
Before (broken):
After (fixed):