Class: Eazypi::Components
- Inherits:
-
Object
- Object
- Eazypi::Components
- Defined in:
- lib/eazypi/components.rb
Overview
OpenAPI spec ComponentsObject
Instance Method Summary collapse
- #add_schema(name, schema) ⇒ Object
- #add_security_scheme(name, scheme) ⇒ Object
-
#initialize ⇒ Components
constructor
A new instance of Components.
- #to_openapi_spec ⇒ Object
Constructor Details
#initialize ⇒ Components
Returns a new instance of Components.
6 7 8 9 |
# File 'lib/eazypi/components.rb', line 6 def initialize @schemas = {} @security_schemes = {} end |
Instance Method Details
#add_schema(name, schema) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/eazypi/components.rb', line 15 def add_schema(name, schema) # Make sure it never gets a changed copy + never gets overwritten @schemas[name] = schema.dup unless @schemas.key?(name) "#/components/schemas/#{name}" end |
#add_security_scheme(name, scheme) ⇒ Object
11 12 13 |
# File 'lib/eazypi/components.rb', line 11 def add_security_scheme(name, scheme) @security_schemes[name] = scheme end |
#to_openapi_spec ⇒ Object
22 23 24 25 26 27 |
# File 'lib/eazypi/components.rb', line 22 def to_openapi_spec { "schemas" => @schemas.empty? ? nil : @schemas.transform_values(&:to_openapi_spec), "securitySchemes" => @security_schemes.empty? ? nil : @security_schemes.transform_values(&:to_openapi_spec) }.compact end |