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 @@ -49,12 +49,12 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
content: {
'application/vnd.atlas.2023-01-01+json': {
schema: {
$ref: '#/components/schemas/SchemaRequest',
$ref: '#/components/schemas/Schema',
},
},
'application/vnd.atlas.2024-01-01+json': {
schema: {
$ref: '#/components/schemas/SchemaRequest',
$ref: '#/components/schemas/Schema',
},
},
},
Expand Down Expand Up @@ -109,7 +109,10 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
},
},
},
'/resource2': {
'/resource/{id}': {
get: {},
},
'/resourceTwo': {
post: {
requestBody: {
content: {
Expand All @@ -127,7 +130,10 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
},
},
},
'/resource3': {
'/resourceTwo/{id}': {
get: {},
},
'/resourceThree': {
post: {
requestBody: {
content: {
Expand All @@ -140,6 +146,9 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
},
},
},
'/resourceThree/{id}': {
get: {},
},
},
},
errors: [
Expand All @@ -158,19 +167,19 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
{
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
message: 'The response body schema must reference a schema with a Request suffix. http://go/ipa/106',
path: ['paths', '/resource2', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
message: 'The response body schema is defined inline and must reference a predefined schema. http://go/ipa/106',
path: ['paths', '/resource3', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
path: ['paths', '/resourceThree', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
severity: DiagnosticSeverity.Warning,
},
],
Expand Down Expand Up @@ -207,7 +216,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
},
},
},
'/resource2': {
'/resourceTwo': {
post: {
requestBody: {
content: {
Expand All @@ -231,7 +240,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
},
},
},
'/resource3': {
'/resourceThree': {
post: {
requestBody: {
content: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
],
},
},
'/resource2': {
'/resourceTwo': {
post: {
parameters: [],
},
Expand All @@ -98,7 +98,7 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
],
},
},
'/resource2': {
'/resourceTwo': {
post: {
parameters: [
{
Expand Down Expand Up @@ -127,14 +127,14 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
{
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
message: 'Input parameter [query-param]: Create operations should not have query parameters. http://go/ipa/106',
path: ['paths', '/resource2', 'post'],
path: ['paths', '/resourceTwo', 'post'],
severity: DiagnosticSeverity.Warning,
},
{
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
message:
'Input parameter [query-param-2]: Create operations should not have query parameters. http://go/ipa/106',
path: ['paths', '/resource2', 'post'],
path: ['paths', '/resourceTwo', 'post'],
severity: DiagnosticSeverity.Warning,
},
],
Expand All @@ -158,7 +158,7 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
},
},
},
'/resource2': {
'/resourceTwo': {
post: {
parameters: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getResponseOfGetMethodByMediaType, isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
import {
getResourcePathItems,
getResponseOfGetMethodByMediaType,
isCustomMethodIdentifier,
isResourceCollectionIdentifier,
isSingletonResource,
} from './utils/resourceEvaluation.js';
import { resolveObject } from './utils/componentUtils.js';
import { isDeepEqual, omitDeep } from './utils/compareUtils.js';
import { hasException } from './utils/exceptions.js';
Expand All @@ -12,7 +18,10 @@ export default (input, opts, { path, documentInventory }) => {
const oas = documentInventory.resolved;
const resourcePath = path[1];
let mediaType = input;
if (isCustomMethodIdentifier(resourcePath) || !mediaType.endsWith('json')) {
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
collectException,
handleInternalError,
} from './utils/collectionUtils.js';
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
import {
getResourcePathItems,
isCustomMethodIdentifier,
isResourceCollectionIdentifier,
isSingletonResource,
} from './utils/resourceEvaluation.js';
import { resolveObject } from './utils/componentUtils.js';
import { getSchemaRef } from './utils/methodUtils.js';

Expand All @@ -17,8 +22,15 @@ export default (input, _, { path, documentInventory }) => {
const oas = documentInventory.unresolved;
const resourcePath = path[1];
const contentPerMediaType = resolveObject(oas, path);
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);

if (isCustomMethodIdentifier(resourcePath) || !input.endsWith('json') || !contentPerMediaType.schema) {
const isResourceCollection = isResourceCollectionIdentifier(resourcePath) && !isSingletonResource(resourcePaths);
if (
isCustomMethodIdentifier(resourcePath) ||
!isResourceCollection ||
!input.endsWith('json') ||
!contentPerMediaType.schema
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import {
collectException,
handleInternalError,
} from './utils/collectionUtils.js';
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
import {
getResourcePathItems,
isCustomMethodIdentifier,
isResourceCollectionIdentifier,
isSingletonResource,
} from './utils/resourceEvaluation.js';

const RULE_NAME = 'xgen-IPA-106-create-method-should-not-have-query-parameters';
const ERROR_MESSAGE = 'Create operations should not have query parameters.';

const ignoredParameters = ['envelope', 'pretty'];

export default (input, _, { path }) => {
export default (input, _, { path, documentInventory }) => {
const resourcePath = path[1];
const oas = documentInventory.resolved;
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);

if (isCustomMethodIdentifier(resourcePath)) {
const isResourceCollection = isResourceCollectionIdentifier(resourcePath) && !isSingletonResource(resourcePaths);
if (isCustomMethodIdentifier(resourcePath) || !isResourceCollection) {
return;
}

Expand Down
Loading