Skip to content

Instantly share code, notes, and snippets.

@MikeRalphson
Last active December 8, 2020 10:22
Show Gist options
  • Save MikeRalphson/c533a8e977129b616565cfecbc14a6f4 to your computer and use it in GitHub Desktop.
Save MikeRalphson/c533a8e977129b616565cfecbc14a6f4 to your computer and use it in GitHub Desktop.
OpenAPI 3.1 $ref inside and outside schema objects
openapi: 3.1.0
info:
title: My API
version: 1.0.0
paths:
/things:
post:
parameters:
- $ref: '#/components/parameters/type'
description: The type of the thing to submit # only summary and description are effective here, they override any inside the $ref
requestBody:
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/thing'
required:
- name
responses:
'200':
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/thing'
required: # all constraints within and outside the $ref must validate
- id
- name
description: The new thing being returned including its id # all annotations within and outside the $ref are collected (not merged or overridden)
components:
schemas:
thing:
description: Generic description of a thing with no required properties
type: object
properties:
id:
type: integer
name:
type: string
parameters:
type:
description: Generic description of a type parameter
name: type
in: query
schema:
type: string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment