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." }]; }

Implements

Constructors

constructor

new JSONSchema(properties?): JSONSchema

Constructs a new JSONSchema.

Parameters

NameTypeDescription
properties?IJSONSchemaProperties to set

Returns

JSONSchema

Properties

array

array: string[]

Items in 'array' must be unique.

Implementation of

IJSONSchema.array


default

default: string

JSONSchema default.

Implementation of

IJSONSchema.default


description

description: string

A short description of the schema.

Implementation of

IJSONSchema.description


enum

enum: string[]

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

Implementation of

IJSONSchema.enum


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

Implementation of

IJSONSchema.example


exclusiveMaximum

exclusiveMaximum: boolean

JSONSchema exclusiveMaximum.

Implementation of

IJSONSchema.exclusiveMaximum


exclusiveMinimum

exclusiveMinimum: boolean

JSONSchema exclusiveMinimum.

Implementation of

IJSONSchema.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]: IValue

Implementation of

IJSONSchema.extensions


fieldConfiguration

Optional fieldConfiguration: null | IFieldConfiguration

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

Implementation of

IJSONSchema.fieldConfiguration


format

format: string

Format

Implementation of

IJSONSchema.format


maxItems

maxItems: Long

JSONSchema maxItems.

Implementation of

IJSONSchema.maxItems


maxLength

maxLength: Long

JSONSchema maxLength.

Implementation of

IJSONSchema.maxLength


maxProperties

maxProperties: Long

JSONSchema maxProperties.

Implementation of

IJSONSchema.maxProperties


maximum

maximum: number

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

Implementation of

IJSONSchema.maximum


minItems

minItems: Long

JSONSchema minItems.

Implementation of

IJSONSchema.minItems


minLength

minLength: Long

JSONSchema minLength.

Implementation of

IJSONSchema.minLength


minProperties

minProperties: Long

JSONSchema minProperties.

Implementation of

IJSONSchema.minProperties


minimum

minimum: number

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

Implementation of

IJSONSchema.minimum


multipleOf

multipleOf: number

JSONSchema multipleOf.

Implementation of

IJSONSchema.multipleOf


pattern

pattern: string

JSONSchema pattern.

Implementation of

IJSONSchema.pattern


readOnly

readOnly: boolean

JSONSchema readOnly.

Implementation of

IJSONSchema.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".

Implementation of

IJSONSchema.ref


required

required: string[]

JSONSchema required.

Implementation of

IJSONSchema.required


title

title: string

The title of the schema.

Implementation of

IJSONSchema.title


type

type: JSONSchemaSimpleTypes[]

JSONSchema type.

Implementation of

IJSONSchema.type


uniqueItems

uniqueItems: boolean

JSONSchema uniqueItems.

Implementation of

IJSONSchema.uniqueItems

Methods

toJSON

toJSON(): Object

Converts this JSONSchema to JSON.

Returns

Object

JSON object


create

create(properties?): JSONSchema

Creates a new JSONSchema instance using the specified properties.

Parameters

NameTypeDescription
properties?IJSONSchemaProperties to set

Returns

JSONSchema

JSONSchema instance


decode

decode(reader, length?): JSONSchema

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

JSONSchema

Throws

If the payload is not a reader or valid buffer

Throws

If required fields are missing


decodeDelimited

decodeDelimited(reader): JSONSchema

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

Parameters

NameTypeDescription
readerUint8Array | ReaderReader or buffer to decode from

Returns

JSONSchema

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
messageIJSONSchemaJSONSchema 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
messageIJSONSchemaJSONSchema 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


getTypeUrl

getTypeUrl(typeUrlPrefix?): string

Gets the default type url for JSONSchema

Parameters

NameTypeDescription
typeUrlPrefix?stringyour custom typeUrlPrefix(default "type.googleapis.com")

Returns

string

The default type url


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