Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dry-types-json-schema

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dry-types-json-schema

  • 0.0.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Dry::Types::JSONSchema

Example

Dry::Types.load_extensions(:json_schema)

AnnotatedString = Dry::Types["string"].meta(format: :email, title: "Notes")

AnnotatedString.json_schema
#=> {:type=>:string, :title=>"Notes", :format=>:email}

module Types
  include Dry.Types()
end

class StructTest < Dry::Struct
  schema schema.meta(title: "Title", description: "description")

  VariableList = Types::Array
   .of(Types::String | Types::Hash)
   .constrained(min_size: 1)
   .meta(description: "Allow an array of strings or multiple hashes")

  attribute  :data,   Types::String | Types::Hash
  attribute  :string, Types::String.constrained(min_size: 1, max_size: 255)
  attribute  :list,   VariableList
end

StructTest.json_schema
# =>
# {:type=>:object,
#    :properties=>
#     {:data=>{:anyOf=>[{:type=>:string}, {:type=>:object}]},
#      :string=>{:type=>:string, :minLength=>1, :maxLength=>255},
#      :list=>
#       {:type=>:array,
#        :items=>{:anyOf=>[{:type=>:string}, {:type=>:object}]},
#        :description=>"Allow an array of strings or multiple hashes",
#        :minItems=>1}},
#    :required=>[:data, :string, :list],
#    :title=>"Title",
#    :description=>"description"}

FAQs

Package last updated on 08 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc