Module: JekyllOpenAPI::Filters
- Defined in:
- lib/jekyll_openapi/filters.rb
Overview
Liquid filters over the JekyllOpenAPI model and renderers.
This module has no dependency on the liquid gem itself: it is a plain module of filter methods. Consumers opt in with:
Liquid::Template.register_filter(JekyllOpenAPI::Filters)
or register only a subset by wrapping the methods they want.
Instance Method Summary collapse
-
#oapi_dereference(input) ⇒ Object
Replace every local $ref with a lazy, name-preserving Reference.
-
#oapi_examples(input) ⇒ Object
Normalized example list for a parameter or media-type object, unifying
examples(named Example Objects),example(single value) and the schema-level equivalents. -
#oapi_headers(response) ⇒ Object
Normalized header list for a response object: each entry is description, required, deprecated, schema.
-
#oapi_html_schema(input) ⇒ Object
Render a JSON-Schema as semantic HTML, linking named component schemas to their #schema-
anchor instead of inlining them. -
#oapi_is_xml(content_type) ⇒ Object
True for XML-family media types (application/xml, text/xml, *+xml).
-
#oapi_merge_parameters(path_params, operation_params) ⇒ Object
Merge path-level and operation-level parameter lists (operation wins).
-
#oapi_operation_anchor(op) ⇒ Object
Stable fragment id for an operation (entry from
oapi_operations, or a bare operationId). -
#oapi_operations(input, tag = nil) ⇒ Object
Flat operation list from a full document, optionally filtered by tag.
-
#oapi_parameters(input) ⇒ Object
Group a parameter list by location: => [...], "path" => [...], ....
-
#oapi_representation(content_type) ⇒ Object
Classify a media-type string: "xml" | "json" | "text" | "binary".
-
#oapi_schema(input) ⇒ Object
Render a JSON-Schema as a TypeScript-like string.
-
#oapi_schema_anchor(name) ⇒ Object
Anchor id for a named schema, e.g.
-
#oapi_schemas(input) ⇒ Object
Named schema map of a full document (for a "Models" reference section).
-
#oapi_security_schemes(input) ⇒ Object
Named security scheme map of a full document.
-
#oapi_servers(input) ⇒ Object
Declared servers of a full document.
-
#oapi_tag_anchor(tag) ⇒ Object
Stable fragment id for a tag (tag object from
oapi_tags, or a bare name). -
#oapi_tags(input) ⇒ Object
Tag list of a full document.
-
#oapi_xml_schema(input) ⇒ Object
Render a JSON-Schema as a simplified XML example.
Instance Method Details
#oapi_dereference(input) ⇒ Object
Replace every local $ref with a lazy, name-preserving Reference. Reads walk through transparently; recursion and reuse are handled (see Reference).
14 15 16 |
# File 'lib/jekyll_openapi/filters.rb', line 14 def oapi_dereference(input) Dereferencer.new(input).dereference end |
#oapi_examples(input) ⇒ Object
Normalized example list for a parameter or media-type object, unifying
examples (named Example Objects), example (single value) and the
schema-level equivalents. Each entry is value, summary, description.
31 32 33 |
# File 'lib/jekyll_openapi/filters.rb', line 31 def oapi_examples(input) Examples.normalize(input) end |
#oapi_headers(response) ⇒ Object
Normalized header list for a response object: each entry is
description, required, deprecated, schema. $ref'd headers resolve.
109 110 111 |
# File 'lib/jekyll_openapi/filters.rb', line 109 def oapi_headers(response) Headers.list(response) end |
#oapi_html_schema(input) ⇒ Object
Render a JSON-Schema as semantic HTML, linking named component schemas to
their #schema-
75 76 77 |
# File 'lib/jekyll_openapi/filters.rb', line 75 def oapi_html_schema(input) SchemaRenderer::HTML.render(input, markdown: markdown_formatter) end |
#oapi_is_xml(content_type) ⇒ Object
True for XML-family media types (application/xml, text/xml, *+xml).
103 104 105 |
# File 'lib/jekyll_openapi/filters.rb', line 103 def oapi_is_xml(content_type) ContentType.xml?(content_type) end |
#oapi_merge_parameters(path_params, operation_params) ⇒ Object
Merge path-level and operation-level parameter lists (operation wins)
24 25 26 |
# File 'lib/jekyll_openapi/filters.rb', line 24 def oapi_merge_parameters(path_params, operation_params) Parameters.merge(path_params, operation_params) end |
#oapi_operation_anchor(op) ⇒ Object
Stable fragment id for an operation (entry from oapi_operations, or a
bare operationId). Falls back to method+path when operationId is absent.
87 88 89 |
# File 'lib/jekyll_openapi/filters.rb', line 87 def oapi_operation_anchor(op) Anchors.operation(op) end |
#oapi_operations(input, tag = nil) ⇒ Object
Flat operation list from a full document, optionally filtered by tag. See Document#operations for the shape of each entry.
37 38 39 |
# File 'lib/jekyll_openapi/filters.rb', line 37 def oapi_operations(input, tag = nil) document(input).operations(tag: tag) end |
#oapi_parameters(input) ⇒ Object
Group a parameter list by location: => [...], "path" => [...], ...
19 20 21 |
# File 'lib/jekyll_openapi/filters.rb', line 19 def oapi_parameters(input) Parameters.group(input) end |
#oapi_representation(content_type) ⇒ Object
Classify a media-type string: "xml" | "json" | "text" | "binary".
Robust to text/xml, application/*+xml, and ; charset=… suffixes.
98 99 100 |
# File 'lib/jekyll_openapi/filters.rb', line 98 def oapi_representation(content_type) ContentType.representation(content_type) end |
#oapi_schema(input) ⇒ Object
Render a JSON-Schema as a TypeScript-like string
62 63 64 |
# File 'lib/jekyll_openapi/filters.rb', line 62 def oapi_schema(input) SchemaRenderer::TypeScript.render(input) end |
#oapi_schema_anchor(name) ⇒ Object
Anchor id for a named schema, e.g. "Pet" => "schema-Pet". Use it for the
matching id on a Models section so the renderer's links resolve.
81 82 83 |
# File 'lib/jekyll_openapi/filters.rb', line 81 def oapi_schema_anchor(name) SchemaRenderer::HTML.anchor(name) end |
#oapi_schemas(input) ⇒ Object
Named schema map of a full document (for a "Models" reference section)
47 48 49 |
# File 'lib/jekyll_openapi/filters.rb', line 47 def oapi_schemas(input) document(input).schemas end |
#oapi_security_schemes(input) ⇒ Object
Named security scheme map of a full document
52 53 54 |
# File 'lib/jekyll_openapi/filters.rb', line 52 def oapi_security_schemes(input) document(input).security_schemes end |
#oapi_servers(input) ⇒ Object
Declared servers of a full document
57 58 59 |
# File 'lib/jekyll_openapi/filters.rb', line 57 def oapi_servers(input) document(input).servers end |
#oapi_tag_anchor(tag) ⇒ Object
Stable fragment id for a tag (tag object from oapi_tags, or a bare name).
92 93 94 |
# File 'lib/jekyll_openapi/filters.rb', line 92 def oapi_tag_anchor(tag) Anchors.tag(tag) end |
#oapi_tags(input) ⇒ Object
Tag list of a full document
42 43 44 |
# File 'lib/jekyll_openapi/filters.rb', line 42 def (input) document(input). end |
#oapi_xml_schema(input) ⇒ Object
Render a JSON-Schema as a simplified XML example
67 68 69 |
# File 'lib/jekyll_openapi/filters.rb', line 67 def oapi_xml_schema(input) SchemaRenderer::XML.render(input) end |