-
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 Contact Object (#3236)
Refs #3097
- Loading branch information
Showing
12 changed files
with
193 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,34 @@ | ||
import { StringElement, ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class Contact extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'contact'; | ||
} | ||
|
||
get name(): StringElement | undefined { | ||
return this.get('name'); | ||
} | ||
|
||
set name(name: StringElement | undefined) { | ||
this.set('name', name); | ||
} | ||
|
||
get url(): StringElement | undefined { | ||
return this.get('url'); | ||
} | ||
|
||
set url(url: StringElement | undefined) { | ||
this.set('url', url); | ||
} | ||
|
||
get email(): StringElement | undefined { | ||
return this.get('email'); | ||
} | ||
|
||
set email(email: StringElement | undefined) { | ||
this.set('email', email); | ||
} | ||
} | ||
|
||
export default Contact; |
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/contact/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 ContactElement from '../../../../elements/Contact'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
|
||
const ContactVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'Contact']), | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init() { | ||
this.element = new ContactElement(); | ||
}, | ||
}); | ||
|
||
export default ContactVisitor; |
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
14 changes: 14 additions & 0 deletions
14
packages/apidom-ns-openapi-2/test/refractor/elements/Contact/__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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ContactElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ContactElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))) | ||
`; |
34 changes: 34 additions & 0 deletions
34
packages/apidom-ns-openapi-2/test/refractor/elements/Contact/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 { assert, expect } from 'chai'; | ||
import { includesClasses, sexprs } from '@swagger-api/apidom-core'; | ||
|
||
import { ContactElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ContactElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const contactElement = ContactElement.refract({ | ||
name: 'API Support', | ||
url: 'https://www.example.com/support', | ||
email: '[email protected]', | ||
}); | ||
|
||
expect(sexprs(contactElement)).toMatchSnapshot(); | ||
}); | ||
|
||
specify('should support specification extensions', function () { | ||
const contactElement = ContactElement.refract({ | ||
name: 'API support', | ||
'x-extension': 'extension', | ||
}) as ContactElement; | ||
|
||
assert.isFalse( | ||
includesClasses(['specification-extension'], contactElement.getMember('name')), | ||
); | ||
assert.isTrue( | ||
includesClasses(['specification-extension'], contactElement.getMember('x-extension')), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |