Skip to content

feat(cli): add validation fields to ContainerType in IR#12144

Closed
sbawabe wants to merge 24 commits intomainfrom
devin/1770404069-container-type-validation
Closed

feat(cli): add validation fields to ContainerType in IR#12144
sbawabe wants to merge 24 commits intomainfrom
devin/1770404069-container-type-validation

Conversation

@sbawabe
Copy link
Copy Markdown
Contributor

@sbawabe sbawabe commented Feb 6, 2026

Description

Refs #12106

Adds an optional ContainerTypeValidation base property to the ContainerType discriminated union in the IR, with plumbing to flow validation from OpenAPI → IR → FDR. Builds on the base-properties approach from #12106 and includes a fix to the TS SDK generator to support base-properties on discriminated unions. Validation values (minItems, maxItems, uniqueItems for arrays; minProperties, maxProperties for maps) are now extracted from OpenAPI schemas and propagated through the full pipeline.

Link to Devin run: https://app.devin.ai/sessions/83c7515ef32b494daec35f9429127e68
Requested by: @sbawabe

Changes Made

IR type definitions (types.yml)

  • Added base-properties: validation: optional<ContainerTypeValidation> to ContainerType union
  • Added ContainerTypeValidation discriminated union with list, map, set variants
  • Added ListValidationRules (minItems, maxItems, uniqueItems), MapValidationRules (minItems, maxItems), SetValidationRules (minItems, maxItems)
  • Note: MapType does not have its own validation field — map validation is handled exclusively through ContainerTypeValidation.map to avoid a type conflict where ContainerType.Map extends both MapType and _Base

TS SDK generator fix (GeneratedUnionImpl.ts, AbstractParsedSingleUnionType.ts)

  • Removed the throw in addBuilderProperties() that blocked unions with base-properties
  • Added getBasePropertyAssignmentsForBuilder() to generate propertyName: undefined assignments for all base properties in builder factory functions
  • Bumped generator version to 3.49.4

OpenAPI → IR validation extraction

  • ArraySchemaConverter: extracts minItems, maxItems, uniqueItems from OpenAPI array schemas and creates ContainerTypeValidation.list(...) on the resulting ContainerType
  • MapSchemaConverter: accepts minProperties/maxProperties from the parent schema via new constructor args; creates ContainerTypeValidation.map(...) when present
  • SchemaConverter: passes this.schema.minProperties / this.schema.maxProperties to MapSchemaConverter

FDR converter (convertTypeShape.ts)

  • Reads validation from container.validation and passes minItems/maxItems to FDR list, map, and set types

Call-site updates (importers, IR generator, type resolver)

  • Updated OneOfSchemaConverter, CreateTypeReferenceFromFernType, parseInlineType, TypeResolver — these continue to use factory defaults (validation: undefined) since they don't have access to OpenAPI validation constraints

Snapshot updates (~105 files)

  • Updated ir-generator-tests JSON definitions (101 files) to include "validation": null on all ContainerType objects
  • Updated ete-test snapshots (diff, protoc-gen-fern, dependencies file size), IR migration snapshots, v3-importer-tests snapshots
  • Updated min-max-values-ir.snap and min-max-values-fdr.snap with actual validation values (e.g., minItems: 1, maxItems: 10)

Changelog

  • CLI: 3.86.0 (feat, irVersion: 65)
  • TS SDK generator: 3.49.4 (fix)

Updates since last revision

  • Merged origin/main multiple times to resolve conflicts in generators/typescript/sdk/versions.yml, packages/cli/cli/versions.yml, and packages/cli/ete-tests/.../dependencies.test.ts.snap
  • Bumped CLI version to 3.86.0 and TS SDK generator version to 3.49.4 to sit above upstream versions
  • Updated exhaustive test definition snapshot after merge

Human Review Checklist

  • Factory object mutation pattern: The converters mutate the object returned by ContainerType.list(...) / ContainerType.map(...) to set validation. This works but is fragile if factory functions ever return frozen objects.
  • Map validation field naming: MapValidationRules uses minItems/maxItems internally, but OpenAPI uses minProperties/maxProperties. The converter maps minProperties → minItems, and FDR converter maps back minItems → minProperties. Verify this round-trip is intentional.
  • Set validation not wired: No converter creates ContainerTypeValidation.set(...) from OpenAPI (OpenAPI doesn't have native set validation). The FDR converter reads it if present, but nothing populates it.
  • Auto-generated example IDs: Many v3-importer-tests snapshots have changed example ID hashes (e.g., "id": "db78b62a""id": "6339919d"). This is expected since the new validation field affects hash computation, but worth verifying.

Testing

  • pnpm run check passes (lint + typecheck)
  • pnpm --filter @fern-api/ir-generator-tests test:update — all 311 tests pass
  • pnpm --filter @fern-api/register test -- --update — snapshots updated with actual validation values
  • IR migration tests pass locally
  • 6/7 required CI checks passing (lint, depcheck, compile, biome, test, Validate versions.yml files)
  • test-ete — failing due to CI infrastructure timeout ("Build CLI (dev) has timed out after 5 minutes"), not related to code changes

- Add ContainerTypeValidation base-property to ContainerType union
- Add ListValidationRules, MapValidationRules, SetValidationRules types
- Add validation field to MapType
- Fix TS SDK generator to support base-properties in union builders
- Update all converters and parsers to pass validation (defaulting to undefined)
- Flow validation from IR to FDR converter

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 2 commits February 6, 2026 20:00
…tainerType base property

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
@devin-ai-integration devin-ai-integration Bot changed the title feat(cli): add validation fields to ContainerType and MapType in IR feat(cli): add validation fields to ContainerType in IR Feb 6, 2026
devin-ai-integration Bot and others added 21 commits February 6, 2026 20:08
…pshots with validation field

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
… snapshot, include merge changes

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
- ArraySchemaConverter: extract minItems, maxItems, uniqueItems from array schemas
- MapSchemaConverter: extract minProperties, maxProperties from map schemas
- SchemaConverter: pass parent schema validation to MapSchemaConverter
- FDR converter already reads validation from ContainerType (no changes needed)
- Updated min-max-values snapshots with actual validation values

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
…napshot

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
…shots)

Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
Co-Authored-By: Sarah Bawabe <sarah@buildwithfern.com>
@sbawabe sbawabe closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant