mirror of
https://github.com/LukeHagar/prettier-plugin-openapi.git
synced 2025-12-06 04:21:03 +00:00
7.1 KiB
7.1 KiB
Supported Keys - Complete Reference
This document provides a comprehensive list of all supported keys for Swagger 2.0, OpenAPI 3.0, 3.1, and 3.2 specifications.
Top-Level Keys
All Versions
swagger(Swagger 2.0 only)openapi(OpenAPI 3.0+)infopathssecuritytagsexternalDocs
Version-Specific
jsonSchemaDialect(OpenAPI 3.1+)servers(OpenAPI 3.0+)webhooks(OpenAPI 3.1+)components(OpenAPI 3.0+)host(Swagger 2.0 only)basePath(Swagger 2.0 only)schemes(Swagger 2.0 only)consumes(Swagger 2.0 only)produces(Swagger 2.0 only)definitions(Swagger 2.0 only)parameters(Swagger 2.0 only)responses(Swagger 2.0 only)securityDefinitions(Swagger 2.0 only)
Info Section Keys
All Versions
titledescriptionversiontermsOfServicecontactlicense
Version-Specific
summary(OpenAPI 3.1+)
Contact Section Keys
All Versions
nameurlemail
License Section Keys
All Versions
nameurl
Components Section Keys (OpenAPI 3.0+)
All Versions
schemasresponsesparametersexamplesrequestBodiesheaderssecuritySchemeslinkscallbacks
Version-Specific
pathItems(OpenAPI 3.1+)
Operation Keys
All Versions
tagssummarydescriptionoperationIdparametersresponsesdeprecatedsecurity
Version-Specific
consumes(Swagger 2.0 only)produces(Swagger 2.0 only)requestBody(OpenAPI 3.0+)schemes(Swagger 2.0 only)callbacks(OpenAPI 3.0+)servers(OpenAPI 3.0+)
Parameter Keys
All Versions
nameindescriptionrequireddeprecatedallowEmptyValuestyleexplodeallowReservedschemaexampleexamples
Swagger 2.0 Specific
typeformatitemscollectionFormatdefaultmaximumexclusiveMaximumminimumexclusiveMinimummaxLengthminLengthpatternmaxItemsminItemsuniqueItemsenummultipleOf
Schema Keys
Core JSON Schema Keywords
$schema$id$ref$anchor$dynamicAnchor$dynamicRef$vocabulary$comment$defs$recursiveAnchor$recursiveRef
Basic Type and Format
typeformattitledescriptiondefaultexampleexamplesenumconst
Numeric Validation
multipleOfmaximumexclusiveMaximumminimumexclusiveMinimum
String Validation
maxLengthminLengthpattern
Array Validation
maxItemsminItemsuniqueItemsitemsprefixItemscontainsminContainsmaxContainsunevaluatedItems
Object Validation
maxPropertiesminPropertiesrequiredpropertiespatternPropertiesadditionalPropertiesunevaluatedPropertiespropertyNamesdependentRequireddependentSchemas
Schema Composition
allOfoneOfanyOfnotifthenelse
OpenAPI Specific
discriminatorxmlexternalDocsdeprecated
Additional JSON Schema Keywords
contentEncodingcontentMediaTypecontentSchema
Response Keys
All Versions
descriptionheaders
Version-Specific
content(OpenAPI 3.0+)schema(Swagger 2.0 only)examples(Swagger 2.0 only)links(OpenAPI 3.0+)
Security Scheme Keys
All Versions
typedescriptionnameinschemebearerFormatopenIdConnectUrl
Version-Specific
flows(OpenAPI 3.0+)flow(Swagger 2.0 only)authorizationUrl(Swagger 2.0 only)tokenUrl(Swagger 2.0 only)scopes(Swagger 2.0 only)
OAuth Flow Keys (OpenAPI 3.0+)
All Versions
authorizationUrltokenUrlrefreshUrlscopes
Server Keys
All Versions
urldescriptionvariables
Server Variable Keys
All Versions
enumdefaultdescription
Tag Keys
All Versions
namedescriptionexternalDocs
External Docs Keys
All Versions
descriptionurl
Webhook Keys (OpenAPI 3.1+)
All Versions
tagssummarydescriptionoperationIdparametersrequestBodyresponsescallbacksdeprecatedsecurityservers
Special Sorting Rules
Paths
- Sorted by specificity (more specific paths first)
- Paths with fewer parameters come before paths with more parameters
Response Codes
- Sorted numerically (200, 201, 400, 404, etc.)
- Non-numeric codes sorted alphabetically
Schema Properties
- Sorted alphabetically
Parameters
- Sorted alphabetically
Security Schemes
- Sorted alphabetically
Definitions (Swagger 2.0)
- Sorted alphabetically
Security Definitions (Swagger 2.0)
- Sorted alphabetically
Version Detection
The plugin automatically detects the OpenAPI/Swagger version based on the presence of specific keys:
- Swagger 2.0: Contains
swaggerkey - OpenAPI 3.0: Contains
openapikey with version 3.0.x - OpenAPI 3.1: Contains
openapikey with version 3.1.x - OpenAPI 3.2: Contains
openapikey with version 3.2.x
Custom Extensions
All custom extensions (keys starting with x-) are supported and can be positioned using the configuration arrays at the top of src/index.ts.
Unknown Keys
Keys that are not in the standard arrays or custom extensions configuration will be sorted alphabetically at the bottom of their respective objects.
Examples
Swagger 2.0 Example
swagger: "2.0"
info:
title: My API
version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
- https
paths:
/users:
get:
summary: Get users
responses:
'200':
description: OK
definitions:
User:
type: object
properties:
id:
type: integer
OpenAPI 3.0 Example
openapi: 3.0.0
info:
title: My API
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/users:
get:
summary: Get users
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
components:
schemas:
User:
type: object
properties:
id:
type: integer
OpenAPI 3.1+ Example
openapi: 3.1.0
info:
title: My API
version: 1.0.0
summary: API for managing users
servers:
- url: https://api.example.com/v1
paths:
/users:
get:
summary: Get users
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
webhooks:
userCreated:
post:
summary: User created webhook
responses:
'200':
description: OK
components:
schemas:
User:
type: object
properties:
id:
type: integer
Notes
- The plugin supports all valid keys from all versions
- Version-specific keys are handled appropriately based on the detected version
- Custom extensions are fully supported with configurable positioning
- Unknown keys are sorted alphabetically at the bottom
- All sorting is consistent and predictable