Convert Figma logo to code with AI

interagent logoprmd

JSON Schema tools and doc generation for HTTP APIs

2,096
172
2,096
79

Top Related Projects

A specification for building JSON APIs

A resource-focused Rails library for developing JSON:API compliant servers.

ActiveModel::Serializer implementation and Rails hooks

Quick Overview

The prmd project is a tool for generating documentation from JSON Schema files. It provides a way to create human-readable documentation for APIs and other data structures defined using JSON Schema.

Pros

  • Automated Documentation Generation: prmd allows you to generate documentation automatically from your JSON Schema files, reducing the effort required to maintain up-to-date documentation.
  • Customizable Output: The tool supports various output formats, including Markdown, HTML, and JSON, allowing you to choose the format that best suits your needs.
  • Validation and Linting: prmd includes built-in validation and linting capabilities, helping you ensure the correctness and consistency of your JSON Schema definitions.
  • Extensibility: The project is designed to be extensible, allowing you to create custom templates and plugins to tailor the documentation generation process to your specific requirements.

Cons

  • Limited Functionality: While prmd is a useful tool for generating documentation from JSON Schema, it may not provide all the features and functionality that some users might require, such as advanced formatting options or integration with other documentation tools.
  • Dependency on JSON Schema: The tool is tightly coupled with the JSON Schema format, which means that it may not be suitable for projects that use other data definition formats.
  • Potential Learning Curve: Users who are not familiar with JSON Schema or the prmd tool may need to invest some time in learning how to use it effectively.
  • Maintenance Concerns: As with any open-source project, there are concerns about the long-term maintenance and support of prmd, which could impact its continued usefulness.

Code Examples

Not applicable, as prmd is not a code library.

Getting Started

Not applicable, as prmd is not a code library.

Competitor Comparisons

A specification for building JSON APIs

Pros of JSON API

  • JSON API provides a well-defined and widely-adopted specification for building APIs, which can help with interoperability and consistency.
  • The JSON API specification includes features like resource relationships, sparse fieldsets, and pagination, which can be useful for building complex APIs.
  • JSON API has a large and active community, with many libraries and tools available for working with the specification.

Cons of JSON API

  • The JSON API specification can be more complex and rigid than some other API design approaches, which may not be suitable for all use cases.
  • Implementing the full JSON API specification can require more development effort compared to a more lightweight API design.
  • The JSON API specification may not be as well-suited for certain types of APIs, such as those with a lot of custom or non-standard functionality.

Code Comparison

interagent/prmd

# Define a schema
schema = {
  type: 'object',
  properties: {
    id: { type: 'string' },
    name: { type: 'string' },
    email: { type: 'string', format: 'email' }
  },
  required: ['id', 'name', 'email']
}

# Generate documentation
prmd generate schema.json > docs.md

json-api/json-api

// Define a resource
const resource = {
  type: 'articles',
  id: '1',
  attributes: {
    title: 'JSON API paints my bikeshed!',
    body: 'The shortest article. Ever.'
  },
  relationships: {
    author: {
      data: { type: 'people', id: '9' }
    }
  }
};

// Serialize the resource
const serializedResource = JSON.stringify(resource);

A resource-focused Rails library for developing JSON:API compliant servers.

Pros of jsonapi-resources

  • Provides a comprehensive set of features for building JSON API-compliant APIs, including support for filtering, sorting, and pagination.
  • Integrates well with popular Ruby on Rails framework, making it a good choice for Rails-based projects.
  • Actively maintained with a large and engaged community.

Cons of jsonapi-resources

  • May have a steeper learning curve compared to simpler solutions like interagent/prmd, especially for developers not familiar with the JSON API specification.
  • Potentially more complex and feature-rich than some projects may require, leading to a larger codebase and potential performance overhead.

Code Comparison

interagent/prmd

# Define a schema
schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    email: { type: 'string', format: 'email' }
  },
  required: ['name', 'email']
}

# Generate documentation
Prmd.compile(schema)

jsonapi-resources

# Define a resource
class PersonResource < JSONAPI::Resource
  attributes :name, :email
  has_many :posts
end

# Define a controller
class PeopleController < JSONAPI::ResourceController
  # Implement CRUD actions
end

ActiveModel::Serializer implementation and Rails hooks

Pros of Active Model Serializers

  • Provides a consistent and structured way to serialize model data for API responses
  • Supports a wide range of features, including nested relationships, sparse fieldsets, and custom serialization logic
  • Integrates well with the Rails ecosystem, making it a natural choice for Rails-based APIs

Cons of Active Model Serializers

  • Can be more complex to set up and configure compared to a simpler serialization library
  • May have a steeper learning curve for developers unfamiliar with the Rails ecosystem
  • Can potentially add overhead to the serialization process, depending on the complexity of the models and relationships

