Skip to content

Conversation

nt0tsky
Copy link
Contributor

@nt0tsky nt0tsky commented Aug 27, 2025

This PR adds a new Operation discriminator example from openapi.yaml to illustrate and validate discriminator usage in nested array structures.
While top-level discriminators are already supported, additional work was needed for deep structures: this PR introduces the new parameter discriminator: true to enable proper validation when discriminators are used inside arrays or other nested schemas.

Changes

  • test/resources/discriminator.yaml – Defines the Operation schema with discriminator mapping inside an array context.
  • test/discriminator.spec.ts – Comprehensive test suite covering.
  • API config – Added new parameter discriminator: true to ensure proper deep discriminator support.

Purpose

  • Clarify that top-level discriminator support already works
  • Provide an explicit example and test coverage for deep discriminator structures (arrays, nested schemas)
  • Ensure consistent error handling and validation by enabling discriminator: true

@nt0tsky
Copy link
Contributor Author

nt0tsky commented Aug 27, 2025

@cdimascio any thoughts on this ? :)

@cdimascio
Copy link
Owner

Thanks for the PR. Will have a look within the next week. Cheers!

@nt0tsky
Copy link
Contributor Author

nt0tsky commented Sep 5, 2025

@cdimascio just kind reminder :)

@cdimascio cdimascio requested a review from Copilot September 5, 2025 11:45
Copy link

@Copilot Copilot AI left a 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 enhances discriminator validation support in OpenAPI by introducing a new discriminator: true parameter. The implementation focuses on enabling proper discriminator validation for nested array structures and deep schema hierarchies.

  • Adds a comprehensive Operation discriminator example with nested array validation
  • Introduces the discriminator parameter to request validation options
  • Provides extensive test coverage for discriminator validation scenarios

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/resources/discriminator.yaml Defines Operation schema with discriminator mapping in array context for testing
test/discriminator.spec.ts Comprehensive test suite covering valid/invalid discriminator operations
test/ajv.options.spec.ts Tests for new discriminator parameter handling in AjvOptions
src/framework/types.ts Adds discriminator boolean property to ValidateRequestOpts
src/framework/ajv/options.ts Implements discriminator parameter in request validation options

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

key: string;
titleTranslationKey: string;
type: 'normal' | 'intermediate';
step?: string;
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

The step property is marked as optional in the TypeScript type definition but is required in the OpenAPI schema (line 179 in discriminator.yaml). This inconsistency could lead to confusion and validation errors.

Suggested change
step?: string;
step: string;

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, check one more time

allowUnknownQueryParameters,
coerceTypes,
removeAdditional,
discriminator
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

Missing comma after the discriminator property. This will cause a syntax error.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, check one more time

@nt0tsky
Copy link
Contributor Author

nt0tsky commented Sep 6, 2025

comments/suggestions by Copilot were fixed, thanks @cdimascio

@cdimascio
Copy link
Owner

Thank you @nt0tsky 👍 PR looks good. I will get this merged and rolled into a new version.

One last thing, could you please update the doc here, https://github.com/cdimascio/express-openapi-validator-documentation, with this new option. Best, thanks again

@cdimascio cdimascio merged commit 0c4fe03 into cdimascio:master Sep 6, 2025
6 checks passed
@nt0tsky
Copy link
Contributor Author

nt0tsky commented Sep 6, 2025

@cdimascio sure, I will do it today/tomorrow. Thank you

@cdimascio
Copy link
Owner

Thanks appreciate it 🚀

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