Module: A2A::Schema
- Defined in:
- lib/a2a/schema.rb,
lib/a2a/schema/definition.rb,
lib/a2a/schema/validation_error.rb
Overview
Schema-validated A2A protocol objects, powered by json_schemer.
Loads the bundled data/a2a.json schema, rewrites external $ref values to internal #/definitions/… pointers, and dynamically generates Definition subclasses for each type.
A2A::Schema["Agent Capabilities"]
#=> Class < Definition with .schema, .valid?, reader methods
A2A::Schema["Agent Card"]
#=> Class < Definition
A2A::Schema.list_definitions
#=> ["API Key Security Scheme", "Agent Capabilities", ...]
Defined Under Namespace
Classes: Definition, ValidationError
Constant Summary collapse
- DATA_PATH =
File.("../../data/a2a.json", __dir__).freeze
Class Method Summary collapse
-
.[](name) ⇒ Object
Look up a definition by title.
-
.list_definitions ⇒ Object
All available definition titles, sorted.
-
.raw_schema ⇒ Object
The parsed + ref-rewritten JSON schema hash.
-
.reset! ⇒ Object
Reset all cached state (useful for tests).
-
.schemer ⇒ Object
The JSONSchemer instance for the full A2A schema bundle.
Class Method Details
.[](name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/a2a/schema.rb', line 36 def [](name) @definition_classes[name] ||= begin definitions = raw_schema.fetch("definitions", {}) unless definitions.key?(name) raise "No A2A definition found for #{name.inspect}!" \ "\nAvailable: #{list_definitions.join(", ")}" end encoded = URI::DEFAULT_PARSER.escape(name) ref_schema = schemer.ref("#/definitions/#{encoded}") build_definition_class(ref_schema, name, definitions[name]) end end |
.list_definitions ⇒ Object
56 57 58 |
# File 'lib/a2a/schema.rb', line 56 def list_definitions raw_schema.fetch("definitions", {}).keys.sort end |
.raw_schema ⇒ Object
The parsed + ref-rewritten JSON schema hash.
67 68 69 |
# File 'lib/a2a/schema.rb', line 67 def raw_schema @raw_schema ||= load_and_rewrite_schema end |
.reset! ⇒ Object
Reset all cached state (useful for tests).
72 73 74 75 76 77 |
# File 'lib/a2a/schema.rb', line 72 def reset! @definition_classes.clear @schemer = nil @raw_schema = nil @ref_map = nil end |
.schemer ⇒ Object
The JSONSchemer instance for the full A2A schema bundle. Cached after first access.
62 63 64 |
# File 'lib/a2a/schema.rb', line 62 def schemer @schemer ||= JSONSchemer.schema(raw_schema) end |