redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Bug: validateMimeTypeOAS3 error - `allowedValues` is not provided for `request-mime-type` rule

Open jeremyfiel opened this issue 4 years ago • 9 comments

Describe the bug when I use lint extends all I'm getting an error for allowedValues is not provided for request-mime-type rule. If I change the config to recommended the linter succeeds.

To Reproduce Steps to reproduce the behavior:

  1. Given this .redocly.yaml file (below)
  2. And this OpenAPI file(s)
  3. Run this command with these arguments... openapi lint ./my-swagger.yaml --format stylish
  4. See error

Expected behavior the linter should produce an error for the missing mime-type and define where it should be included in the spec.

Logs

openapi lint ./my-swagger.yaml --format stylish
validating ./my-swagger.yaml...
Something went wrong when processing ./my-swagger.yaml:

  - Parameter "allowedValues" is not provided for "request-mime-type" rule.

(node:28796) UnhandledPromiseRejectionWarning: Error: Parameter "allowedValues" is not provided for "request-mime-type" rule
    at Object.validateMimeTypeOAS3 (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\utils.js:111:15)
    at leave (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\rules\oas3\request-mime-type.js:10:29)
    at visitWithContext (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:205:13)
    at walkNode (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:177:21)
    at walkNode (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:154:25)
    at walkNode (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:154:25)
    at walkNode (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:154:25)
    at walkNode (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:154:25)
    at Object.walkDocument (C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\walk.js:32:5)
    at C:\Users\fiel\.nvm\versions\node\v14.18.1\bin\node_modules\@redocly\openapi-cli\node_modules\@redocly\openapi-core\lib\lint.js:64:16
(Use `node --trace-warnings ...` to show where the warning was created)
(node:28796) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28796) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

OpenAPI definition If applicable, add an OpenAPI definition and .redocly.yaml configuration file that helps reproduce the problem. At a minimum, please state the specification version(s) you're using (e.g. 2.0, 3.0, 3.1).

openapi: 3.0.0
info:
  version: '1.1'
  title: 'an api'
  description: ' a description.'
  contact:
    name: 'Jeremy'
    email: '[email protected]'
servers:
  - url: 'http://api.redocly.com'
paths:
  /v1/endpoint:
    post:
      summary: 'this is a summary'
      description: 'this is a description'
      operationId: createRecord
      tags:
        - createRecord
      parameters:
        - $ref: '#/components/parameters/customerTransactionId'
        - $ref: '#/components/parameters/clientId'
        - $ref: '#/components/parameters/locale'
        - $ref: '#/components/parameters/establishedId'

      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/component_1'
lint:
  extends:
    - all
  rules:
    info-license: off
    info-license-url: off
    operation-tag-defined: off
    tag-description: off

openapi-cli Version(s) 1.0.0-beta.69

Node.js Version(s) v14.18.1

Additional context relates to #422

jeremyfiel avatar Dec 08 '21 23:12 jeremyfiel

You should not use all ruleset. This is intended for internal use for benchmarks/etc. It may have conflicting rules.

We'll have to fix it in the docs.

RomanHotsiy avatar Dec 09 '21 08:12 RomanHotsiy

cc @skadinna

RomanHotsiy avatar Dec 09 '21 08:12 RomanHotsiy

Also, we may want it to have a default value like application/json? Thoughts?

adamaltman avatar Jan 04 '22 21:01 adamaltman

@adamaltman I agree.

RomanHotsiy avatar Jan 05 '22 06:01 RomanHotsiy

@andriyl can we add a default value of application/json for that request-mime-type rule?

adamaltman avatar Jan 21 '22 03:01 adamaltman

@adamaltman, @RomanHotsiy do you mean a default value of the allowedValue? If yes, I think we can.

tatomyr avatar Apr 05 '22 08:04 tatomyr

I'm getting this issue and based on an earlier comment I changed the config to recommended.

I'm still getting the same error. What is the rule even saying? I've searched the spec and can't even find a mention of a key named allowedValues.

michaelgwelch avatar May 11 '22 20:05 michaelgwelch

@michaelgwelch could you provide your setup so I can recreate this with the recommended ruleset?

tatomyr avatar May 12 '22 07:05 tatomyr

@tatomyr You can hide my comment or mark it as off-topic. After struggling with this for a bit my colleague that set up redocly-cli on our repo showed me that we actually have 4 different config files. 😄 We have 4 different configs we need to run with. I changed one that wasn't being called in our normal build. If I change the correct config file then the problem does disappear as mentioned above.

We are having fun trying to figure out how to upgrade from @redocly/openapi-cli": "^1.0.0-beta.63, but I just discovered that with recommended everything seems to work fine.

michaelgwelch avatar May 12 '22 14:05 michaelgwelch