-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[fix] Apply REMOVE_X_INTERNAL normalizer to nested inline properties #22097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-internal
removal 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.
modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java
Show resolved
Hide resolved
modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java
Outdated
Show resolved
Hide resolved
…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. |
Description
This PR fixes a bug where the
REMOVE_X_INTERNAL=true
normalizer fails to remove thex-internal
extension from inline object properties within schemas.Problem
When
REMOVE_X_INTERNAL=true
is set, the normalizer correctly removesx-internal
from top-level schemas incomponents/schemas
, but fails to process inline object properties.This causes issues when:
admin.yaml
imports fromchat.yaml
)x-internal: true
type: object
with nested propertiesResult: TypeScript generator creates a type reference but no interface definition, causing compilation errors.
Solution
Apply the same
x-internal
removal logic tonormalizeProperties()
that already exists innormalizeComponentsSchemas()
, ensuring inline properties are handled consistently.Bug Trigger Conditions
x-internal: true
Testing
Example
Before (broken):
After (fixed):