Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Merge configuration files into one #17

Open
wedi opened this issue Oct 25, 2021 · 3 comments
Open

Suggestion: Merge configuration files into one #17

wedi opened this issue Oct 25, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@wedi
Copy link

wedi commented Oct 25, 2021

It would be nice to have just one configuration file as seen in most tools.

It looks like openapiformatrc[.(yaml|json)] would follow a common pattern.

@thim81
Copy link
Owner

thim81 commented Oct 25, 2021

@wedi Thanks (again) for the valuable feedback.

Which configurations would you like to see merged?

In the CI flow, that we are using, we use it to format and filter 1 OpenAPI and store multiple results in seperate OpenAPI files.

Example:

  • public documentation for production
  • internal preview documentation (which contains upcoming endpoints)
  • an OpenAPI for Newman with a subset for tests.

@wedi
Copy link
Author

wedi commented Oct 25, 2021

That's a pretty neat workflow and I believe my suggestion wouldn't break it. You could keep the existing parameters and document that they overwrite the combined config file. (Although that might make it more complicated than it needs to be.)

Which configurations would you like to see merged?

All of them. 🤓 Similar to this:

{
  "file": "src/openapi.yaml",   // file and string or files and [] if you decide to allow multiple (globs)
  "filter": {
    "methods": [],
    "tags": [],
    "operationIds": [],
    "operations": [],
    "flags": [],
    "flagValues": [],
    "unusedComponents": [],
    "stripFlags": []
  },
  "lineWidth": -1,    // maybe 0 should do the same?
  "sort": {   // set to false for `no-sort`
    "root": ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
    "get": ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
    "post": ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
    "put": ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
    "patch": ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
    "delete": ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
    "parameters": ["name", "in", "description", "required", "schema"],
    "requestBody": ["description", "headers", "content", "links"],
    "responses": ["description", "headers", "content", "links"],
    "content": [],
    "components": ["parameters", "schemas"],
    "schema": ["description", "type", "items", "properties", "format", "example", "default"],
    "schemas": ["description", "type", "items", "properties", "format", "example", "default"],
    "properties": ["description", "type", "items", "format", "example", "default", "enum"]
  },
  "sort-components": [],
  "verbose": false,
}

I have two reasons for this suggestion.

  1. Less clutter in already cluttered root directories
  2. It would allow to replace
    openapi-format --sortFile .openapi-format-sort.json --sortComponentsFile .openapi-format-sort-components.json --filterFile .openapi-format-filter.json src/openapi.yaml -o src/openapi.yaml
    with
    openapi-format src/openapi.yaml -o src/openapi.yaml
    or even openapi-format . per my other suggestion.

Looking at eslint and prettier it seems -c|--config would be a sensible choice for a parameter to use a config file for a certain job and it would allow you to keep --configFile for backwards compatibility if desired (but it would break -c).

I digged into eslint and they use a highly customized config loader whereas prettier uses a library called cosmicconfig. They have lodash in their dependency list, too, so they might use that to merge with default settings.

@thim81 thim81 added the enhancement New feature or request label Nov 18, 2021
@thim81
Copy link
Owner

thim81 commented Nov 18, 2021

@wedi I ll make a PR as soon as I have some time.

I ll make it a separate cli option, so that you can have the choice if you want to split the config or have 1 central file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants