fix(schema example): xml gen should follow json gen behavior (#6555)

* ref: #6470 
* fixes: #6540
* fixes: #4943 

* add example override option to json
* add example override option to xml
* added basic oneOf and anyOf support
* fix anyof|oneof
* only lift xml to items


Co-authored-by: Tim Lai <timothy.lai@gmail.com>
This commit is contained in:
Mahtis Michel
2020-11-03 19:58:59 +01:00
committed by GitHub
parent 64ae7af565
commit 288c89bdbb
8 changed files with 488 additions and 228 deletions

View File

@@ -0,0 +1,43 @@
openapi: 3.0.0
info:
description: Test API
version: v1
title: Test API
tags:
- name: Test
description: Test API
servers:
- url: /v1
paths:
/test:
post:
tags:
- Test
summary: Test endpoint
description: Test
operationId: postTest
responses:
'200':
description: Returns response
content:
application/xml:
schema:
$ref: '#/components/schemas/test'
components:
schemas:
test:
type: object
properties:
a:
type: string
b:
type: integer
c:
oneOf:
- type: object
- type: array
items:
type: string
- type: boolean
- type: integer
- type: number

View File

@@ -0,0 +1,85 @@
openapi: 3.0.0
info:
description: Test API
version: v1
title: Test API
tags:
- name: Test
description: Test API
servers:
- url: /v1
paths:
/test:
post:
tags:
- Test
summary: Test endpoint
description: Test
operationId: postTest
responses:
'200':
description: Returns response
content:
application/xml:
schema:
$ref: '#/components/schemas/test'
components:
schemas:
test:
type: object
properties:
a:
type: string
b:
type: integer
c:
type: array
items:
$ref: '#/components/schemas/Things'
d:
type: array
items:
anyOf:
- $ref: '#/components/schemas/TextObject'
- $ref: '#/components/schemas/ImageObject'
Things:
type: object
oneOf:
- $ref: '#/components/schemas/TextObject'
- $ref: '#/components/schemas/ImageObject'
TextObject:
required:
- data
type: object
properties:
objectType:
type: string
example: Text
xml:
name: ObjectType
data:
type: string
example: This is a text
xml:
name: Data
description: Contains a text
ImageObject:
required:
- data
type: object
properties:
objectType:
type: string
example: image
xml:
name: ObjectType
data:
type: string
example: This is a image
xml:
name: Data
description: Contains a image

View File

@@ -0,0 +1,20 @@
describe("#4943: XML example not rendered correctly with oneOf", () => {
it("should render integer property correctly", () => {
cy
.visit("/?url=/documents/bugs/4943.yaml")
.get("#operations-Test-postTest")
.click()
.get(".microlight")
.contains("<b>0</b>")
})
it("should render oneOf property correctly", () => {
cy
.visit("/?url=/documents/bugs/4943.yaml")
.get("#operations-Test-postTest")
.click()
.get(".try-out__btn")
.click()
.get(".microlight")
.contains("<c>\n\t</c>")
})
})

View File

@@ -0,0 +1,11 @@
describe("#6540: XML example not rendered correctly with oneOf", () => {
it("should render xml like json", () => {
const expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test>\n\t<a>string</a>\n\t<b>0</b>\n\t<c>\n\t\t<ObjectType>Text</ObjectType>\n\t\t<Data>This is a text</Data>\n\t</c>\n\t<c>\n\t\t<ObjectType>image</ObjectType>\n\t\t<Data>This is a image</Data>\n\t</c>\n\t<d>\n\t\t<ObjectType>Text</ObjectType>\n\t\t<Data>This is a text</Data>\n\t</d>\n\t<d>\n\t\t<ObjectType>image</ObjectType>\n\t\t<Data>This is a image</Data>\n\t</d>\n</test>"
cy
.visit("/?url=/documents/bugs/6540.yaml")
.get("#operations-Test-postTest")
.click()
.get(".microlight")
.contains(expected)
})
})