-
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-workflows-1): Add Reference Object
- Loading branch information
1 parent
8435e5c
commit 13c5d19
Showing
13 changed files
with
196 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,27 @@ | ||
import { StringElement, ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class Reference extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'reference'; | ||
this.classes.push('workflowsSpec-reference'); | ||
} | ||
|
||
get $ref(): StringElement | undefined { | ||
return this.get('$ref'); | ||
} | ||
|
||
set $ref($ref: StringElement | undefined) { | ||
this.set('$ref', $ref); | ||
} | ||
|
||
get value(): StringElement | undefined { | ||
return this.get('value'); | ||
} | ||
|
||
set value(value: StringElement | undefined) { | ||
this.set('value', value); | ||
} | ||
} | ||
|
||
export default Reference; |
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
17 changes: 17 additions & 0 deletions
17
packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/$RefVisitor.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,17 @@ | ||
import stampit from 'stampit'; | ||
import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; | ||
|
||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const $RefVisitor = stampit(FallbackVisitor, { | ||
methods: { | ||
StringElement(stringElement: StringElement) { | ||
this.element = cloneDeep(stringElement); | ||
this.element.classes.push('reference-value'); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default $RefVisitor; |
32 changes: 32 additions & 0 deletions
32
packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/reference/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,32 @@ | ||
import stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
import { ObjectElement, isStringElement } from '@swagger-api/apidom-core'; | ||
|
||
import ReferenceElement from '../../../../elements/Reference'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const ReferenceVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'Reference']), | ||
canSupportSpecificationExtensions: false, | ||
}, | ||
init() { | ||
this.element = new ReferenceElement(); | ||
}, | ||
methods: { | ||
ObjectElement(objectElement: ObjectElement) { | ||
// @ts-ignore | ||
const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); | ||
|
||
// mark this ReferenceElement with reference metadata | ||
if (isStringElement(this.element.$ref)) { | ||
this.element.classes.push('reference-element'); | ||
} | ||
|
||
return result; | ||
}, | ||
}, | ||
}); | ||
|
||
export default ReferenceVisitor; |
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
11 changes: 11 additions & 0 deletions
11
packages/apidom-ns-workflows-1/test/refractor/elements/Reference/__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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ReferenceElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ReferenceElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))) | ||
`; |
19 changes: 19 additions & 0 deletions
19
packages/apidom-ns-workflows-1/test/refractor/elements/Reference/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,19 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from '@swagger-api/apidom-core'; | ||
|
||
import { ReferenceElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ReferenceElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const referenceElement = ReferenceElement.refract({ | ||
$ref: '#/path/to/somewhere', | ||
value: 'override', | ||
}); | ||
|
||
expect(sexprs(referenceElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |