Understanding Firestone's Generated OpenAPI Specification
The primary output of the firestone generate openapi command is a single openapi.yaml (or JSON) file. This file is a standard OpenAPI 3.x specification that describes your entire API, meticulously generated from your Firestone resource blueprints. Understanding its structure is key to integrating with other tools and debugging issues.
How Firestone Maps Resources to Paths
Firestone translates the methods you define in your resource schema into OpenAPI paths.
Given this methods block in a users.yaml schema:
methods:
resource: [get, post]
instance: [get, put, delete]
Firestone generates two primary paths:
-
The Resource Path:
/usersget: Operation to list all users (corresponds tomethods.resource.get).post: Operation to create a new user (corresponds tomethods.resource.post).
-
The Instance Path:
/users/{user_id}get: Operation to retrieve a single user by its ID (corresponds tomethods.instance.get).put: Operation to update a user (corresponds tomethods.instance.put).delete: Operation to delete a user (corresponds tomethods.instance.delete).
The name of the path parameter (user_id in this case) is taken directly from the schema.key.name field in your resource schema.
How Firestone Maps Schemas to Components
To promote reusability and keep the specification clean, Firestone places all your data models (JSON Schemas) into the components/schemas section.
Your resource schema's items definition:
schema:
type: array
items:
type: object
properties:
first_name:
type: string
email:
type: string
format: email
required: [first_name, email]
Is translated into a reusable component schema, typically named after the resource's kind. For a users resource, you might find a User schema in the components section:
openapi.yaml:
components:
schemas:
User:
type: object
properties:
first_name:
type: string
email:
type: string
format: email
required: [first_name, email]
The operations in the paths section will then reference this component using $ref:
paths:
/users:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
description: "User created successfully"
content:
application/json:
schema:
$ref: '#/components/schemas/User'
Troubleshooting with the Generated Spec
- Endpoint Not Appearing? Check the
methodssection of the corresponding resource schema. Ensure the HTTP verb you're looking for is listed for either theresourceorinstance. - Incorrect Request/Response Body? Examine the
schema.itemsdefinition in your resource schema. The structure defined here is what Firestone uses to create the component schema. Check for missing properties or incorrecttypedeclarations. - Authentication Not Working? Look at the
securitySchemesandsecuritysections at the top level of the spec, as well as at the individual operations underpaths. This will tell you exactly how Firestone interpreted your security definitions.