-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ns-openapi-2): add support for XML Object (#3234)
Refs #3097
- Loading branch information
Showing
12 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
StringElement, | ||
ObjectElement, | ||
BooleanElement, | ||
Attributes, | ||
Meta, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
class Xml extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'xml'; | ||
} | ||
|
||
get name(): StringElement | undefined { | ||
return this.get('name'); | ||
} | ||
|
||
set name(name: StringElement | undefined) { | ||
this.set('name', name); | ||
} | ||
|
||
get namespace(): StringElement | undefined { | ||
return this.get('namespace'); | ||
} | ||
|
||
set namespace(namespace: StringElement | undefined) { | ||
this.set('namespace', namespace); | ||
} | ||
|
||
get prefix(): StringElement | undefined { | ||
return this.get('prefix'); | ||
} | ||
|
||
set prefix(prefix: StringElement | undefined) { | ||
this.set('prefix', prefix); | ||
} | ||
|
||
get attribute(): BooleanElement | undefined { | ||
return this.get('attribute'); | ||
} | ||
|
||
set attribute(attribute: BooleanElement | undefined) { | ||
this.set('attribute', attribute); | ||
} | ||
|
||
get wrapped(): BooleanElement | undefined { | ||
return this.get('wrapped'); | ||
} | ||
|
||
set wrapped(wrapped: BooleanElement | undefined) { | ||
this.set('wrapped', wrapped); | ||
} | ||
} | ||
|
||
export default Xml; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/xml/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
|
||
import XmlElement from '../../../../elements/Xml'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
|
||
const XmlVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'XML']), | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init() { | ||
this.element = new XmlElement(); | ||
}, | ||
}); | ||
|
||
export default XmlVisitor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/apidom-ns-openapi-2/test/refractor/elements/Xml/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements XmlElement should refract to semantic ApiDOM tree 1`] = ` | ||
(XmlElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(BooleanElement)) | ||
(MemberElement | ||
(StringElement) | ||
(BooleanElement))) | ||
`; |
34 changes: 34 additions & 0 deletions
34
packages/apidom-ns-openapi-2/test/refractor/elements/Xml/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect, assert } from 'chai'; | ||
import { sexprs, includesClasses } from '@swagger-api/apidom-core'; | ||
|
||
import { XmlElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('XmlElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const xmlElement = XmlElement.refract({ | ||
name: 'animal', | ||
namespace: 'http://swagger.io/schema/sample', | ||
prefix: 'sample', | ||
attribute: true, | ||
wrapped: false, | ||
}); | ||
|
||
expect(sexprs(xmlElement)).toMatchSnapshot(); | ||
}); | ||
|
||
specify('should support specification extensions', function () { | ||
const xmlElement = XmlElement.refract({ | ||
name: 'animal', | ||
'x-extension': 'extension', | ||
}) as XmlElement; | ||
|
||
assert.isFalse(includesClasses(['specification-extension'], xmlElement.getMember('name'))); | ||
assert.isTrue( | ||
includesClasses(['specification-extension'], xmlElement.getMember('x-extension')), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |