The API for which I\'m writing a Swagger 2.0 specification is basically a store for any JSON value.
I want a path to read value and a path to store any JSON values (
Maybe this is what your are looking for "Patterned Objects":
Field Pattern: ^x-
Type: Any
Description: Allows extensions to the Swagger Schema. The field name MUST begin with x-, for example, x-internal-id. The value can be null, a primitive, an array or an object. See Vendor Extensions for further details.
Source: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md
An arbitrary-type schema can be defined using an empty schema {}
:
# swagger: '2.0'
definitions:
AnyValue: {}
# openapi: 3.0.0
components:
schemas:
AnyValue: {}
or if you want a description
:
# swagger: '2.0'
definitions:
AnyValue:
description: 'Can be anything: string, number, array, object, etc. (except `null`)'
# openapi: 3.0.0
components:
schemas:
AnyValue:
description: 'Can be anything: string, number, array, object, etc., including `null`'
Without a defined type
, a schema allows any values. Note that OpenAPI 2.0 Specification does not support null
values, but some tools might support nulls nevertheless.
In OpenAPI 3.0, type
-less schemas allow null
values unless nulls are explicitly disallowed by other constraints (such as an enum
).
See this Q&A for more details on how type
-less schemas work.
Here's how Swagger Editor 2.0 handles a body parameter with the AnyValue
schema:
I don't know how code generators handle this though.