Linting Rules - Swagger V2 Produce JSON Media Type

Number of APIs: 2

This is a Spectral governance rule to enforce that a Swagger produces application/json media types. Here is a JSON version of the rule that can be applied using this API-driven collection API, or at CLI or CI/CD pipeline.

{
  "swagger-v2-produce-json-media-type": {
    "description": "Ensures that application/json media types are able to be produced.",
    "message": "The APIs should be able to produce application/json media types.",
    "severity": "error",
    "recommended": true,
    "format": "oas2",
    "given": "$..produces.*",
    "then": {
      "function": "schema",
      "functionOptions": {
        "schema": {
          "type": "string",
          "enum": [
            "application/json"
          ]
        }
      }
    }
  }
}

This request can be run as part of this collection, or dragged and dropped to another collection of governance requests organized by folder, demonstrating how API governance linting works, but also providing a rule that can be used as part of your wider API governance strategy.

  1. Swagger V2 Produce JSON Media Type POST {{baseUrl}}/linter/?rulesUrl=https://rules.linting.org/rules/swagger-v2-produce-json-media-type/

  2. Swagger V2 Produce JSON Media Type POST {{baseUrl}}/linter?rulesUrl=https://rules.linting.org/rules/swagger-v2-produce-json-media-type/