feat: group / sort parameters by location (#6745)

This commit is contained in:
Mahtis Michel
2021-01-14 20:39:01 +01:00
committed by GitHub
parent a2f7917661
commit ddaee4ec42
3 changed files with 164 additions and 61 deletions

View File

@@ -0,0 +1,63 @@
openapi: 3.0.1
info:
title: Example Swagger
version: '1.0'
servers:
- url: /api/v1
paths:
/test/{id}/related/{relatedId}:
post:
parameters:
- in: path
name: relatedId
required: true
schema:
type: integer
default: 1
description: The related ID
- in: header
name: TRACE-ID
required: true
schema:
type: integer
default: 1
description: The trace ID
- in: cookie
name: debug
required: true
schema:
type: number
enum:
- 0
- 1
description: debug flag
- in: header
name: USER-ID
required: true
schema:
type: integer
default: 1
description: The user ID
- in: query
name: asc
required: true
schema:
type: boolean
default: true
description: sort asc
- in: path
name: id
required: true
schema:
type: integer
default: 1
description: The ID
requestBody:
description: Some
content:
application/json:
schema:
type: string
responses:
200:
description: Some

View File

@@ -0,0 +1,30 @@
describe("Parameter order", () => {
it("should be well ordered", () => {
cy.visit("/?url=/documents/features/parameter-order.yaml")
.get("#operations-default-post_test__id__related__relatedId_")
.click()
.get(".parameters > tbody")
.children()
.each((tr, i, arr) => {
const parameterTableRows = Array.from(arr)
expect(tr).to.have.attr("data-param-in")
if (i === 0) {
return
}
const inValue = tr[0].getAttribute("data-param-in")
if (!inValue) {
return
}
const beforeInValue = parameterTableRows[i - 1].getAttribute("data-param-in")
const sameAsBefore = beforeInValue === inValue
if (sameAsBefore) {
expect(parameterTableRows[i - 1]).to.have.attr("data-param-in", inValue)
return
}
for (let x = i + 1; x < parameterTableRows.length; x++) {
expect(parameterTableRows[x]).to.not.have.attr("data-param-in", beforeInValue)
}
})
})
})