stoplightio / spectral-documentation

Teach Spectral how to help improve the quality of your OpenAPI-based documentation.
8 stars 4 forks source link

Unexpected error with docs-description #5

Closed philsturgeon closed 1 year ago

philsturgeon commented 1 year ago

Unexpected error coming out of docs-description for parameter arrays.

Context

In a pull request (https://github.com/stoplightio/spectral-documentation/pull/4) I'm bringing over parameter description tests from the core oas ruleset, and they're failing in my ruleset. Tried a bunch of things but I think something special is happening that might need the insight the core team.

Current Behavior

This test for docs-description should be valid:


  {
    name: "valid operation level parameters",
    document: {
      swagger: "2.0",
      paths: {
        "/todos": {
          get: {
            parameters: [
              {
                name: "limit",
                in: "query",
                description: "This is how it works.",
                type: "integer",
              },
            ],
          },
        },
      },
    },
    errors: [],
  },

The unexpected error is:

 FAIL  __tests__/docs-description.test.ts
  ● Rule docs-description › valid operation level parameters

    expect(received).toEqual(expected) // deep equality

    - Expected  -  1
    + Received  + 22

    - Array []
    + Array [
    +   Object {
    +     "code": "docs-description",
    +     "message": "\"get.description\" property must be truthy.",
    +     "path": Array [
    +       "paths",
    +       "/todos",
    +       "get",
    +     ],
    +     "range": Object {
    +       "end": Object {
    +         "character": 140,
    +         "line": 0,
    +       },
    +       "start": Object {
    +         "character": 42,
    +         "line": 0,
    +       },
    +     },
    +     "severity": 1,
    +   },
    + ]

What is a get.description? It's meant to be get.parameters[0].decription its looking at.

The JSONPath in the ruleset shows the object is being found properly:

image

So I can only assume something funny is happening in nimma or elsewhere in Spectral?

Expected Behavior

I expect the above test to pass.

Grab the parameter-descriptions branch (#4) and run npm test.

P0lip commented 1 year ago

I think it's because you also list OperationObject in the DescribableObjects alias, and in the example input above you do have a get operation, that does not have any description, so you'd need to add one or remove OperationObject from the alias you use.


  {
    name: "valid operation level parameters",
    document: {
      swagger: "2.0",
      paths: {
        "/todos": {
          get: {
            description: 'should be present here too since we look for it',
            parameters: [
              {
                name: "limit",
                in: "query",
                description: "This is how it works.",
                type: "integer",
              },
            ],
          },
        },
      },
    },
    errors: [],
  },
philsturgeon commented 1 year ago

Thank you! Proper silly of me to not notice that, but its one of the first rules that does that many things. Passing now!