Code Monkey home page Code Monkey logo

redocly-cli-cookbook's Introduction

Redocly CLI Cookbook

A community collection of rulesets, configuration, custom plugins and other additions for Redocly CLI. We know our users have some great tips, examples, and code to share, and this is the place to do just that. We would love to have your contributions here too!

Important

Redocly are the repository maintainers, but we can't thoroughly test everything here. Please browse, share, and use what you find at your own risk.

If you're new to Redocly CLI, start with the documentation to get up and running, then come back here to pick out any elements you would like to re-use yourself. To keep up with new developments, either subscribe to the project repository, or sign up for the Redocly product newsletter.

Usage

Use the content here as a starting point for your own work.

  1. Take a look at what's available in each category, and pick any that you think apply to your situation.

  2. Each section links to the documentation for that feature, incase you need an introduction or refresher.

  3. Copy and paste the examples you want to use into your own setup, then edit them to fit your own needs.

If you come up with something new, please consider sharing it here by opening a pull request.

Categories

Rulesets

Combine existing built-in rules in ways that serve a specific purpose, and make a resuable ruleset.

Configurable rules

There are some fantastic examples of configurable rules in the wild, we hope the list here inspires you to share more of your own!

Custom plugins

The custom plugin is the ultimate in extensibility, but it's an advanced feature. Try these plugins for inspiration and to get you started. Rather than including the whole plugin, there are also sections for individual rules and decorators further down.

Decorators (for custom plugins)

Rules (for custom plugins)

Miscellaneous (including tips and tricks)

Share anything that didn't fit the existing categories here.

Contributing

Please share your best Redocly CLI usage with us! Each item should be shared in its own pull request, following the existing directory structure and including the README template copied into each folder. Full instructions are in the CONTRIBUTING file.

Requests

If there's something you think should be in the collection and it isn't, let us know! Open an issue, and describe the problem you'd like to see solved with Redocly CLI. We can't make promises, but we are pretty sure someone out there will know the answer.

redocly-cli-cookbook's People

Contributors

adamaltman avatar cidtori avatar dannyvdsluijs avatar jeremyfiel avatar lornajane avatar nicobao avatar tatomyr avatar taylorkrusen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redocly-cli-cookbook's Issues

Add link checking

Check links in the markdown files, especially the README, are valid and working. Add the check to the CI to run on every pull request, and add instructions to CONTRIBUTING on running it locally.

rule/require-array-items: false positive

Adding a type to the bar property makes the error go away, but I'm not clear on how the where is matching that schema in the first place.

swagger.json:

{
	"swagger": "2.0",
	"definitions": {
		"Foo": {
			"type": "object",
			"properties": {
				"bar": {}
			}
		}
	}
}

redocly.yml

https://github.com/Redocly/redocly-cli-cookbook/tree/main/configurable-rules/required-items-for-array-schemas

apis:
  main:
    root: swagger.json

rules:
  rule/require-array-items:
    subject:
      type: Schema
    assertions:
      required:
        - items
    where:
      - subject:
          type: Schema
          property: type
        assertions:
          const: array
    message: The 'items' field is required for schemas of array type.

Error:

$ npx redocly lint swagger.json
validating swagger.json...
[1] swagger.json:7:5 at #/definitions/Foo/properties/bar

The 'items' field is required for schemas of array type.

5 | 			"type": "object",
6 | 			"properties": {
7 | 				"bar": {}
8 | 			}
9 | 		}

Error was generated by the rule/require-array-items rule.


swagger.json: validated in 6ms

โŒ Validation failed with 1 error.
run `redocly lint --generate-ignore-file` to add all problems to the ignore file.

Custom rules -- can a built-in rule be overridden to relax enforcement of certain specific conditions?

Hello.

I'm using Redocly for validation of a Swagger JSON file that references (via $ref) a JSON Schema file.

The top-level object in my JSON Schema file contains these two properties:

"$schema": "http://json-schema.org/draft-04/schema",
"id": "api-response.json",

The Redocly spec rule doesn't like these two properties ... I'd like to be able to ignore those specific top-level properties without totally disabling the spec rule.

Is there a way to configure a built-in rule to allow it to continue to enforce its rules, but with certain exceptions?

Thank you.

Add option to make alphabetical sort decorator case-sensitive

PR #5 added an example of a decorator for alphabetical sorting. Someone highlighted the importance of case-sensitivity.

Here's a paraphrased example of sorting challenges caused by casing:

Pretend you're looking for the term "API Keys" on an alphabetically sorted list. Which order would you expect?

Case sensitive Not case-sensitive
AML
API keys
Accounts
Allowlists
Application owners
Application users
Coupons
Accounts
Allowlists
AML
API keys
Application owners
Application users
Coupons

The redocly-cli solved for this using an ignoreCase flag. A similar solution might work well here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.