Swagger - Swagger contains a OpenAPI / Swagger universal documentation generator and server handler.

Swagger is low-level library which generate output compatible with Swagger / OpenAPI Spec 3.0.1, and wrapped many friendly APIs let developer understand and use it easier.

builder = Swagger::Builder.new(
  title: "Simple App API Demo",
  version: "1.0.0",
  description: "Simple App API Demo document written by Crystal",
  terms_url: "https://github.com/icyleaf/swagger",
  license: Swagger::License.new("MIT", "https://opensource.org/licenses/MIT"),
  contact: Swagger::Contact.new("icyleaf", "icyleaf.cn@gmail.com", "http://icyleaf.com")
)

builder.add(Swagger::Object.new("User", "object", [
    Swagger::Property.new("id", "integer", "int32", example: 1),
    Swagger::Property.new("nickname", example: "icyleaf wang"),
    Swagger::Property.new("username", example: "icyleaf"),
    Swagger::Property.new("email", example: "icyleaf.cn@gmail.com"),
    Swagger::Property.new("bio", "Personal bio"),
]))

builder.add(Swagger::Controller.new("Users", "User Resources", [
  Swagger::Action.new("get", "/users", "List users", parameters: [
    Swagger::Parameter.new("page", "query", "integer", "Current page", default_value: 1, format: "int32"),
    Swagger::Parameter.new("limit", "query", "integer", "How many items to return at one time (max 100)", default_value: 50, format: "int32"),
  ]),
  Swagger::Action.new("get", "/users/{id}", "Get user by id", parameters: [Swagger::Parameter.new("id", "path")], responses: [
    Swagger::Response.new("200", "Success response"),
    Swagger::Response.new("404", "Not found user")
  ], request: Swagger::Request.new("User")),
  Swagger::Action.new("post", "/users", "Create user",
    request: Swagger::Request.new([
      Swagger::Property.new("username", required: true, description: "The name of user"),
      Swagger::Property.new("email", "string", required: true, description: "Email"),
      Swagger::Property.new("gender", "integer", default_value: 0, description: "Man or Female"),
      Swagger::Property.new("password", required: true, description: "Set your password"),
      Swagger::Property.new("confirm_password", required: true, description: "Confirm password"),
    ], "Form data", "application/x-www-form-urlencoded"),
    responses: [
      Swagger::Response.new("200", "Success response", "User"),
      Swagger::Response.new("404", "Not found user")
    ]
  ),
  Swagger::Action.new("get", "/user/{id}", "Get user by id", parameters: [Swagger::Parameter.new("id", "path")], responses: [
    Swagger::Response.new("200", "Success response"),
    Swagger::Response.new("404", "Not found user")
  ], deprecated: true)
]))

builder.add(Swagger::Server.new("http://swagger.dev:{port}/{version}/api", "Development", [
  Swagger::Server::Variable.new("port", "3000", ["3000"], "API port"),
  Swagger::Server::Variable.new("version", "v2", ["v2", "v3"], description: "API version"),
]))
builder.add(Swagger::Server.new("http://example.com/api", "Production"))

Swagger::HTTP::Server.run(builder.built)

https://github.com/icyleaf/swagger

Poncho - A .env parser/loader improved for performance.

poncho-logo

Poncho is a .env parser/loader improved for performance.

Mostly full support of parsing rules

Poncho parses the contents of your file containing environment variables is available to use. It accepts a String or IO and will return an Hash with the parsed keys and values. Currently supports the following rules:

  • Skipped the empty line and comment(#).
  • Ignore the comment which after (#).
  • NAME=foo becomes {"NAME" => "foo"}.
  • Empty values become empty strings.
  • Whirespace is removed from right ends of the value.
  • Single and Double quoted values are escaped.
  • New lines are expanded if in double quotes.
  • Inner quotes are maintained (such like json).
  • Overwrite optional (default is non-overwrite).
  • Only accpets string type value.

Following twelve-factor app of loading orders

Poncho loads the environment file is easy to use. It accepts both single file (or path) and multiple files. Loads single file supports the following order with environment name (default is development):

  • .env - The OriginalĀ®
  • .env.development - Environment-specific settings.
  • .env.local - Local overrides. This file is loaded for all environments except test.
  • .env.development.local - Local overrides of environment-specific settings.

Read more: https://github.com/icyleaf/poncho

Totem: Crystal configuration with spirit.

totem-logo

https://github.com/icyleaf/totem

What is Totem?

Configuration file formats is always the problem, you want to focus on building awesome things. Totem is here to help with that.

Totem has following features:

Load and parse a configuration file or string in JSON, YAML, dotenv formats. Reading from environment variables. Provide a mechanism to set default values for your different configuration options. Provide an alias system to easily rename parameters without breaking existing code. Write configuration to file with JSON, YAML formats. Uses the following precedence order. Each item takes precedence over the item below it:

  • alias
  • override, explicit call to set
  • env
  • config
  • default

Totem configuration keys are case insensitive.