Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
document: {
components: componentSchemas,
paths: {
'/valid-resource': {
'/resource': {
post: {
requestBody: {
content: {
Expand All @@ -90,6 +90,9 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
},
},
},
'/resource/{id}': {
get: {},
},
},
},
errors: [],
Expand Down Expand Up @@ -121,7 +124,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
document: {
components: componentSchemas,
paths: {
'/invalid-resource': {
'/resource': {
post: {
requestBody: {
content: {
Expand All @@ -140,21 +143,24 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
},
},
},
'/resource/{id}': {
get: {},
},
},
},
errors: [
{
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
message:
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: id. http://go/ipa/106',
path: ['paths', '/invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
message:
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at one of the inline schemas. http://go/ipa/106',
path: ['paths', '/invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -164,7 +170,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
document: {
components: componentSchemas,
paths: {
'/nested-invalid-resource': {
'/resource': {
post: {
requestBody: {
content: {
Expand All @@ -177,21 +183,17 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
},
},
},
'/resource/{id}': {
get: {},
},
},
},
errors: [
{
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
message:
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: user.userId. http://go/ipa/106',
path: [
'paths',
'/nested-invalid-resource',
'post',
'requestBody',
'content',
'application/vnd.atlas.2023-01-01+json',
],
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -201,7 +203,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
document: {
components: componentSchemas,
paths: {
'/array-invalid-resource': {
'/resource': {
post: {
requestBody: {
content: {
Expand All @@ -214,21 +216,17 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
},
},
},
'/resource/{id}': {
get: {},
},
},
},
errors: [
{
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
message:
'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: items.items.itemId. http://go/ipa/106',
path: [
'paths',
'/array-invalid-resource',
'post',
'requestBody',
'content',
'application/vnd.atlas.2023-01-01+json',
],
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -238,7 +236,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
document: {
components: componentSchemas,
paths: {
'/excepted-resource': {
'/resource': {
post: {
requestBody: {
content: {
Expand All @@ -254,6 +252,9 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
},
},
},
'/resource/{id}': {
get: {},
},
},
},
errors: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
import {
getResourcePathItems,
isCustomMethodIdentifier,
isResourceCollectionIdentifier,
isSingletonResource,
} from './utils/resourceEvaluation.js';
import { resolveObject } from './utils/componentUtils.js';
import { hasException } from './utils/exceptions.js';
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
Expand All @@ -10,9 +15,12 @@ const ERROR_MESSAGE = 'The Create method request object must not include input f
export default (input, _, { path, documentInventory }) => {
const resourcePath = path[1];
const oas = documentInventory.resolved;
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
let mediaType = input;

if (isCustomMethodIdentifier(resourcePath) || !mediaType.endsWith('json')) {
const isResourceCollection = isResourceCollectionIdentifier(resourcePath) && !isSingletonResource(resourcePaths);

if (isCustomMethodIdentifier(resourcePath) || !isResourceCollection || !mediaType.endsWith('json')) {
return;
}

Expand Down
Loading