Class: RivetCms::OpenApiGenerator
- Inherits:
-
Object
- Object
- RivetCms::OpenApiGenerator
- Defined in:
- app/services/rivet_cms/open_api_generator.rb
Overview
Builds an OpenAPI 3 document describing the delivery API for an organization's content types. Field types map to JSON Schema; references/components/media expand into nested schemas.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(organization, base_url: "/api", content_types: nil, components: nil) ⇒ OpenApiGenerator
constructor
content_types/components narrow the document to a permitted subset; nil means all.
Constructor Details
#initialize(organization, base_url: "/api", content_types: nil, components: nil) ⇒ OpenApiGenerator
content_types/components narrow the document to a permitted subset; nil means all. Excluded types must not be referenced either, or the document would carry $refs to schemas it does not contain.
9 10 11 12 13 14 |
# File 'app/services/rivet_cms/open_api_generator.rb', line 9 def initialize(organization, base_url: "/api", content_types: nil, components: nil) @organization = organization @base_url = base_url @content_types = content_types @components = components end |
Instance Method Details
#as_json ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/rivet_cms/open_api_generator.rb', line 16 def as_json(*) content_types = (@content_types || @organization.content_types.order(:name)).to_a { openapi: "3.0.3", info: { title: "RivetCms Delivery API", version: "1.0.0" }, servers: [ { url: @base_url } ], components: { securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } }, schemas: content_types.each_with_object({}) { |ct, acc| acc[schema_name(ct)] = document_schema(ct) } }, security: [ { bearerAuth: [] } ], paths: content_types.each_with_object({}) { |ct, acc| add_paths(acc, ct) } } end |