SchemaGenerator
Anchor::TypeScript::SchemaGenerator
Example
class Schema < Anchor::Schema
resource UserResource
resource PostResource
end
content = Anchor::TypeScript::SchemaGenerator.call(
register: Schema.register,
context: {},
include_all_fields: true,
)
path = Rails.root.join("schema.ts")
File.open(path, "w") { |f| f.write(content) }Anchor::TypeScript::SchemaGenerator.call returns a String of the TypeScript schema.
TypeScript type expressions for Anchor types can be found in Anchor::Types. Type expressions are generated by
Anchor::TypeScript::Serializer.
See Quick Start for a full example.
.call Parameters
register
- Type:
Anchor::Schema::Register - Required
context
- Type:
Any - Default:
{}
context passed to Resource.anchor_fetchable_fields.
include_all_fields
- Type:
Boolean - Default:
nil
Use JSONAPI::Resource.fields irrespective of Resource.anchor_fetchable_fields.