encoding/openapi

CUE v0.18.0

Package openapi provides OpenAPI encoding and decoding functionality.

This is an EXPERIMENTAL API.

Schemas

#Config

cue
#Config: {
	// version is fixed to 3.0.0 for now.
	version!: "3.0.0"

	info?: #Info

	// selfContained causes all non-expanded external references to be included
	// in this document.
	selfContained: bool | *false

	// expandReferences replaces references with actual objects when generating
	// OpenAPI Schema. It is an error for an CUE value to refer to itself
	// if this option is used.
	expandReferences: bool | *false
}

#Config represents options for generating OpenAPI.

#Contact

cue
#Contact: {
	name?:  string
	url?:   string
	email?: string
}

#Contact represents contact information for the exposed API.

#Info

cue
#Info: {
	title!:          string
	version!:        string
	summary?:        string
	description?:    string
	termsOfService?: string
	contact?:        #Contact
	license?:        #License
}

#Info represents metadata about the API.

#License

cue
#License: {
	name!: string
	url?:  string
}

#License represents license information for the exposed API.

Functions

MarshalSchema

cue
MarshalSchema: func(config: _, schema: _ @schema()) -> string

Marshal returns the OpenAPI encoding of schema for the given OpenAPI version. The optional config value can be used to make further adjustments.

Experimental: this API may change.

schema can have the following fields:

	#Config: {
	  // version holds the OpenAPI version to use when marshaling.
	  // Currently only "3.0.0" is supported.
	  version!: "3.0.0" // currently "3.0.0" only
	  // selfContained causes all non-expanded external references
	  // to be included//
	  selfContained?: bool
	  // expandReferences replaces references with actual objects when generating
	  // OpenAPI Schema. It is an error for an CUE value to refer to itself
	  // if this option is used.
	  expandReferences?: bool
	  // info specifies the info section of the OpenAPI document. To be a valid
	  // OpenAPI document, it must include at least the title and version fields.
	  info?: {
	    title: string
	    description: string
	    version: string
	  }
	}
Install CUE