Skip to content

Commit 2ea9b6b

Browse files
Added support to parse Parameters from Components
1 parent 09edbaf commit 2ea9b6b

5 files changed

Lines changed: 60 additions & 4 deletions

File tree

src/models/entities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { StoreI } from "src/stores/entities.store";
2-
import { ConfigI } from "./config.model";
1+
import { StoreI } from 'src/stores/entities.store';
2+
import { ConfigI } from './config.model';
33

4+
export type USED_IN_ATTRIBUTE = 'query' | 'param';
45
export interface PhysycalFile {
56
name: string;
67
fileName: string;

src/models/model-attributes.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { getFixedTypeName } from '../utils/models.util';
2+
import { USED_IN_ATTRIBUTE } from './entities';
23
import { ModelModel } from './model.model';
34

45
export class ModelAttributessModel {
56
name: string;
7+
usedIn: USED_IN_ATTRIBUTE;
68
description?: string;
79
example?: string;
810
deprecated?: boolean;
@@ -26,7 +28,7 @@ export class ModelAttributessModel {
2628
}
2729

2830
get hasComments(): boolean {
29-
return !!this.description || !!this.example || !!this.deprecated;
31+
return !!this.description || !!this.example || !!this.deprecated;
3032
}
3133

3234
/**
@@ -57,7 +59,6 @@ export class ModelAttributessModel {
5759
this._model = model;
5860
}
5961

60-
6162
/**
6263
* Return a fake array with "arrayLevels" elements to print it in mustache.js
6364
*/

src/models/parameter.model.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ModelAttributessModel } from './model-attributes.model';
2+
3+
export class ParameterModel extends ModelAttributessModel {
4+
parameterNameRef: string;
5+
6+
get uri(): string {
7+
return `#/components/parameters/${this.parameterNameRef}`;
8+
}
9+
10+
constructor(
11+
parameterNameRef: string,
12+
attributeModel?: ModelAttributessModel,
13+
) {
14+
super(null);
15+
this.parameterNameRef = parameterNameRef;
16+
17+
if (attributeModel) {
18+
Object.assign(this, attributeModel);
19+
}
20+
}
21+
22+
getAttribute(): ModelAttributessModel {
23+
return this as ModelAttributessModel;
24+
}
25+
}

src/stores/entities.store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { ApiStore } from './api.store';
22
import { ModelStore } from './model.store';
3+
import { ParameterStore } from './parameter.store';
34

45
export interface StoreI {
56
models: ModelStore;
7+
parameters: ParameterStore;
68
apis: ApiStore;
79
}
810

911
export const Store = {
1012
models: new ModelStore(),
13+
parameters: new ParameterStore(),
1114
apis: new ApiStore(),
1215
} as StoreI;

src/stores/parameter.store.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ParameterModel } from '@model/parameter.model';
2+
3+
export class ParameterStore {
4+
private _parameters: Set<ParameterModel> = new Set<ParameterModel>();
5+
6+
get parameters(): ParameterModel[] {
7+
return [...this._parameters];
8+
}
9+
10+
add(attribute: ParameterModel): void {
11+
if (!this._parameters.has(attribute)) {
12+
console.debug(
13+
'Added parameter attribute to the store:',
14+
attribute.usedIn,
15+
attribute.uri,
16+
);
17+
this._parameters.add(attribute);
18+
} else {
19+
throw `Model ${attribute.uri} declared twice`;
20+
}
21+
}
22+
23+
getByUri(uri: string): ParameterModel {
24+
return this.parameters.find((attribute) => attribute.uri === uri);
25+
}
26+
}

0 commit comments

Comments
 (0)