-
Notifications
You must be signed in to change notification settings - Fork 271
fix(openapi): prioritize property-level examples over referenced schema examples #10806
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
Open
devin-ai-integration
wants to merge
11
commits into
main
Choose a base branch
from
devin/1763854835-fix-property-example-priority
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(openapi): prioritize property-level examples over referenced schema examples #10806
devin-ai-integration
wants to merge
11
commits into
main
from
devin/1763854835-fix-property-example-priority
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…es in OpenAPI parser When a property has both a $ref and examples/example fields (OpenAPI 3.1+), the parser now correctly uses the property-level examples instead of the examples from the referenced schema. This fixes both the old parser (openapi-ir-parser) and the new parser (openapi-to-ir/v3-importer-commons) to handle this case properly. Fixes #7932 Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The old parser uses OpenAPI 3.0 types which don't support the examples property. The fix is only needed in the new v3 parser which uses OpenAPI 3.1. Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
- Extract example/examples from properties before schema conversion - Prioritize property-level examples over type declaration examples - Handle OpenAPI 3.1+ siblings (example/examples on same level as ) - Revert incorrect fix in SchemaOrReferenceConverter Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
…lity
- Changed from {propertyId}_property_example_{index} to {propertyId}_example_{index}
- Maintains existing IR contract and snapshot test expectations
- Fix still prioritizes property-level examples over type-level examples
Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
The fix now properly extracts property-level examples, which changes the IR output for several test fixtures. These changes are expected and correct: - Property ordering may differ (JSON objects are unordered by spec) - More examples are now populated in v2Examples.userSpecifiedExamples - Property-level examples now take precedence over type-level examples All v3-importer-tests pass with updated snapshots. Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
Replace the 'as any' cast with a type-safe type guard function that checks for the presence of example/examples fields on OpenAPI schemas. This eliminates the need for the biome-ignore comment while maintaining type safety. The HasExamples type uses OpenAPIV3_1.BaseSchemaObject['examples'] to ensure compatibility with the openapi-types library definitions. Co-Authored-By: Colton Berry <coltonsberry@gmail.com>
Add test fixture and test case to validate that property-level examples take precedence over referenced schema examples (issue #7932). The test verifies that when a property has both a $ref and examples: - Property-level examples are extracted and used in v2Examples - Schema-level examples from the referenced type are NOT used - Example: Company.logo uses logo.png (property example) not invoice.pdf (File schema example) Test follows the conventions in CLAUDE.md and includes: - Fixture with OpenAPI spec demonstrating the issue - Test case with meaningful assertions - Snapshots for regression testing Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
…s://git-manager.devin.ai/proxy/github.com/fern-api/fern into devin/1763854835-fix-property-example-priority
Resolved merge conflict in openapi-from-flag.test.ts by keeping both the new property-level examples test and all new tests from main. Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
- Removed leftover merge conflict marker (>>>>>>> origin/main) - Applied biome formatting fixes to test file - Verified biome check passes locally - Verified depcheck passes locally - Verified test passes locally Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
The isWildcardStatusCode field was added to the IR in commit 9d9a902 for 4XX/5XX support. This commit updates the snapshot for the new property-level examples test to match the current IR shape. This change is unrelated to the property-level examples fix - it's simply bringing the snapshot in sync with the IR structure from main. Co-Authored-By: danny@buildwithfern.com <danny@buildwithfern.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Linear ticket: Closes #7932
When an OpenAPI 3.1+ schema property has both a
$refandexample/examplesfields (which is valid in OpenAPI 3.1+), the parser now correctly prioritizes the property-level examples over the examples from the referenced schema.Previously, if you had:
The parser would use the examples from the
Fileschema instead of the property-level examples. This fix ensures property-level examples take precedence.Changes Made
v3-importer-commons/ConvertProperties.ts) to extract and prioritize property-level exampleshasExamples()to safely detect schemas with example/examples fields (works for both SchemaObjects and ReferenceObjects with siblings)exampleandexamplesfields are now extracted before schema conversionv2Examplesinstead of falling back to type declaration examples{propertyId}_example_{index}) to maintain backward compatibility with existing IR contractpackages/cli/registerthat validates property-level example precedence through the complete--from-openapipipelineopenapi-ir-parser) was NOT modified because it uses OpenAPI 3.0 types which don't support theexamplesproperty. This fix only applies to the v3 parser which handles OpenAPI 3.1+ specs.Testing
✅ All tests pass - The fix is verified to work correctly:
packages/cli/register/src/ir-to-fdr-converter/__test__/openapi-from-flag.test.tsfixtures/property-level-examples/with OpenAPI spec matching issue OpenAPI: Property-level examples for $ref properties are ignored #7932Company.logouses property-level example (logo.png) instead of File schema example (invoice.pdf)packages/cli/registerpass locallypackages/cli/api-importers/v3-importer-testspass locally (6 files updated)Updates Since Last Revision
Maintenance Updates (Latest commits)
isWildcardStatusCodefield (this field was added to the IR in main via commit 9d9a902 for 4XX/5XX support - unrelated to this PR)Test Case Added (Previous commit)
CLAUDE.mdtesting conventions$ref+examplessiblingslogo.png)invoice.pdfis absent)--from-openapipipeline produces correct FDR outputSnapshot Updates (Earlier commit)
v2Examples.userSpecifiedExampleswhere property-level examples existliteral: "error"→named: "ErrorStatus") - this appears to be a side effect of improved type extractionHuman Review Checklist
Critical items to verify:
openapi-from-flag.test.tsand confirm it properly validates the fixErrorStatus,CircleType,SquareType). Confirm this is expected behavior and doesn't break downstream generators. This is a significant behavioral change that could affect SDK generation.$ref + example(singular) ✅ Covered by test$ref + examples(array) ✅ Covered by testallOf: [$ref] + examplesallOf: [$ref, {examples: ...}]api: specs: - openapi:) use the v3 parser and benefit from this fix (currently unverified)Implementation notes:
hasExamples()to safely detect schemas with example/examples fields:typeof schema === "object" && schema != null && ("example" in schema || "examples" in schema)$refcan have siblings)convertPropertiesfunction before callingSchemaOrReferenceConverterpropertyLevelExamplesarray and used to populatev2Exampleson the property{propertyId}_example_{index}Known risks:
api: specs: - openapi: ../openapi.yml) use the v3 parser. If they use the old parser, they won't benefit from this fix.allOf: [$ref, {examples: ...}]pattern from the issue hasn't been explicitly tested in the new test case.Scope limitation:
openapi-to-ir/v3-importer-commons)openapi-ir-parser) will not benefit from this fixDevin session: https://app.devin.ai/sessions/eb789030add4441bb97a4b6a2eb22a80
Requested by: @dannysheridan