Skip to content

Commit

Permalink
fix: disable info-contact & operation-tag-defined rule
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur310 committed Feb 3, 2025
1 parent 87388f1 commit d025297
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@ const ruleset = {
extends: [oas],
// the rules defined below are based on recommendations from https://docs.google.com/document/d/1WwfAPlB4YKHyRhLm1g_hHZja4hjbYkoTrIqIZvGxE5s/edit?tab=t.0
rules: {
'info-contact': {
description: 'info-contact rule disabled',
given: '$',
message: 'info-contact rule disabled',
then: {
field: 'info',
function: schema,
functionOptions: {
schema: {
type: 'object',
properties: {
contact: {}
}
}
}
}
},
'operation-tag-defined': {
description: 'operation-tag-defined rule disabled',
given: '$.paths[*][get,post,put,delete,patch]',
message: 'operation-tag-defined rule disabled',
then: {
function: schema,
functionOptions: {
schema: {
type: 'object',
properties: {
tags: {}
}
}
}
}
},
'openapi-version': {
description: 'openapi version must be 3.0.0',
given: '$',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,130 @@ components:
expect(JSON.stringify(result)).not.toMatch(/operations-parameters-content/);
});

it('should not log info-contact & operation-tag-defined', async () => {
const inputYaml = `openapi: 3.0.0
info:
title: CaseManager
version: 1.0.0
description: This is auto-generated OpenAPI v3 spec for CaseManager.
paths:
/CaseManager/getCaseById:
get:
summary: Retrieve a Case record using the provided Case ID.
description: Method to retrieve a Case record using the provided Case ID.
tags:
- Case Management
responses:
'200':
description: The Case record retrieved.
content:
application/json:
schema:
$ref: '#/components/schemas/Case'
operationId: getCaseById
/CaseManager/createCase:
post:
summary: Create a new Case record
description: Method to create a new Case record with the provided details.
tags:
- Case Management
requestBody:
content:
application/json:
schema:
type: object
properties:
subject:
type: string
status:
type: string
origin:
type: string
priority:
type: string
responses:
'200':
description: The newly created Case ID
content:
application/json:
schema:
$ref: '#/components/schemas/Id'
operationId: createCase
/CaseManager/deleteCase:
delete:
summary: Deletes a Case record using the provided Case ID.
description: Method to delete a Case record using the provided Case ID.
tags:
- Case Management
responses:
'204':
description: Case record successfully deleted.
operationId: deleteCase
/CaseManager/upsertCase:
put:
summary: Upsert a Case record using the provided details and Case ID.
description: Method to upsert a Case record using the provided details and Case ID.
tags:
- Case Management
parameters:
- name: subject
in: query
required: true
schema:
type: string
- name: status
in: query
required: true
schema:
type: string
- name: origin
in: query
required: true
schema:
type: string
- name: priority
in: query
required: true
schema:
type: string
- name: id
in: query
required: true
schema:
type: string
responses:
'200':
description: The Case ID of the upserted Case.
content:
application/json:
schema:
$ref: '#/components/schemas/Id'
operationId: upsertCase
components:
schemas:
Case:
type: object
properties:
CaseNumber:
type: string
Subject:
type: string
Status:
type: string
Origin:
type: string
Priority:
type: string
Id:
type: string
description: The unique identifier of the Case record.`;

const result = await runRulesetAgainstYaml(inputYaml);

expect(JSON.stringify(result)).not.toMatch(/info-contact/);
expect(JSON.stringify(result)).not.toMatch(/operation-tag-defined/);
});

const runRulesetAgainstYaml = async (inputYaml: string) => {
const spectral = new Spectral();

Expand Down

0 comments on commit d025297

Please sign in to comment.