Skip to content

Commit 4f671a8

Browse files
fix: update models with latest parser-api (#723)
1 parent e3f0289 commit 4f671a8

11 files changed

+14601
-201
lines changed

package-lock.json

Lines changed: 14444 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/models/correlation-id.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ import type { BaseModel } from './base';
22
import type { DescriptionMixinInterface, ExtensionsMixinInterface } from './mixins';
33

44
export interface CorrelationIdInterface extends BaseModel, DescriptionMixinInterface, ExtensionsMixinInterface {
5-
hasLocation(): boolean;
65
location(): string | undefined;
76
}

src/models/oauth-flow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { BaseModel } from './base';
22
import { ExtensionsMixinInterface } from './mixins';
33

44
export interface OAuthFlowInterface<J extends Record<string, any> = Record<string, any>> extends BaseModel<J>, ExtensionsMixinInterface {
5+
hasAuthorizationUrl(): boolean;
56
authorizationUrl(): string | undefined;
7+
hasTokenUrl(): boolean;
8+
tokenUrl(): string | undefined;
69
hasRefreshUrl(): boolean;
710
refreshUrl(): string | undefined;
811
scopes(): Record<string, string> | undefined;
9-
tokenUrl(): string | undefined;
1012
}

src/models/v2/components.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export class Components extends BaseModel<v2.ComponentsObject> implements Compon
5959
);
6060
}
6161

62+
operations(): OperationsInterface {
63+
return new Operations([]);
64+
}
65+
6266
messages(): MessagesInterface {
6367
return this.createCollection('messages', Messages, Message);
6468
}
@@ -75,10 +79,6 @@ export class Components extends BaseModel<v2.ComponentsObject> implements Compon
7579
return this.createCollection('serverVariables', ServerVariables, ServerVariable);
7680
}
7781

78-
operations(): OperationsInterface {
79-
return new Operations([]);
80-
}
81-
8282
operationTraits(): OperationTraitsInterface {
8383
return this.createCollection('operationTraits', OperationTraits, OperationTrait);
8484
}

src/models/v2/correlation-id.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import type { ExtensionsInterface } from '../extensions';
88
import type { v2 } from '../../spec-types';
99

1010
export class CorrelationId extends BaseModel<v2.CorrelationIDObject> implements CorrelationIdInterface {
11+
location(): string {
12+
return this._json.location;
13+
}
14+
1115
hasDescription(): boolean {
1216
return hasDescription(this);
1317
}
@@ -16,14 +20,6 @@ export class CorrelationId extends BaseModel<v2.CorrelationIDObject> implements
1620
return description(this);
1721
}
1822

19-
hasLocation(): boolean {
20-
return !!this._json.location;
21-
}
22-
23-
location(): string | undefined {
24-
return this._json.location;
25-
}
26-
2723
extensions(): ExtensionsInterface {
2824
return extensions(this);
2925
}

src/models/v2/oauth-flow.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ import type { OAuthFlowInterface } from '../oauth-flow';
88
import type { v2 } from '../../spec-types';
99

1010
export class OAuthFlow<F extends v2.OAuthFlowObjectBase> extends BaseModel<F> implements OAuthFlowInterface {
11+
hasAuthorizationUrl(): boolean {
12+
return !!this.json<v2.OAuthFlowObjectAuthorizationCode>().authorizationUrl;
13+
}
14+
1115
authorizationUrl(): string | undefined {
1216
return this.json<v2.OAuthFlowObjectAuthorizationCode>().authorizationUrl;
1317
}
1418

19+
hasTokenUrl(): boolean {
20+
return !!this.json<Extract<v2.OAuthFlowObject, v2.OAuthFlowObjectImplicit>>().tokenUrl;
21+
}
22+
23+
tokenUrl(): string | undefined {
24+
return this.json<Extract<v2.OAuthFlowObject, v2.OAuthFlowObjectImplicit>>().tokenUrl;
25+
}
26+
1527
hasRefreshUrl(): boolean {
1628
return !!this._json.refreshUrl;
1729
}
@@ -24,10 +36,6 @@ export class OAuthFlow<F extends v2.OAuthFlowObjectBase> extends BaseModel<F> im
2436
return this._json.scopes;
2537
}
2638

27-
tokenUrl(): string | undefined {
28-
return this.json<Extract<v2.OAuthFlowObject, v2.OAuthFlowObjectImplicit>>().tokenUrl;
29-
}
30-
3139
extensions(): ExtensionsInterface {
3240
return extensions(this);
3341
}

src/models/v2/operation-trait.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BaseModel } from '../base';
22
import { SecurityScheme } from './security-scheme';
3+
import { SecurityRequirements } from './security-requirements';
4+
import { SecurityRequirement } from './security-requirement';
35

46
import { bindings, hasDescription, description, extensions, hasExternalDocs, externalDocs, tags } from './mixins';
57