Code Comparison

Active Model Serializers:

class PostSerializer < ActiveModel::Serializer
  attributes :id, :title, :content
  has_many :comments
end

PRMD:

{
  name: 'post',
  description: 'A blog post',
  attributes: {
    id: { type: 'integer' },
    title: { type: 'string' },
    content: { type: 'string' }
  },
  relationships: {
    comments: {
      type: 'array',
      items: { type: 'comment' }
    }
  }
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Prmd Travis Status

Gem Version

JSON Schema tooling: scaffold, verify, and generate documentation from JSON Schema documents.

Introduction

JSON Schema provides a great way to describe an API. prmd provides tools for bootstrapping a description like this, verifying its completeness, and generating documentation from the specification.

To learn more about JSON Schema in general, start with this excellent guide and supplement with the specification. The JSON Schema usage conventions expected by prmd specifically are described in /docs/schemata.md.

Installation

Install the command-line tool with:

$ gem install prmd

If you're using prmd within a Ruby project, you may want to add it to the application's Gemfile:

gem 'prmd'
$ bundle install

Usage

Prmd provides four main commands:

  • init: Scaffold resource schemata
  • combine: Combine schemata and metadata into single schema
  • verify: Verify a schema
  • doc: Generate documentation from a schema
  • render: Render views from schema

Here's an example of using these commands in a typical workflow:

# Fill out the resource schemata
$ mkdir -p schemata
$ prmd init app  > schemata/app.json
$ prmd init user > schemata/user.json
$ vim schemata/{app,user}.json   # edit scaffolded files

# Provide top-level metadata
$ cat <<EOF > meta.json
{
 "description": "Hello world prmd API",
 "id": "hello-prmd",
 "links": [{
   "href": "https://api.hello.com",
   "rel": "self"
 }],
 "title": "Hello Prmd"
}
EOF

# Combine into a single schema
$ prmd combine --meta meta.json schemata/ > schema.json

# Check it’s all good
$ prmd verify schema.json

# Build docs
$ prmd doc schema.json > schema.md

Using YAML instead of JSON as a resource and meta format

init and combine supports YAML format:

# Generate resources in YAML format
$ prmd init --yaml app  > schemata/app.yml
$ prmd init --yaml user > schemata/user.yml

# Combine into a single schema
$ prmd combine --meta meta.json schemata/ > schema.json

combine can detect both *.yml and *.json and use them side by side. For example, if one have a lot of legacy JSON resources and wants to create new resources in YAML format - combine will be able to handle it properly.

Render from schema

$ prmd render --template schemata.erb schema.json > schema.md

Typically you'll want to prepend header and overview information to your API documentation. You can do this with the --prepend flag:

$ prmd doc --prepend overview.md schema.json > schema.md

You can also chain commands together as needed, e.g.:

$ prmd combine --meta meta.json schemata/ | prmd verify | prmd doc --prepend overview.md > schema.md

See prmd <command> --help for additional usage details.

Documentation rendering settings

Out of the box you can supply a settings file (in either JSON or YAML) that will tweak the layout of your documentation.

$ prmd doc --settings config.json schema.json > schema.md

Available options (and their defaults)

{
  "doc": {
    "url_style": "default", // can also be "json"
    "disable_title_and_description": false, // remove the title and the description, useful when using your own custom header
    "toc": false // insert the table of content for json scheme documentation to the top of the file. (default disable)
  }
}

Use as rake task

In addition, prmd can be used via rake tasks

# Rakefile
require 'prmd/rake_tasks/combine'
require 'prmd/rake_tasks/verify'
require 'prmd/rake_tasks/doc'

namespace :schema do
  Prmd::RakeTasks::Combine.new do |t|
    t.options[:meta] = 'schema/meta.json'    # use meta.yml if you prefer YAML format
    t.paths << 'schema/schemata/api'
    t.output_file = 'schema/api.json'
  end

  Prmd::RakeTasks::Verify.new do |t|
    t.files << 'schema/api.json'
  end

  Prmd::RakeTasks::Doc.new do |t|
    t.files = { 'schema/api.json' => 'schema/api.md' }
  end
end

task default: ['schema:combine', 'schema:verify', 'schema:doc']

File Layout

We suggest the following file layout for JSON schema related files:

/docs (top-level directory for project documentation)
  /schema (API schema documentation)
    /schemata
      /{resource.[json,yml]} (individual resource schema)
    /meta.[json,yml] (overall API metadata)
    /overview.md (preamble for generated API docs)
    /schema.json (complete generated JSON schema file)
    /schema.md (complete generated API documentation file)

where [json,yml] means that it could be either json or yml.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

NPM DownloadsLast 30 Days