Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dx 3119 #18

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions DX-3119.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Adding XML Example Support to ReDoc

1. Create a new XML Object in `./src/services/models` with the following properties
1. Name: string
2. Attribute: boolean
3. prefix: string
4. namespace: string
5. wrapped: true
* This is for wrapped arrays
2. Modify `./src/services/models/Field.ts` to include the above newly created field as an optional property
3. Modify `./src/utils/openapi.ts` to add a function checking whether or not a content type is XML
```js line 167
export function isXmlLike(contentType: string): boolean {
return contentType.search(/xml/i) !== -1;
}
// OR
export function contentTypeIsXml(contentType: string): boolean {
return contentType === 'application/xml';
}
```
4. Update `./src/services/models/MediaType.ts` to:
* Import the function created in step 3 to line 7
```js
import { isJsonLike, contentTypeIsXml, mapValues } from '../../utils';
```
* Create a new `generateXmlExample` function to generate the XML example from the OpenAPI Schema
* https://github.com/oozcitak/xmlbuilder2
* Add logic to the if/else to generate examples for XML Schemas
```js Line 51
} else if (contentTypeIsXml(name)) {
this.generateXmlExample(parser, info);
}
```
* A dependancy they are using, `openapi-sampler` to generate examples, does not and will not support XML samples
* https://github.com/Redocly/openapi-sampler/issues/121
5. Update `./src/services/OpenApiParser.ts` `deref()` function to work for xml schemas?
6. Update the return statement in `./src/services/models/Example.ts` to generate XML examples?
```js Line 53
} else if (isXmlLike(mimeType)) {
try {
return JSON.parse(txt); // this needs to parse `txt` to XML
} catch (e) {
return txt;
}
}
```
Loading