Skip to content

Conversation

@lovisaberggren
Copy link
Collaborator

@lovisaberggren lovisaberggren commented Mar 13, 2025

Proposed changes

Adds rule xgen-IPA-105-list-method-response-is-get-method-response which checks that the paginated List method results reference the same schema as the resource Get method. Also handles version matching, which affected the existing rule xgen-IPA-106-create-method-request-body-is-get-method-response.

New rule xgen-IPA-105-list-method-response-is-get-method-response has 2 violations
Existing rule xgen-IPA-106-create-method-request-body-is-get-method-response has one new violation
I'll do follow-up to add exceptions to both above

Added tests for the rule and unit tests for the functions used to get the responses based on a version.

Jira ticket: CLOUDP-304938

}
return path;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to methodUtils

return null;
}

const versions = Object.keys(response.content);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added version matching here used in both getResponseOfListMethodByMediaType and getResponseOfGetMethodByMediaType

@lovisaberggren lovisaberggren marked this pull request as ready for review March 14, 2025 11:17
@lovisaberggren lovisaberggren requested a review from a team as a code owner March 14, 2025 11:17
xgen-IPA-105-list-method-response-is-get-method-response:
description: >-
The response body of the List method should consist of the same resource object returned by the Get method. Validation checks that the List method results items reference the same schema as the Get method response.<br/>
- Validation applies to List methods for resource collections only<br/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand:

  • Validation makes schemaName level comparison only
  • Validation also does not make inline schema comparison

Are these assumptions correct? If so,
List-Get relationship is strict, so I am okay with expecting exactly the same schema.
Do we assume Get response always has schema reference, and should we consider inline schemas?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validation makes schemaName level comparison only

Yes, it checks that it refers to the exact same schema

Validation also does not make inline schema comparison

The paginated schema can be inline, but the resource schema itself is expected to be a schema ref, if the get doesn't have a ref, there will be a violation. I can add a test to cover this to make sure

}

// Ignore if the List method does not have a response schema
const listMethodResponse = getResponseOfListMethodByMediaType(mediaType, resourcePath, oas);
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb Mar 14, 2025

Choose a reason for hiding this comment

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

Why do we call this method? Isn't the rule iterating list method response content already?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, we can just get the response, I'll update 👍

function: 'eachResourceHasListMethod'
xgen-IPA-105-list-method-response-is-get-method-response:
description: >-
The response body of the List method should consist of the same resource object returned by the Get method. Validation checks that the List method results items reference the same schema as the Get method response.<br/>
Copy link
Member

Choose a reason for hiding this comment

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

That is based on assumption that "list operations" return pagginated objects - with results, total etc.
I seen that one before. Would we have validation and helper to check for that assumption each rule can base on it?

Suggested change
The response body of the List method should consist of the same resource object returned by the Get method. Validation checks that the List method results items reference the same schema as the Get method response.<br/>
The response body of the List method should consist of the same resource object returned by the Get method. Validation checks that the List method response contains items property with reference the same schema as the Get method response.<br/>

Copy link
Member

Choose a reason for hiding this comment

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

I really like that I can see how you interpreted the rule inside the PR. Saves us back and forth with code based discussion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes this one only applies to paginated lists (we ignore if it's not paginated). We will have another IPA to cover pagination in general

Copy link
Member

Choose a reason for hiding this comment

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

@lovisaberggren Yes. I'm aware. My intention for this comment was to add note to the yaml/docs.

}

// Ignore if the List method response is not found or not paginated
if (!resolvedListSchema || !schemaIsPaginated(resolvedListSchema)) {
Copy link
Member

@wtrocki wtrocki Mar 14, 2025

Choose a reason for hiding this comment

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

Unrelated to the PR but helper implementation might need additional checks as it now based on weak assumption that property named results means paggination. This logic should be covered in the rule description etc.

e.g "Pagginated property is determined by object returning results property with type array or something like this.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO we should at least check if results type is array
return fields.includes('properties') && Object.keys(schema['properties']).includes('results');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'll add a note in the description, and also add a check that the results is an array

Copy link
Member

Choose a reason for hiding this comment

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

Awesome. Second comment can be follow up jira as you haven't introduced that helper in this PR

}

// Ignore if the List method does not have a response schema
const listMethodResponse = oas.paths[resourcePath].get.responses['200'].content[mediaType];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const listMethodResponse = oas.paths[resourcePath].get.responses['200'].content[mediaType];
const listMethodResponse = resolveObject(documentInventory.resolved, path);

return [
{
path,
message: `Could not validate that the List method returns the same resource object as the Get method. The Get method does not have a schema.`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Should we return the same error for the createMethodRequest comparison?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, that makes sense 👍

function: 'eachResourceHasListMethod'
xgen-IPA-105-list-method-response-is-get-method-response:
description: >-
The response body of the List method should consist of the same resource object returned by the Get method. http://go/ipa/105
Copy link
Member

Choose a reason for hiding this comment

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

Link to IPA is no longer needed as it is already part of the docs and in failure we do reference to the docs in open source repo

Suggested change
The response body of the List method should consist of the same resource object returned by the Get method. http://go/ipa/105
The response body of the List method should consist of the same resource object returned by the Get method.

Copy link
Member

Choose a reason for hiding this comment

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

Meta comment/ Not this PR/Project:

In retrospect we could use public shortener to link to this repo to be kind for non MongoDB use cases.
Technically you could make blog post covering new mongodb validations and then go links will be the only blocker. All the info will be availabile upstream.
This can be addressed once we get our plans around IPA publication done.

Copy link
Member

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

LGTM

All comments are nits.

Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@lovisaberggren lovisaberggren merged commit 7449c54 into main Mar 14, 2025
13 checks passed
@lovisaberggren lovisaberggren deleted the CLOUDP-304938 branch March 14, 2025 15:08
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.

3 participants