Skip to content
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

Added a Validation that checks all operationIds in Link objects are valid #404

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ayushshrivastv
Copy link
Contributor

Issue #236

This PR directly addresses the issue mentioned in the GitHub project (issue #236) for OpenAPIKit.

I have added a validation that ensures operationIds in Link objects refer to actual Operations that exist in the document.

Changes

  1. I've created a new optional validation called linkOperationsExist that verifies Link objects with operationIds are pointing to valid Operations in the document.

  2. Extracting the operationId from the Link object (ignoring Links that use operationRef instead)

  • Collecting all operationIds from all Operations in the document (using different approaches in OpenAPIKit and OpenAPIKit30)
  • Checking if the Link's operationId is contained in the list of valid operationIds
  1. When a Link refers to a non-existent operationId, the validation produces a clear error message indicating that the Link's operationId has no corresponding Operation in the document.

This validation is optional and not included in the default validator.

let validator = Validator.default.validating(.linkOperationsExist)
try document.validate(using: validator)

The PR completes the TODO item in the project while maintaining consistency with the existing validation framework, ensuring that OpenAPI documents can be properly validated for correctness in their Link references.

@mattpolzin
Copy link
Owner

Thanks! Superficially this looks good. I’ll take a closer look soon.

@mattpolzin
Copy link
Owner

Looks like I'll have to take a look at the pet store spec failures. Don't see that being related to this PR unless I missed a modification to that test file on read through.

@ayushshrivastv
Copy link
Contributor Author

If there’s anything I missed or need to change, please let me know. I’ll double check and make sure everything’s in order. I’ve already tested it locally, and the test cases are passing!

@mattpolzin mattpolzin self-assigned this Apr 6, 2025
@mattpolzin mattpolzin self-requested a review April 6, 2025 14:14
Copy link
Owner

@mattpolzin mattpolzin left a comment

Choose a reason for hiding this comment

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

Thanks for adding some missing tests while you were in there! I left one question but nothing else looks amiss.

Comment on lines +417 to +420
let operationIds = context.document.paths.values
.compactMap { context.document.components[$0] }
.flatMap { $0.endpoints }
.compactMap { $0.operation.operationId }
Copy link
Owner

Choose a reason for hiding this comment

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

why not use the allOperationIds helper here like you did for the OpenAPIKit module's validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You’re right, we can use allOperationIds here as well. I overlooked that in the module validation—thanks for pointing it out!

@mattpolzin
Copy link
Owner

I've fixed the tests that were broken for no reason connected to this PR and merged that in.

@mattpolzin
Copy link
Owner

The one remaining test failure is related to the security requirements validation test you added. As best I can tell (and I don't have memory one way or the other) the validation you are testing does not exist. Did you intend to add one? The validity of security requirements is asserted while decoding documents, but there is not a Validation per se for it, it is built into the decoding process currently.

@ayushshrivastv
Copy link
Contributor Author

The one remaining test failure is related to the security requirements validation test you added. As best I can tell (and I don't have memory one way or the other) the validation you are testing does not exist. Did you intend to add one? The validity of security requirements is asserted while decoding documents, but there is not a Validation per se for it, it is built into the decoding process currently.

I took another look, and you’re right—there isn’t a separate validation step for security requirements; it’s handled implicitly during decoding. I had originally assumed there was a dedicated validation function for it, but that’s not the case.

I’ll go ahead and adjust the test (or remove it if it no longer makes sense in this context) and update the implementation accordingly.

ThankYou!

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