소스 검색

fix(xml): example generation if an array has an example (#6634)

ref: #6627
bubble
Tim Lai 3 년 전
committed by GitHub
부모
커밋
24225e47bf
No known key found for this signature in database GPG 키 ID: 4AEE18F83AFDEB23
3개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. +4
    -0
      src/core/plugins/samples/fn.js
  2. +41
    -0
      test/e2e-cypress/static/documents/bugs/6627.yaml
  3. +11
    -0
      test/e2e-cypress/tests/bugs/6627.js

+ 4
- 0
src/core/plugins/samples/fn.js 파일 보기

@@ -202,6 +202,10 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und
if (schema && props[propName] && props[propName].writeOnly && !includeWriteOnly) {
continue
}
if (schema && props[propName] && props[propName].xml && props[propName].xml.attribute && !(example && example[propName])) {
_attr[props[propName].xml.name || propName] = sample[propName]
continue
}
if (schema && props[propName] && props[propName].xml && props[propName].xml.attribute) {
_attr[props[propName].xml.name || propName] = example[propName]
continue


+ 41
- 0
test/e2e-cypress/static/documents/bugs/6627.yaml 파일 보기

@@ -0,0 +1,41 @@
openapi: 3.0.1
info:
title: XML array schema with array-level example
version: 1.0.0

paths:
/users:
get:
responses:
"200":
description: ''
content:
application/xml:
schema:
$ref: '#/components/schemas/Users'

components:
schemas:
Users:
type: array
example:
- id: 123
name: bob
- id: 456
name: jane
xml:
name: Users
wrapped: true
items:
type: object
xml:
name: User
properties:
id:
type: integer
xml:
attribute: true
name:
type: string
xml:
attribute: true

+ 11
- 0
test/e2e-cypress/tests/bugs/6627.js 파일 보기

@@ -0,0 +1,11 @@
describe("#6627: XML example when defined as array", () => {
it("should render xml like json", () => {
const expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Users>\n\t<User id=\"123\" name=\"bob\">\n\t</User>\n\t<User id=\"456\" name=\"jane\">\n\t</User>\n</Users>"
cy
.visit("/?url=/documents/bugs/6627.yaml")
.get("#operations-default-get_users")
.click()
.get(".microlight")
.contains(expected)
})
})

불러오는 중...
취소
저장