Module: Keiyaku::Serialize

Defined in:
lib/keiyaku/runtime.rb,
sig/keiyaku.rbs

Overview

Serialize parameters per the OpenAPI style/explode rules. Implemented are the defaults — form for query, simple for path and header — and the one rendering deepObject has. The generator refuses anything else rather than guessing, so a name reaching deep: here has already been checked.

Constant Summary collapse

ESCAPED =

What a path parameter has to be encoded down to: RFC 3986's unreserved characters are what simple expansion may leave as they are, and this matches everything else.

/[^A-Za-z0-9\-._~]/

Class Method Summary collapse

Class Method Details

.deep_object(name, value) ⇒ Object

filter=live&filter=2026-07-27, which is the whole of what deepObject means. The specification stops at one level — it says nothing about what a key's own value may be — so a value that is itself an object or an array is refused rather than sent as whatever #to_s makes of it, which no server could read back.

Raises:



433
# File 'lib/keiyaku/runtime.rb', line 433

def self.deep_object: (String name, untyped value) -> Array[[String, String]]

.multipart(fields, boundary) ⇒ Object

Build a multipart/form-data body. An array property becomes one part per element, which is what the default form encoding means for an array.



498
# File 'lib/keiyaku/runtime.rb', line 498

def self.multipart: (Hash[String, untyped], String boundary) -> String

.part(name, value, boundary) ⇒ String

Parameters:

  • name (String)
  • value (Object)
  • boundary (String)

Returns:

  • (String)


141
# File 'sig/keiyaku.rbs', line 141

def self.part: (String name, untyped value, String boundary) -> String

.path(name, value, explode: false) ⇒ String

Parameters:

  • name (String)
  • value (Object)
  • explode: (Boolean) (defaults to: false)

Returns:

  • (String)


136
# File 'sig/keiyaku.rbs', line 136

def self.path: (String name, untyped value, ?explode: bool) -> String

.query(params, deep: []) ⇒ Array[[String, String]]

Parameters:

  • (Hash[String, untyped])
  • deep: (Array[String]) (defaults to: [])

Returns:

  • (Array[[String, String]])


134
# File 'sig/keiyaku.rbs', line 134

def self.query: (Hash[String, untyped], ?deep: Array[String]) -> Array[[String, String]]

.simple(name, value, explode: false, escape: false) ⇒ Object

OpenAPI's simple style, which is what a path or a header parameter is written in unless the document said otherwise: an array is its elements separated by commas, and an object is its keys and values in that same flat list — or key=value pairs where explode said so, which is the one part of this a value cannot be asked and the operation has to carry.

What it exists to keep off the wire is Ruby's own #to_s: [1, 2] on a header reaches a server as a string with brackets and a space in it, and nothing on the other side reads that back as two values.



464
# File 'lib/keiyaku/runtime.rb', line 464

def self.simple: (String name, untyped value, ?explode: bool, ?escape: bool) -> String

.simple_part(name, value, escape: false) ⇒ Object

One value inside a simple parameter. The style's row in the specification stops where deepObject's does: it gives no spelling for an array or an object inside one, so that is refused rather than sent as whatever #to_s makes of it.

In a path it is percent-encoded and the separators around it are not, which is RFC 6570's simple expansion and the only way the two are told apart: a segment is allowed to hold a comma, so the comma between two elements is left as one and a comma inside an element becomes %2C. The encoding is down to the unreserved characters — a space is %20 and not the + that means a space only in a query — and it is by byte, so a name outside ASCII survives the trip. A header is not a URL and is not encoded at all.



487
# File 'lib/keiyaku/runtime.rb', line 487

def self.simple_part: (String name, untyped value, ?escape: bool) -> String

.stringify(value) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


139
# File 'sig/keiyaku.rbs', line 139

def self.stringify: (untyped) -> String