Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
934 stars 146 forks source link

Provide a way to enforce file names #81

Closed rkrauskopf closed 2 years ago

rkrauskopf commented 4 years ago

Currently, you can only create visitors for a node type. We would like to be able specify a visitor for a file.

An example would be if I would like to enforce that all the schemas in a file need to be in alphabetical order.

Currently, to add rules for a specific file I have to specify a random OpenAPISchema type definition in a rule, check that the context.filePath is in the file that I expect, and then apply my validation rules.

RomanHotsiy commented 4 years ago

Oh, that's an interesting idea. We're not sure how to fit into our internal concept.

We will discuss it internally and get back to you soon.

JamesMessinger commented 4 years ago

This would be a killer feature for us. We want to use openapi-cli as a linter that enforces a consistent folder/file structure in all of our APIs, so any developer in the company can easily work on any API in the company without having to learn a new structure each time. Here's the structure that we're enforcing:

|-- openapi.yaml      (the main/entry file)
|-- info.yaml         (the info section)
|-- tags.yaml         (the tags section)
|-- paths/
| |-- foo/
|   |-- bar/
|     |-- path.yaml   (the definition of the /foo/bar path)
|     |-- get.yaml    (the definition of the GET /foo/bar operation)
|     |-- post.yaml   (the definition of the POST /foo/bar operation)
|
|-- schemas/
  |-- enums.yaml      (all enumerations are defined here)
  |-- fizz.yaml       (the JSON schema for fizz objects)
  |-- buzz.yaml       (the JSON schema for buzz objects)

So we need to be able to create file-level rules such as:

adamaltman commented 4 years ago

@JamesMessinger what are you doing in the case of path parameters with your paths folder structure? For example:

JamesMessinger commented 4 years ago

Yes, exactly. Path parameters are just part of the folder structure.

adamaltman commented 4 years ago

This is done (I think). @RomanHotsiy we should add an example of enforcing file names. For example, Rebilly uses PascalCase for component file names with two exceptions: headers (some hybrid of kebab-case and PascalCase == Kebab-Case) and parameters (camelCase). How about a sample rule that enforces a particular case for filenames.

adamaltman commented 2 years ago

@RomanHotsiy this is effectively done with the $ref assertion, right?

RomanHotsiy commented 2 years ago

Not exactly but it can be used for some file-names checks for sure.

adamaltman commented 2 years ago

I'm going to close this since it can be used for $ref filename checks. I'm not sure what other filename would want to be checked besides the root file?