Documentation
¶
Overview ¶
Package model contains JSON models of Open-RPC spec. See source in https://spec.open-rpc.org link.
Index ¶
- type Components
- type Contact
- type ContentDescriptor
- type Error
- type Example
- type ExamplePairing
- type ExternalDocs
- type Info
- type License
- type MapPropertiesString
- type MapPropertyNumber
- type Method
- type OpenRPC
- type ParamStructure
- type Reference
- type Schema
- type SchemaProperty
- type SchemaPropertyItem
- type SchemaType
- type Server
- type ServerVariable
- type ServiceDescriptions
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Components ¶
type Components struct { // An object to hold reusable Content Descriptor Objects. ContentDescriptors map[string]*ContentDescriptor `json:"contentDescriptors,omitempty"` // An object to hold reusable Schema Objects. Schemas map[string]*Schema `json:"schemas,omitempty"` // An object to hold reusable Tag Objects. Tags map[string]*Tag `json:"tags,omitempty"` }
Components holds a set of reusable objects for different aspects of the OpenRPC. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.
type Contact ¶
type Contact struct { // The identifying name of the contact person/organization. Name string `json:"name,omitempty"` // The URL pointing to the contact information. MUST be in the format of a URL. URL string `json:"url,omitempty"` // The email address of the contact person/organization. MUST be in the format of an email address. Email string `json:"email,omitempty"` }
Contact information for the exposed API.
type ContentDescriptor ¶
type ContentDescriptor struct { // REQUIRED. Name of the content that is being described. If the content described is a method // parameter assignable by-name, this field SHALL define the parameter’s key (ie name). Name string `json:"name"` // A short summary of the content that is being described. Summary string `json:"summary,omitempty"` // A verbose explanation of the content descriptor behavior. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // REQUIRED. Schema that describes the content. Reference to Schema object. Schema *Reference `json:"schema"` // Determines if the content is a required field. Default value is false. Required bool `json:"required,omitempty"` // Specifies that the content is deprecated and SHOULD be transitioned out of usage. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` }
ContentDescriptor Content Descriptors are objects that do just as they suggest - describe content. They are reusable ways of describing either parameters or result. They MUST have a schema.
func (*ContentDescriptor) Reference ¶
func (c *ContentDescriptor) Reference() *Reference
Reference creates reference to described ContentDescriptor object in Components.
type Error ¶
type Error struct { // REQUIRED. A Number that indicates the error type that occurred. This MUST be an integer. // The error codes from and including -32768 to -32000 are reserved for pre-defined errors. // These pre-defined errors SHOULD be assumed to be returned from any JSON-RPC api. Code int `json:"code"` // REQUIRED. A String providing a short description of the error. // The message SHOULD be limited to a concise single sentence. Message string `json:"message"` // A Primitive or Structured value that contains additional information about the error. // This may be omitted. The value of this member is defined by the Server // (e.g. detailed error information, nested errors etc.). Data json.RawMessage `json:"data,omitempty"` }
Error defines an application level error.
type Example ¶
type Example struct { // Canonical name of the example. Name string `json:"name"` // Short description for the example. Summary string `json:"summary,omitempty"` // A verbose explanation of the example. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // Embedded literal example. The value field and externalValue field are mutually exclusive. // To represent examples of media types that cannot naturally represented in JSON, // use a string value to contain the example, escaping where necessary. Value json.RawMessage `json:"value,omitempty"` // A URL that points to the literal example. This provides the capability // to reference examples that cannot easily be included in JSON documents. // The value field and externalValue field are mutually exclusive. ExternalValue string `json:"externalValue,omitempty"` }
Example is an object the defines an example that is intended to match a given Content Descriptor Schema. If the Content Descriptor Schema includes examples, the value from this Example Object supercedes the value of the schema example.
type ExamplePairing ¶
type ExamplePairing struct { // Name for the example pairing. Name string `json:"name"` // Short description for the example pairing. Summary string `json:"summary,omitempty"` // A verbose explanation of the example pairing. Description string `json:"description,omitempty"` // Example parameters. Params []*Example `json:"params"` // Example result. Result *Example `json:"result"` }
ExamplePairing consists of a set of example params and result. The result is what you can expect from the JSON-RPC service given the exact params.
type ExternalDocs ¶
type ExternalDocs struct { // A verbose explanation of the target documentation. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // REQUIRED. The URL for the target documentation. Value MUST be in the format of a URL. URL string `json:"url"` }
ExternalDocs allows referencing an external resource for extended documentation.
type Info ¶
type Info struct { // REQUIRED. The title of the application. Title string `json:"title"` // A verbose description of the application. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A URL to the Terms of Service for the API. MUST be in the format of a URL. TermsOfService string `json:"termsOfService,omitempty"` // The contact information for the exposed API. Contact *Contact `json:"contact,omitempty"` // The license information for the exposed API. License *License `json:"license,omitempty"` // REQUIRED. The version of the OpenRPC document // (which is distinct from the OpenRPC Specification version or // the API implementation version). Version string `json:"version"` }
Info the object provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.
type License ¶
type License struct { // REQUIRED. The license name used for the API. Name string `json:"name"` // A URL to the license used for the API. MUST be in the format of a URL. URL string `json:"url,omitempty"` }
License information for the exposed API.
type MapPropertiesString ¶
type MapPropertiesString map[string]*SchemaProperty
MapPropertiesString type to show map["key"] = value.
type MapPropertyNumber ¶
type MapPropertyNumber map[int]*SchemaProperty
MapPropertyNumber field to show map[0] = value.
type Method ¶
type Method struct { // REQUIRED. The canonical name for the method. The name MUST be unique within the methods array. Name string `json:"name"` // A list of tags for API documentation control. Tags can be used for logical grouping of // methods by resources or any other qualifier. Tags []*Reference `json:"tags,omitempty"` // A short summary of what the method does. Summary string `json:"summary,omitempty"` // A verbose explanation of the method behavior. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this method. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // REQUIRED. A list of parameters that are applicable for this method. // The list MUST NOT include duplicated parameters and therefore require name to be unique. // The list can use the Reference Object to link to parameters that are defined // by the Content Descriptor Object. // All optional params (content descriptor objects with “required”: false) // MUST be positioned after all required params in the list. // It is reference to ContentDescriptor. Params []*Reference `json:"params"` // REQUIRED. The description of the result returned by the method. It is be a Content Descriptor. Result *Reference `json:"result"` // A list of custom application defined errors that MAY be returned. // The Errors MUST have unique error codes. Errors []*Error `json:"errors,omitempty"` // An alternative servers array to service this method. // If an alternative servers array is specified at the Root level, it will be overridden by this value. Servers []*Server `json:"servers,omitempty"` // The expected format of the parameters. As per the JSON-RPC 2.0 specification, // the params of a JSON-RPC request object may be an array, object, or either // (represented as by-position, by-name, and either respectively). // When a method has a paramStructure value of by-name, // callers of the method MUST send a JSON-RPC request object whose params field is an object. // Further, the key names of the params object MUST be the same as the contentDescriptor.names // for the given method. Defaults to "either". ParamStructure ParamStructure `json:"paramStructure,omitempty"` // Array of Example Pairing Object where each example // includes a valid params-to-result Content Descriptor pairing. Examples []*ExamplePairing `json:"examples,omitempty"` // Declares this method to be deprecated. Consumers SHOULD refrain from usage of the declared method. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` }
Method describes the interface for the given method name. The method name is used as the `method` field of the JSON-RPC body. It therefore MUST be unique.
type OpenRPC ¶
type OpenRPC struct { // REQUIRED. This string MUST be the semantic version number of the // OpenRPC Specification version that the OpenRPC document uses. Openrpc string `json:"openrpc"` // REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required. Info *Info `json:"info"` // An array of Server Objects, which provide connectivity information to a target server. // If the servers property is not provided, or is an empty array, // the default value would be a Server Object with a url value of localhost Servers []*Server `json:"servers,omitempty"` // REQUIRED. The available methods for the API. While it is required, // the array may be empty (to handle security filtering, for example). Methods []*Method `json:"methods"` // An element to hold various schemas for the specification. Components *Components `json:"components,omitempty"` // Additional external documentation. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` }
OpenRPC this is the root object of the OpenRPC document. The contents of this object represent a whole OpenRPC document. How this object is constructed or stored is outside the scope of the OpenRPC Specification.
type ParamStructure ¶
type ParamStructure string
ParamStructure the expected format of the parameters. As per the JSON-RPC 2.0 specification, the params of a JSON-RPC request object may be an array, object, or either.
const ( ParamStructureByName ParamStructure = "by-name" ParamStructureByPosition ParamStructure = "by-position" ParamStructureByEither ParamStructure = "either" )
List of the ParamStructure variants.
type Reference ¶
type Reference struct { // REQUIRED. The reference string. Ref string `json:"$ref"` }
Reference a simple object to allow referencing other components in the specification, internally and externally. The Reference Object is defined by JSON Schema and follows the same structure, behavior and rules.
type Schema ¶
type Schema struct { // A name of scheme MUST to be unique. Name string `json:"-"` // Type of the scheme. Type SchemaType `json:"type"` // A verbose explanation of the schema. Description string `json:"description,omitempty"` // List of the required properties. Required []string `json:"required,omitempty"` // Properties list of the properties if Type is object. Properties map[string]*SchemaProperty `json:"properties,omitempty"` // Enum list of string type. Enum []string `json:"enum,omitempty"` }
Schema allows the definition of input and output data types. The Schema Objects MUST follow the specifications outline in the JSON Schema Specification 7. This is a simplified version.
func (*Schema) ReferenceAsProperty ¶
func (s *Schema) ReferenceAsProperty() *SchemaProperty
ReferenceAsProperty create reference to Schema object in Components as SchemaPropertyItem.
func (*Schema) ReferenceAsPropertyItem ¶
func (s *Schema) ReferenceAsPropertyItem() *SchemaPropertyItem
ReferenceAsPropertyItem create reference to Schema object in Components as SchemaPropertyItem.
type SchemaProperty ¶
type SchemaProperty struct { // Reference to another the scheme. Other fields MUST be empty if this not. Ref string `json:"$ref,omitempty"` // Type of the property. // Has one of six primitive types. Type SchemaType `json:"type,omitempty"` // Title of the property Title string `json:"title,omitempty"` // A verbose explanation of the property. Description string `json:"description,omitempty"` // Using if type is 'array'. Items *SchemaPropertyItem `json:"items,omitempty"` // ContentEncoding of the type string. Example "base64". ContentEncoding string `json:"contentEncoding,omitempty"` // Marks that property is deprecated. Deprecated bool `json:"deprecated,omitempty"` // Properties fields to show key -> value of the map. Use MapPropertyNumber or MapPropertiesString types. Properties interface{} `json:"properties,omitempty"` // PatternProperties helps to define map. // Examples: // ".*": {"type":"number"} -> {"field":1} // "\d+": {"$ref":"/path/to/type"} -> {3:object{}} PatternProperties map[string]*SchemaProperty `json:"patternProperties,omitempty"` }
SchemaProperty describes property of the scheme.
type SchemaPropertyItem ¶
type SchemaPropertyItem struct { Ref string `json:"$ref,omitempty"` Type SchemaType `json:"type,omitempty"` }
SchemaPropertyItem describes items of the property with type 'array'. Only one field must be filled.
type SchemaType ¶
type SchemaType string
SchemaType has one of six primitive types: null, boolean, object, array, number, string.
const ( SchemaTypeNull SchemaType = "null" SchemaTypeBoolean SchemaType = "boolean" SchemaTypeObject SchemaType = "object" SchemaTypeArray SchemaType = "array" SchemaTypeNumber SchemaType = "number" SchemaTypeString SchemaType = "string" )
List of the primitive types.
type Server ¶
type Server struct { // REQUIRED. A name to be used as the canonical name for the server. Name string `json:"name"` // REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, // to indicate that the host location is relative to the location // where the OpenRPC document is being served. // Server Variables (https://spec.open-rpc.org/#server-variables) // are passed into the Runtime Expression (https://spec.open-rpc.org/#runtime-expression) // to produce a server URL. URL string `json:"url"` // A short summary of what the server is. Summary string `json:"summary,omitempty"` // An optional string describing the host designated by the URL. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A map between a variable name and its value. // The value is passed into the Runtime Expression (https://spec.open-rpc.org/#runtime-expression) // to produce a server URL. Variables map[string]*ServerVariable `json:"variables,omitempty"` }
Server provides connectivity information to a target server.
type ServerVariable ¶
type ServerVariable struct { // An enumeration of string values to be used if the substitution options are from a limited set. Enum []string `json:"enum,omitempty"` // REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value // is not supplied. Note this behavior is different than the Schema Object’s treatment of default values, // because in those cases parameter values are optional. Default string `json:"default"` // An optional description for the server variable. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` }
ServerVariable an object representing a Server Variable for server URL template substitution.
type ServiceDescriptions ¶
ServiceDescriptions map ServiceName -> OpenRPC spec.
type Tag ¶
type Tag struct { // REQUIRED. The name of the tag. Name string `json:"name"` // A short summary of the tag. Summary string `json:"summary,omitempty"` // A verbose explanation for the tag. // GitHub Flavored Markdown syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this tag. ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` }
Tag adds metadata to a single tag that is used by the Method Object. It is not mandatory to have a Tag Object per tag defined in the Method Object instances.