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 @@ -9,6 +9,15 @@ const componentSchemas = {
Schema: {
type: 'object',
},
BadRequest: {
content: {
'application/json': {
schema: {
type: 'string',
},
},
},
},
},
};

Expand Down Expand Up @@ -42,6 +51,9 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
},
},
},
401: {
$ref: '#/components/schemas/BadRequest',
},
Comment on lines +54 to +56
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Example of what caused the failure, since this rule operates on the unresolved schema, this will end up as undefined, since we're trying to get the schema ref inside of /content/version. Also moved the check for 2xx response first to not evaluate these

400: {
content: {
'application/vnd.atlas.2023-01-01+json': {
Expand Down Expand Up @@ -140,7 +152,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
errors: [
{
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
path: [
'paths',
'/resource/{id}',
Expand All @@ -154,7 +166,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
},
{
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
path: [
'paths',
'/resource/{id}',
Expand All @@ -168,7 +180,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
},
{
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
path: [
'paths',
'/resource/{id}',
Expand All @@ -182,7 +194,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
},
{
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
path: [
'paths',
'/resource/{id}/singleton',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export default (input, _, { path }) => {

function checkViolationsAndReturnErrors(input, path) {
try {
console.log(input);
const responses = input.responses;
console.log(responses);
// If there is no 204 response, return a violation
if (!responses || !responses['204']) {
return [{ path, message: ERROR_MESSAGE }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export default (input, _, { path, documentInventory }) => {
const contentPerMediaType = resolveObject(oas, path);

if (
!contentPerMediaType.schema ||
!responseCode.startsWith('2') ||
!contentPerMediaType ||
!contentPerMediaType.schema ||
!input.endsWith('json') ||
(!isSingleResourceIdentifier(resourcePath) &&
!(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { getSchemaRef } from './utils/methodUtils.js';

const RULE_NAME = 'xgen-IPA-104-get-method-returns-response-suffixed-object';
const ERROR_MESSAGE_SCHEMA_NAME = 'The request schema must reference a schema with a Response suffix.';
const ERROR_MESSAGE_SCHEMA_NAME = 'The response body schema must reference a schema with a Response suffix.';
const ERROR_MESSAGE_SCHEMA_REF = 'The response body schema is defined inline and must reference a predefined schema.';

export default (input, _, { path, documentInventory }) => {
Expand All @@ -26,8 +26,9 @@ export default (input, _, { path, documentInventory }) => {
const contentPerMediaType = resolveObject(oas, path);

if (
!contentPerMediaType.schema ||
!responseCode.startsWith('2') ||
!contentPerMediaType ||
!contentPerMediaType.schema ||
!input.endsWith('json') ||
(!isSingleResourceIdentifier(resourcePath) &&
!(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export default (input, _, { path, documentInventory }) => {
const isSingleton = isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths);

if (
!contentPerMediaType.schema ||
!responseCode.startsWith('2') ||
!contentPerMediaType ||
!contentPerMediaType.schema ||
!input.endsWith('json') ||
(!isSingleResource && !isSingleton)
) {
Expand Down
Loading