Skip to main content

Example 7. Macros

JSight API 0.3OpenAPI 3.0.1 (Swagger)
JSIGHT 0.3

GET /cats // Get all cats.
200 [@cat]
PASTE @errorResponses

GET /cats/{id} // Get a cat by its id.
200 @cat
PASTE @errorResponses

TYPE @cat // Type “Cat”.
{
"id" : 1,
"name": "Tom"
}

MACRO @errorResponses
400 any
401 any
405 any
500 any

Macros are a powerful feature of the JSight API language. It allows you to reuse parts of code as many times as you like.

More about macros: Quick Tutorial. Magic directive MACRO.

Star us on GitHub — it motivates us a lot!

openapi: 3.0.1
info:
title: ""
version: ""
paths:
/cats:
get:
summary: Get all cats.
responses:
200:
description: ""
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Cat'
400:
$ref: '#/components/responses/Error400'
401:
$ref: '#/components/responses/Error401'
405:
$ref: '#/components/responses/Error405'
500:
$ref: '#/components/responses/Error500'
/cats/{id}:
get:
description: "Get a cat by its id."
parameters:
- name: id
in: path
required: true
schema: {}
responses:
200:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
400:
$ref: '#/components/responses/Error400'
401:
$ref: '#/components/responses/Error401'
405:
$ref: '#/components/responses/Error405'
500:
$ref: '#/components/responses/Error500'
components:
schemas:
Cat:
description: Type “Cat”.
type: object
required: [id, name]
properties:
id:
type: integer
example: 1
name:
type: string
example: "Tom"
responses:
Error400:
description: ""
content:
application/json:
schema: {}
Error401:
description: ""
content:
application/json:
schema: {}
Error405:
description: ""
content:
application/json:
schema: {}
Error500:
description: ""
content:
application/json:
schema: {}