@@ -11,18 +13,12 @@ import type { OperationTraitInterface } from '../operation-trait';
1113
import type { TagsInterface } from '../tags';
1214

1315
import type { v2 } from '../../spec-types';
14-
import { SecurityRequirements } from './security-requirements';
15-
import { SecurityRequirement } from './security-requirement';
1616

1717
export class OperationTrait<J extends v2.OperationTraitObject = v2.OperationTraitObject> extends BaseModel<J, { id: string, action: OperationAction }> implements OperationTraitInterface {
1818
id(): string {
1919
return this.operationId() || this._meta.id;
2020
}
2121

22-
action(): OperationAction {
23-
return this._meta.action;
24-
}
25-
2622
hasOperationId(): boolean {
2723
return !!this._json.operationId;
2824
}
@@ -51,14 +47,6 @@ export class OperationTrait<J extends v2.OperationTraitObject = v2.OperationTrai
5147
return hasExternalDocs(this);
5248
}
5349

54-
isSend(): boolean {
55-
return this.action() === 'subscribe';
56-
}
57-
58-
isReceive(): boolean {
59-
return this.action() === 'publish';
60-
}
61-
6250
externalDocs(): ExternalDocumentationInterface | undefined {
6351
return externalDocs(this);
6452
}

src/models/v2/operation.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ import { tilde } from '../../utils';
1111
import type { ChannelsInterface } from '../channels';
1212
import type { ChannelInterface } from '../channel';
1313
import type { MessagesInterface } from '../messages';
14-
import type { OperationInterface } from '../operation';
14+
import type { OperationInterface, OperationAction } from '../operation';
1515
import type { OperationTraitsInterface } from '../operation-traits';
1616
import type { ServersInterface } from '../servers';
1717
import type { ServerInterface } from '../server';
1818

1919
import type { v2 } from '../../spec-types';
2020

