Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kinlane/bb60157440c2665be7c68a4ae2b91bec to your computer and use it in GitHub Desktop.
Save kinlane/bb60157440c2665be7c68a4ae2b91bec to your computer and use it in GitHub Desktop.
api-commons-train-travel-openapi-spectral-rules
rules:
apis-json-name-negative:
description: Name of APIs.json
message: There MUST be a name.
severity: error
given: $
then:
field: name
function: truthy
apis-json-name-positive:
description: Name of APIs.json
message: There is a name.
severity: info
given: $
then:
field: name
function: falsy
apis-json-description-negative:
description: Description of APIs.json
message: There MUST be a description.
given: $
severity: error
then:
field: description
function: truthy
apis-json-description-positive:
description: Description of APIs.json
message: There is a description.
given: $
severity: info
then:
field: description
function: falsy
apis-json-image-negative:
description: Image of APIs.json
message: There MUST be an image.
given: $
severity: error
then:
field: image
function: truthy
apis-json-image-positive:
description: Image of APIs.json
message: There is an image.
given: $
severity: info
then:
field: image
function: falsy
apis-json-specification-aid-negative:
description: >-
Ensures that each APIs.json has a unique identifier expressed as an `aid`.
APIs.json identifiers are a standardized format for allowing API producers
to establish a unique identifier for each API contract they provide using
APIs.json, which will then be prepended to each APIs defined. You can find
details about the standard for APIs.json unique identifier on API Commons
[need link], and explore <a
href="https://apievangelist.com/guidance/identifiers/apis-json-identifier/"
target="_blank">APIs.json Unique Identifiers</a> via API Evangelist.
message: There MUST be a aid.
severity: error
given: $
then:
field: aid
function: truthy
apis-json-specification-aid-positive:
description: >-
Ensures that each APIs.json has a unique identifier expressed as an `aid`.
APIs.json identifiers are a standardized format for allowing API producers
to establish a unique identifier for each API contract they provide using
APIs.json, which will then be prepended to each APIs defined. You can find
details about the standard for APIs.json unique identifier on API Commons
[need link], and explore <a
href="https://apievangelist.com/guidance/identifiers/apis-json-identifier/"
target="_blank">APIs.json Unique Identifiers</a> via API Evangelist.
message: There is an aid.
severity: info
given: $
then:
field: aid
function: falsy
apis-json-url-negative:
description: URL for APIs.json
message: There MUST be a URL.
given: $
severity: error
then:
field: url
function: truthy
apis-json-url-positive:
description: URL for APIs.json
message: There is a URL.
given: $
severity: info
then:
field: url
function: falsy
apis-json-created-negative:
description: Created for APIs.json
message: There MUST be a created date.
given: $
severity: error
then:
field: created
function: truthy
apis-json-created-positive:
description: Created for APIs.json
message: There is a created date.
given: $
severity: info
then:
field: created
function: falsy
apis-json-modified-negative:
description: Modified for APIs.json
message: There COULD be a modified date.
given: $
severity: warn
then:
field: modified
function: truthy
apis-json-modified-positive:
description: Modified for APIs.json
message: There is a modified date.
given: $
severity: info
then:
field: modified
function: falsy
apis-json-specification-type-negative:
description: Specification Type
message: There MUST be a specification type.
severity: error
given: $
then:
field: type
function: truthy
apis-json-specification-type-positive:
description: Specification Type
message: There is a specification type.
severity: info
given: $
then:
field: type
function: falsy
apis-json-specification-version-negative:
description: Specification Version
message: There MUST be a specification version.
severity: error
given: $
then:
field: specificationVersion
function: truthy
apis-json-specification-version-positive:
description: Specification Version
message: There is a specification version.
severity: info
given: $
then:
field: specificationVersion
function: falsy
apis-json-tags-negative:
description: Tags for APIs.json
message: There MUST be a tags object..
given: $
severity: error
then:
field: tags
function: truthy
apis-json-tags-one-negative:
description: One Tag for APIs.json
message: There MUST be at least one tag.
given: $
severity: error
then:
field: tags
function: length
functionOptions:
min: 1
apis-json-tags-positive:
description: Tags for APIs.json
message: There is a tags object.
given: $
severity: info
then:
field: tags
function: falsy
apis-json-tags-upper-case-error:
description: Upper Case Tag for APIs/json
message: Tags Upper Case
severity: error
given: $.tags.*
then:
function: pattern
functionOptions:
match: '[A-Z]\w*'
apis-json-tags-upper-case-info:
description: Upper Case Tag for APIs/json
message: Tags Upper Case
severity: info
given: $.tags.*
then:
function: pattern
functionOptions:
notMatch: '[A-Z]\w*'
apis-json-maintainers-email-negative:
description: Maintainers Email
message: There MUST be an email property for maintainers.
given: $.maintainers.*
severity: error
then:
field: email
function: truthy
apis-json-maintainers-email-positive:
description: Maintainers Email
message: There is a email property for maintainers.
given: $.maintainers.*
severity: info
then:
field: email
function: falsy
apis-json-maintainers-fn-negative:
description: Maintainers for APIs.json
message: There MUST be a FN property for maintainers.
given: $.maintainers.*
severity: error
then:
field: FN
function: truthy
apis-json-maintainers-fn-positive:
description: Maintainers for APIs.json
message: There is a FN property for maintainers.
given: $.maintainers.*
severity: info
then:
field: FN
function: falsy
apis-json-maintainers-negative:
description: Maintainers for APIs.json
message: There MUST be a maintainer object.
given: $
severity: error
then:
field: maintainers
function: truthy
apis-json-maintainers-positive:
description: Maintainers for APIs.json
message: There is a maintainer object.
given: $
severity: info
then:
field: maintainers
function: falsy
apis-json-apis-aid-negative:
description: >-
Ensures that each APIs indexed within an APIs.json can have a unique
identifier expressed as an `aid`. API identifiers (AID) are a standardized
format for allowing API producers to establish a unique identifier for
each API they publish using APIs.json, which will have the aid for the
APIs.json prepended to each APIs aid. You can find details about the
standard for APIs.json unique identifier on API Commons [need link], and
explore <a
href="https://apievangelist.com/guidance/identifiers/api-identifier/"
target="_blank">API Unique Identifiers</a> via API Evangelist.
message: APIs MUST have a aid.
given: $.apis.*
severity: error
then:
field: aid
function: truthy
apis-json-apis-aid-positive:
description: >-
Ensures that each APIs indexed within an APIs.json can have a unique
identifier expressed as an `aid`. API identifiers (AID) are a standardized
format for allowing API producers to establish a unique identifier for
each API they publish using APIs.json, which will have the aid for the
APIs.json prepended to each APIs aid. You can find details about the
standard for APIs.json unique identifier on API Commons [need link], and
explore <a
href="https://apievangelist.com/guidance/identifiers/api-identifier/"
target="_blank">API Unique Identifiers</a> via API Evangelist.
message: API has a aid.
given: $.apis.*
severity: info
then:
field: aid
function: falsy
apis-json-apis-name-negative:
description: Name of APIs
message: APIs MUST have a name.
given: $.apis.*
severity: error
then:
field: name
function: truthy
apis-json-apis-name-positive:
description: Name of APIs
message: API has a name.
given: $.apis.*
severity: info
then:
field: name
function: falsy
apis-json-apis-description-negative:
description: Description of APIs
message: APIs MUST have a description.
given: $.apis.*
severity: error
then:
field: description
function: truthy
apis-json-apis-description-positive:
description: Description of APIs
message: API has a description.
given: $.apis.*
severity: info
then:
field: description
function: falsy
apis-json-apis-image-negative:
description: Image of APIs
message: APIs MUST have an image.
given: $.apis.*
severity: error
then:
field: image
function: truthy
apis-json-apis-image-positive:
description: Image of APIs
message: API has an image.
given: $.apis.*
severity: info
then:
field: image
function: falsy
apis-json-apis-humanURL-negative:
description: Human URL for APIs
message: APIs MUST have a human URL.
given: $.apis.*
severity: error
then:
field: humanURL
function: truthy
apis-json-apis-humanURL-positive:
description: Human URL for APIs
message: APIs has a human URL.
given: $.apis.*
severity: info
then:
field: humanURL
function: falsy
apis-json-apis-baseURL-negative:
description: Base URL for APIs
message: APIs MUST have a base URL.
given: $.apis.*
severity: error
then:
field: baseURL
function: truthy
apis-json-apis-baseURL-positive:
description: Base URL for APIs
message: APIs has a base URL.
given: $.apis.*
severity: info
then:
field: baseURL
function: falsy
apis-json-apis-negative:
description: APIs for APIs.json
message: There MUST be an apis property.
given: $
severity: error
then:
field: apis
function: truthy
apis-json-apis-positive:
description: APIs for APIs.json
message: There is an apis property..
given: $
severity: info
then:
field: apis
function: falsy
apis-json-common-negative:
description: Common property for APIs.json
message: There MUST be a common property.
given: $
severity: error
then:
field: common
function: truthy
apis-json-common-positive:
description: Common property for APIs.json
message: There is an common property.
given: $
severity: info
then:
field: common
function: falsy
apis-json-apis-properties-documentation-positive:
description: API Properties Documentation
message: There is a documentation property.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(documentation|Documentation)\b
apis-json-apis-properties-management-authentication-positive:
description: API Properties Management Authentication
message: Has authentication.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(Authentication)\b
apis-json-apis-properties-management-getting-started-info:
description: API Properties Management Getting Started
message: Has a getting started.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(GettingStarted)\b
apis-json-apis-properties-documentation-openapi-positive:
description: API Properties Documentation OpenAPI
message: API has and OpenAPI.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(openapi|OpenAPI)\b
apis-json-apis-properties-documentation-postman-collection-positive:
description: API Properties Documentation Postman Collection
message: Has a Postman Collection.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(PostmanCollection)\b
apis-json-apis-properties-documentation-insomnia-collection-positive:
description: API Properties Documentation Insomnia Collection
message: Has a Insomnia Collection.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(RunInInsomnia)\b
apis-json-apis-properties-change-change-log-positive:
description: API Properties Change Change Log
message: Has change log.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(api-change-log|change-log|Change Log|Changelog|ChangeLog)\b
apis-json-apis-properties-change-compare-positive:
description: API Properties Change Compare
message: Has API compare.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(compare|Compare)\b
apis-json-apis-properties-change-road-map-positive:
description: API Properties Change Road Map
message: Has road map.
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: type
function: pattern
functionOptions:
notMatch: \b(api-road-map|road-map|Roadmap|Road Map)\b
apis-json-apis-properties-url-positive:
description: API Properties URL
message: API Properties URL
severity: info
given:
- $.apis.*.properties.*
- $.common.*
then:
- field: url
function: pattern
functionOptions:
notMatch: >-
^((http|https)://)[-a-zA-Z0-9@:%._\+~#?&//=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%._\+~#?&//=]*)$
apis-json-apis-contact-negative:
description: Contact for API
message: API COULD have a contact.
severity: warn
given:
- $.apis.*
then:
field: contact
function: truthy
apis-json-apis-contact-positive:
description: Contact for API
message: API has a contact.
severity: info
given:
- $.apis.*
then:
field: contact
function: falsy
apis-json-apis-contact-email-negative:
description: Contact email for API
message: API contact COULD have email.
given: $.apis.*.contact.*
severity: error
then:
field: email
function: truthy
apis-json-apis-contact-email-positive:
description: Contact email for API
message: API contact has email.
given: $.apis.*.contact.*
severity: info
then:
field: email
function: falsy
apis-json-apis-contact-fn-negative:
description: Contact FN for API
message: API contact COULD have FN.
given: $.apis.*.contact.*
severity: error
then:
field: FN
function: truthy
apis-json-apis-contact-fn-positive:
description: Contact FN for API
message: API contact has FN.
given: $.apis.*.contact.*
severity: info
then:
field: FN
function: falsy
apis-json-apis-tags-negative:
description: Tags for API
message: APIs MUST have a tags object.
given: $.apis.*
severity: error
then:
field: tags
function: truthy
apis-json-apis-tags-one-negative:
description: One Tag for API
message: >-
Having at least one tag for your APIs helps ensure that it will be more
discoverable.
given: $.apis.*
severity: error
then:
field: tags
function: length
functionOptions:
min: 1
apis-json-apis-tags-positive:
description: Tags for API
message: API has tags object.
given: $.apis.*
severity: info
then:
field: tags
function: falsy
apis-json-apis-tags-upper-case-error:
description: Upper Case Tag for API
message: API Tags Upper Case
severity: error
given: $.apis.*.tags.*
then:
function: pattern
functionOptions:
match: '[A-Z]\w*'
apis-json-apis-tags-upper-case-info:
description: Upper Case Tag for API
message: API Tags Upper Case
severity: info
given: $.apis.*.tags.*
then:
function: pattern
functionOptions:
notMatch: '[A-Z]\w*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment