liveBook · Manning

GitHub Copilot

As explained in Automating API Delivery

GitHub Copilot is an AI-powered software development tool that generates code and suggestions from programming context and natural-language prompts.

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

How Automating API Delivery covers it

How deep it goes
Explains context and prompting, then walks through rule creation, test generation, and lint execution without replacing review.
Examples
Uses a Spectral description rule, a failing OpenAPI document, and a Spectral lint command.
What it assumes
Builds on OpenAPI documents, Spectral rulesets, VS Code files, and an existing understanding of linting-rule goals.
What you can do after
Apply it via VS Code inline chat to draft and test a Spectral linting rule.
How it connects
Connects AI coding assistants with large language models, prompt engineering, OpenAPI, Spectral, and API linting.

Also explained in

Compare how 5 books explain GitHub Copilot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.