Skip to content

Conversation

@lovisaberggren
Copy link
Collaborator

@lovisaberggren lovisaberggren commented Feb 27, 2025

Proposed changes

Adds new IPA rule xgen-IPA-104-get-method-returns-single-resource to check that get operations don't return paginated or array responses. Applied to GET for standard resources and singleton resources.

Jira ticket: CLOUDP-302984

Testing

  • Added unit test for rule
  • Checked current offenders, there are 23 violations currently

See all violations: https://github.com/mongodb/openapi/pull/463/checks?check_run_id=37928281663

Example violation:

warning  xgen-IPA-104-get-method-returns-single-resource  Get methods should return data for a single resource. This method returns an array or a paginated response. http://go/ipa/104  paths./api/atlas/v2/groups/{groupId}/clusters/{clusterName}/fts/indexes/{databaseName}/{collectionName}.get.responses[200].content.application/vnd.atlas.2023-01-01+json

*/
export function getAllSuccessfulGetResponseSchemas(pathObject) {
const responses = pathObject['get']['responses'];
export function getAllSuccessfulResponseSchemas(operationObject) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated this one to return successful response schemas for any operation, so we can reuse it more. Also returning the path for each schema, to be used in rule evaluations

@lovisaberggren lovisaberggren marked this pull request as ready for review February 27, 2025 14:18
@lovisaberggren lovisaberggren requested a review from a team as a code owner February 27, 2025 14:18
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

@lovisaberggren lovisaberggren merged commit 8799cef into main Feb 27, 2025
13 checks passed
@lovisaberggren lovisaberggren deleted the CLOUDP-302984 branch February 27, 2025 16:13

if (hasException(responseObject, RULE_NAME)) {
collectException(responseObject, RULE_NAME, fullPath);
} else if (schemaIsPaginated(schema) || schemaIsArray(schema)) {
Copy link
Member

@wtrocki wtrocki Feb 27, 2025

Choose a reason for hiding this comment

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

Question - when we have PR level job does this validator runs against dev or production schema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be for the dev schema

Copy link
Member

Choose a reason for hiding this comment

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

Perfect!

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