Class: AnotherApi::OpenAPI::EndpointRegistry
- Inherits:
-
Object
- Object
- AnotherApi::OpenAPI::EndpointRegistry
- Defined in:
- lib/another_api/openapi/endpoint_registry.rb
Overview
Global registry of API endpoint metadata declared by controllers via the EndpointMetadata DSL. The Generator reads this instead of a hardcoded list.
Thread-safe for reads after boot (writes happen at class-load time only).
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
- .all ⇒ Object
- .clear! ⇒ Object
- .register(entry) ⇒ Object
- .resolved_endpoints(configuration: AnotherApi::OpenAPI.configuration) ⇒ Object
-
.schema_short_name(schema, configuration: AnotherApi::OpenAPI.configuration) ⇒ Object
Extract the short class name from a schema class, stripping any configured namespace prefix and collapsing remaining module segments so that sibling namespaces produce distinct schema names.
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/another_api/openapi/endpoint_registry.rb', line 32 def all entries.dup.freeze end |
.clear! ⇒ Object
36 37 38 |
# File 'lib/another_api/openapi/endpoint_registry.rb', line 36 def clear! entries.clear end |
.register(entry) ⇒ Object
28 29 30 |
# File 'lib/another_api/openapi/endpoint_registry.rb', line 28 def register(entry) entries << entry end |
.resolved_endpoints(configuration: AnotherApi::OpenAPI.configuration) ⇒ Object
40 41 42 |
# File 'lib/another_api/openapi/endpoint_registry.rb', line 40 def resolved_endpoints(configuration: AnotherApi::OpenAPI.configuration) all.map { |entry| resolve(entry, configuration) }.compact end |
.schema_short_name(schema, configuration: AnotherApi::OpenAPI.configuration) ⇒ Object
Extract the short class name from a schema class, stripping any configured namespace prefix and collapsing remaining module segments so that sibling namespaces produce distinct schema names.
With prefix “MyApp::Schemas::V1::” set:
MyApp::Schemas::V1::User => "User"
MyApp::Schemas::V1::Seller::Cart => "SellerCart"
MyApp::Schemas::V1::Buyer::Cart => "BuyerCart"
With prefix unset, falls back to demodulize.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/another_api/openapi/endpoint_registry.rb', line 54 def schema_short_name(schema, configuration: AnotherApi::OpenAPI.configuration) klass = schema.is_a?(Class) ? schema : schema.class full_name = klass.name return nil unless full_name prefix = configuration.schema_namespace_prefix if prefix && !prefix.empty? && (suffix = full_name.delete_prefix(prefix)) != full_name suffix.delete("::") else full_name.demodulize end end |