GitHub Copilot is an AI coding assistant that uses programming context and natural-language prompts to analyze code, generate lines or functions, and suggest improvements. It acts like a junior pair programmer, reducing boilerplate so developers can focus on higher-level problems while retaining responsibility for testing and review. section 3.10
Use Copilot effectively by controlling its context and validating its output:
- Open related OpenAPI documents and Spectral rulesets so Copilot can use relevant editor context. section 3.10.1
- Add a top-level comment explaining the file and provide nearby sample code when more guidance is needed. section 3.10.1
- Review generated code and test it because large-language-model output can vary between runs. section 3.10 section 3.10.1
Generate and test an API linting rule
Create chapter3/copilot/rules.yaml, open Copilot inline chat with ⌘–I on Mac or Ctrl–I on Windows, and request a Spectral rule requiring $.info.description. Then create openapi.yaml with the same workflow, asking for a document that makes the rule fail. From the directory, run `spectral lint openapi.yaml --ruleset rules.yaml`; the expected result is a linting-rule violation. section 3.10.1
Write a Spectral linting rule for an OpenAPI file that checks that the info.description field is present
Use the supplied prompt as a starting point for generating a Spectral rule that checks whether OpenAPI info.description is present. section 3.10.1
rules:
openapi-info-description-present:
description: "Check if the info.description field is present"
message: "The info.description field is missing"
given: "$.info"
then:
field: "description"
function: "truthy"
Inspect the generated YAML rule, including its description, message, JSONPath target, field, and truthy validation function. section 3.10.1
openapi: 3.0.0
info:
title: My API #1
version: 1.0.0
paths:
/path/to/endpoint:
get:
summary: Endpoint Summary
description: Endpoint Description
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
Use the deliberately incomplete OpenAPI document as a negative test fixture for the description rule. section 3.10.1
spectral lint openapi.yaml --ruleset rules.yaml
Run the generated rule against the test document with the Spectral command-line interface. section 3.10.1




