kotas/json_schema_rails

View on GitHub
lib/generators/schema/action/templates/schema.yml.erb

Summary

Maintainability
Test Coverage
---
"$schema": "http://json-schema.org/draft-04/schema#"
title: <%= schema_title %>
type: object
required:
  - <%= file_name %>
properties:
  <%= file_name %>:
    type: object
    additionalProperties: false
  <%- if parameters.empty? -%>
    # required:
    #   - param1
    #   - param2
    # properties:
    #   param1:
    #     type: string
    #   param2:
    #     type: string
  <%- else -%>
    required:
    <%- parameters.each do |param| -%>
      <%- if param.required? -%>
      - <%= param %>
      <%- else -%>
      # - <%= param %>
      <%- end -%>
    <%- end -%>
    properties:
    <%- parameters.each do |param| -%>
      <%= param %>:
        type: <%= param.type %>
    <%- end -%>
  <%- end -%>