2121
export class Operation extends OperationTrait<v2.OperationObject> implements OperationInterface {
22+
action(): OperationAction {
23+
return this._meta.action;
24+
}
25+
26+
isSend(): boolean {
27+
return this.action() === 'subscribe';
28+
}
29+
30+
isReceive(): boolean {
31+
return this.action() === 'publish';
32+
}
33+
2234
servers(): ServersInterface {
2335
const servers: ServerInterface[] = [];
2436
const serversData: any[] = [];

test/models/v2/correlation-id.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ import { serializeInput, assertDescription, assertExtensions } from './utils';
55
import type { v2 } from '../../../src/spec-types';
66

77
describe('CorrelationId model', function() {
8-
describe('.hasLocation()', function() {
9-
it('should return true when there is a value', function() {
10-
const doc = serializeInput<v2.CorrelationIDObject>({ location: '...' });
11-
const d = new CorrelationId(doc);
12-
expect(d.hasLocation()).toEqual(true);
13-
});
14-
15-
it('should return false when there is no value', function() {
16-
const doc = serializeInput<v2.CorrelationIDObject>({});
17-
const d = new CorrelationId(doc);
18-
expect(d.hasLocation()).toEqual(false);
19-
});
20-
});
21-
228
describe('.location()', function() {
239
it('should return the value', function() {
2410
const doc = serializeInput<v2.CorrelationIDObject>({ location: '...' });

test/models/v2/oauth-flow.spec.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { v2 } from '../../../src/spec-types';
44

55
const flowObject = {
66
authorizationUrl: 'https://example.com/api/oauth/dialog',
7+
tokenUrl: '...',
8+
refreshUrl: '...',
79
scopes: {
810
'write:pets': 'modify pets in your account',
911
'read:pets': 'read your pets'
@@ -14,13 +16,63 @@ const flow = new OAuthFlow(flowObject);
1416
const emptyObject = new OAuthFlow({} as v2.OAuthFlowObject);
1517

1618
describe('OAuth Flow', function() {
19+
describe('.hasAuthorizationUrl()', function() {
20+
it('should return true if authorizationUrl is present', function() {
21+
expect(flow.hasAuthorizationUrl()).toEqual(true);
22+
});
23+
24+
it('should return false if authorizationUrl is not present', function() {
25+
expect(emptyObject.hasAuthorizationUrl()).toEqual(false);
26+
});
27+
});
28+
1729
describe('.authorizationUrl()', function() {
18-
it('should reutrn undefined if no authorizationUrl present', function() {
30+
it('should return authrozationUrl if present', function() {
31+
expect(flow.authorizationUrl()).toEqual(flowObject.authorizationUrl);
32+
});
33+
34+
it('should return undefined if authorizationUrl is not present', function() {
1935
expect(emptyObject.authorizationUrl()).toBeUndefined();
2036
});
37+
});
38+
39+
describe('.hasTokenUrl()', function() {
40+
it('should return true if tokenUrl is present', function() {
41+
expect(flow.hasTokenUrl()).toEqual(true);
42+
});
43+
44+
it('should return false if tokenUrl is not present', function() {
45+
expect(emptyObject.hasTokenUrl()).toEqual(false);
46+
});
47+
});
48+
49+
describe('.tokenUrl()', function() {
50+
it('should return tokenUrl if present', function() {
51+
expect(flow.tokenUrl()).toEqual(flowObject.tokenUrl);
52+
});
53+
54+
it('should return undefined if tokenUrl is not present', function() {
55+
expect(emptyObject.tokenUrl()).toBeUndefined();
56+
});
57+
});
58+
59+
describe('.hasRefreshUrl()', function() {
60+
it('should return true if refreshUrl is present', function() {
61+
expect(flow.hasRefreshUrl()).toEqual(true);
62+
});
2163

22-
it('should return authrozationUrl ', function() {
23-
expect(flow.authorizationUrl()).toMatch(flowObject.authorizationUrl);
64+
it('should return false if refreshUrl is not present', function() {
65+
expect(emptyObject.hasRefreshUrl()).toEqual(false);
66+
});
67+
});
68+
69+
describe('.refreshUrl()', function() {
70+
it('should return refreshUrl if present', function() {
71+
expect(flow.refreshUrl()).toEqual(flowObject.refreshUrl);
72+
});
73+
74+
it('should return undefined if refreshUrl is not present', function() {
75+
expect(emptyObject.refreshUrl()).toBeUndefined();
2476
});
2577
});
2678

test/models/v2/operation.spec.ts

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,70 @@ describe('Operation model', function() {
2525
});
2626
});
2727

28+
describe('.action()', function() {
29+
it('should return kind/action of operation', function() {
30+
const doc = {};
31+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
32+
expect(d.action()).toEqual('publish');
33+
});
34+
});
35+
36+
describe('.isSend()', function() {
37+
it('should return true when operation is subscribe', function() {
38+
const doc = {};
39+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'subscribe' });
40+
expect(d.isSend()).toBeTruthy();
41+
});
42+
43+
it('should return false when operation is publish', function() {
44+
const doc = {};
45+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
46+
expect(d.isSend()).toBeFalsy();
47+
});
48+
});
49+
50+
describe('.isReceive()', function() {
51+
it('should return true when operation is publish', function() {
52+
const doc = {};
53+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
54+
expect(d.isReceive()).toBeTruthy();
55+
});
56+
57+
it('should return false when operation is subscribe', function() {
58+
const doc = {};
59+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'subscribe' });
60+
expect(d.isReceive()).toBeFalsy();
61+
});
62+
});
63+
64+
describe('.hasOperationId()', function() {
65+
it('should return true if operationId is present', function() {
66+
const doc = { operationId: '...' };
67+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
68+
expect(d.hasOperationId()).toEqual(true);
69+
});
70+
71+
it('should return falsee if operationId is present', function() {
72+
const doc = {};
73+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
74+
expect(d.hasOperationId()).toEqual(false);
75+
});
76+
});
77+
78+
describe('.operationId()', function() {
79+
it('should return operationId if present', function() {
80+
const doc = { operationId: '...' };
81+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
82+
expect(d.operationId()).toEqual(doc.operationId);
83+
});
84+
85+
it('should return undefined if operationId is not present', function() {
86+
const doc = {};
87+
const d = new Operation(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
88+
expect(d.operationId()).toEqual(undefined);
89+
});
90+
});
91+
2892
describe('.servers()', function() {
2993
it('should return collection of servers - channel available on all servers', function() {
3094
const doc = {};
@@ -89,42 +153,6 @@ describe('Operation model', function() {
89153
});
90154
});
91155

92-
describe('.action()', function() {
93-
it('should return kind/action of operation', function() {
94-
const doc = {};
95-
const d = new OperationTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
96-
expect(d.action()).toEqual('publish');
97-
});
98-
});
99-
100-
describe('.isSend()', function() {
101-
it('should return true when operation is subscribe', function() {
102-
const doc = {};
103-
const d = new OperationTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'subscribe' });
104-
expect(d.isSend()).toBeTruthy();
105-
});
106-
107-
it('should return false when operation is publish', function() {
108-
const doc = {};
109-
const d = new OperationTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
110-
expect(d.isSend()).toBeFalsy();
111-
});
112-
});
113-
114-
describe('.isReceive()', function() {
115-
it('should return true when operation is publish', function() {
116-
const doc = {};
117-
const d = new OperationTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'publish' });
118-
expect(d.isReceive()).toBeTruthy();
119-
});
120-
121-
it('should return false when operation is subscribe', function() {
122-
const doc = {};
123-
const d = new OperationTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait', action: 'subscribe' });
124-
expect(d.isReceive()).toBeFalsy();
125-
});
126-
});
127-
128156
describe('.messages()', function() {
129157
it('should return collection of messages - single message', function() {
130158
const doc = { message: { messageId: '...' } };

0 commit comments

Comments
 (0)