Skip to main content

Class: JSONSchema

protoc_gen_openapiv2.options.JSONSchema

JSONSchema represents properties from JSON Schema taken, and as used, in the OpenAPI v2 spec.

This includes changes made by OpenAPI v2.

See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject

See also: https://cswr.github.io/JsonSchema/spec/basic_types/, https://github.com/json-schema-org/json-schema-spec/blob/master/schema.json

Example:

message SimpleMessage { option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = { json_schema: { title: "SimpleMessage" description: "A simple message." required: ["id"] } };

// Id represents the message identifier. string id = 1; [ (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { description: "The unique identifier of the simple message." }]; }

Properties

array

array: string[]

Items in 'array' must be unique.


default

default: string

JSONSchema default.


description

description: string

A short description of the schema.


enum

enum: string[]

Items in enum must be unique https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1


example

example: string

A free-form property to include a JSON example of this field. This is copied verbatim to the output swagger.json. Quotes must be escaped. This property is the same for 2.0 and 3.0.0 https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/3.0.0.md#schemaObject https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject


exclusiveMaximum

exclusiveMaximum: boolean

JSONSchema exclusiveMaximum.


exclusiveMinimum

exclusiveMinimum: boolean

JSONSchema exclusiveMinimum.


extensions

extensions: Object

Custom properties that start with "x-" such as "x-foo" used to describe extra functionality that is not covered by the standard OpenAPI Specification. See: https://swagger.io/docs/specification/2-0/swagger-extensions/

Index signature

▪ [k: string]: $Properties


fieldConfiguration

Optional fieldConfiguration: null | $Properties

Additional field level properties used when generating the OpenAPI v2 file.


format

format: string

Format


maxItems

maxItems: Long

JSONSchema maxItems.


maxLength

maxLength: Long

JSONSchema maxLength.


maxProperties

maxProperties: Long

JSONSchema maxProperties.


maximum

maximum: number

Maximum represents an inclusive upper limit for a numeric instance. The value of MUST be a number,


minItems

minItems: Long

JSONSchema minItems.


minLength

minLength: Long

JSONSchema minLength.


minProperties

minProperties: Long

JSONSchema minProperties.


minimum

minimum: number

minimum represents an inclusive lower limit for a numeric instance. The value of MUST be a number,


multipleOf

multipleOf: number

JSONSchema multipleOf.


pattern

pattern: string

JSONSchema pattern.


readOnly

readOnly: boolean

JSONSchema readOnly.


ref

ref: string

Ref is used to define an external reference to include in the message. This could be a fully qualified proto message reference, and that type must be imported into the protofile. If no message is identified, the Ref will be used verbatim in the output. For example: ref: ".google.protobuf.Timestamp".


required

required: string[]

JSONSchema required.


title

title: string

The title of the schema.


type

type: JSONSchemaSimpleTypes[]

JSONSchema type.


uniqueItems

uniqueItems: boolean

JSONSchema uniqueItems.

Methods

toJSON

toJSON(): Object

Converts this JSONSchema to JSON.

Returns

Object

JSON object


create

create(properties?): JSONSchema & $Shape

Creates a new JSONSchema instance using the specified properties.

Parameters

NameTypeDescription
properties?$ShapeProperties to set

Returns

JSONSchema & $Shape

JSONSchema instance

create(properties?): JSONSchema

Parameters

NameType
properties?$Properties

Returns

JSONSchema


decode

decode(reader, length?): JSONSchema & $Shape

Decodes a JSONSchema message from the specified reader or buffer.

Parameters

NameTypeDescription
readerUint8Array | ReaderReader or buffer to decode from
length?numberMessage length if known beforehand

Returns

JSONSchema & $Shape

JSONSchema

Throws

If the payload is not a reader or valid buffer

Throws

If required fields are missing


decodeDelimited

decodeDelimited(reader): JSONSchema & $Shape

Decodes a JSONSchema message from the specified reader or buffer, length delimited.

Parameters

NameTypeDescription
readerUint8Array | ReaderReader or buffer to decode from

Returns

JSONSchema & $Shape

JSONSchema

Throws

If the payload is not a reader or valid buffer

Throws

If required fields are missing


encode

encode(message, writer?): Writer

Encodes the specified JSONSchema message. Does not implicitly grpc.gateway.protoc_gen_openapiv2.options.JSONSchema.verify|verify messages.

Parameters

NameTypeDescription
message$PropertiesJSONSchema message or plain object to encode
writer?WriterWriter to encode to

Returns

Writer

Writer


encodeDelimited

encodeDelimited(message, writer?): Writer

Encodes the specified JSONSchema message, length delimited. Does not implicitly grpc.gateway.protoc_gen_openapiv2.options.JSONSchema.verify|verify messages.

Parameters

NameTypeDescription
message$PropertiesJSONSchema message or plain object to encode
writer?WriterWriter to encode to

Returns

Writer

Writer


fromObject

fromObject(object): JSONSchema

Creates a JSONSchema message from a plain object. Also converts values to their respective internal types.

Parameters

NameTypeDescription
objectObjectPlain object

Returns

JSONSchema

JSONSchema


toObject

toObject(message, options?): Object

Creates a plain object from a JSONSchema message. Also converts values to other types if specified.

Parameters

NameTypeDescription
messageJSONSchemaJSONSchema
options?IConversionOptionsConversion options

Returns

Object

Plain object