-
Couldn't load subscription status.
- Fork 14
CLOUDP-304942: Adds xgen-IPA-107-update-method-request-body-is-get-method-response #567
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { isSingleResourceIdentifier } from './utils/resourceEvaluation.js'; | ||
| import { resolveObject } from './utils/componentUtils.js'; | ||
| import { hasException } from './utils/exceptions.js'; | ||
| import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js'; | ||
| import { getGETMethodResponseSchemaFromPathItem } from './utils/methodUtils.js'; | ||
| import { checkRequestResponseResourceEqualityAndReturnErrors } from './utils/validations.js'; | ||
|
|
||
| const RULE_NAME = 'xgen-IPA-107-update-method-request-body-is-get-method-response'; | ||
| const ERROR_MESSAGE = | ||
| 'The request body schema properties of the Update method must match the response body schema properties of the Get method.'; | ||
|
|
||
| /** | ||
| * Update method (PUT, PATCH) request body schema properties must match the response body schema properties of the Get method. | ||
| * | ||
| * @param {string} input - An update operation request content version | ||
| * @param {object} _ - Unused | ||
| * @param {{ path: string[], documentInventory: object}} context - The context object containing the path and document | ||
| */ | ||
| export default (input, _, { path, documentInventory }) => { | ||
| const oas = documentInventory.resolved; | ||
| const unresolvedOas = documentInventory.unresolved; | ||
| const resourcePath = path[1]; | ||
| let mediaType = input; | ||
|
|
||
| if (!isSingleResourceIdentifier(resourcePath) || !mediaType.endsWith('json')) { | ||
| return; | ||
| } | ||
|
|
||
| // Ignore if the Update method does not have a request body schema | ||
| const updateMethodRequest = resolveObject(oas, path); | ||
|
|
||
| if (!updateMethodRequest || !updateMethodRequest.schema) { | ||
| return; | ||
| } | ||
|
|
||
| if (hasException(updateMethodRequest, RULE_NAME)) { | ||
| collectException(updateMethodRequest, RULE_NAME, path); | ||
| return; | ||
| } | ||
|
|
||
| // Ignore if there is no matching Get method | ||
| const getMethodResponse = getGETMethodResponseSchemaFromPathItem(oas.paths[resourcePath], mediaType); | ||
| if (!getMethodResponse) { | ||
| return; | ||
| } | ||
|
|
||
| const updateMethodRequestUnresolved = resolveObject(unresolvedOas, path); | ||
| const getMethodResponseUnresolved = getGETMethodResponseSchemaFromPathItem( | ||
| unresolvedOas.paths[resourcePath], | ||
| mediaType | ||
| ); | ||
|
|
||
| const errors = checkRequestResponseResourceEqualityAndReturnErrors( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Create method checks for equality across all fields except those marked as readOnly or writeOnly. Should we apply the same equality check for the Update method? The description also refers to this as "the resource or parts of the resource returned by the Get method." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline: IaC tools require Update request schemas to follow the same requirements as Create request schemas |
||
| path, | ||
| updateMethodRequest, | ||
| getMethodResponse, | ||
| updateMethodRequestUnresolved, | ||
| getMethodResponseUnresolved, | ||
| 'Update', | ||
| 'Get', | ||
| ERROR_MESSAGE | ||
| ); | ||
|
|
||
| if (errors.length !== 0) { | ||
| return collectAndReturnViolation(path, RULE_NAME, errors); | ||
| } | ||
|
|
||
| collectAdoption(path, RULE_NAME); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created common function to be reused