Skip to content

Commit

Permalink
fix: obtain jq wrap/pair from annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Oct 13, 2023
1 parent 0484473 commit 3d38e32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
38 changes: 13 additions & 25 deletions src/parser/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ export default class Endpoint {
apiMetadata: ParsedAPIMetadataObject;
path: string;

constructor(
pathItemObject: SmartAPIPathItemObject,
apiMetadata: ParsedAPIMetadataObject,
path: string
) {
constructor(pathItemObject: SmartAPIPathItemObject, apiMetadata: ParsedAPIMetadataObject, path: string) {
this.pathItemObject = pathItemObject;
this.apiMetadata = apiMetadata;
this.path = path;
Expand Down Expand Up @@ -54,10 +50,7 @@ export default class Endpoint {
queryOperation.server = server;
queryOperation.path = this.path;
queryOperation.tags = this.apiMetadata.tags;
queryOperation.transformer = {
wrap_jq: this.resolveRefIfProvided(op?.transformer?.jq?.wrap),
pair_jq: this.resolveRefIfProvided(op?.transformer?.jq?.pair)
};
queryOperation.transformer = this.resolveRefIfProvided(op?.transformer);
return queryOperation;
}

Expand All @@ -73,13 +66,13 @@ export default class Endpoint {

private resolveRefIfProvided(rec?: SmartAPIReferenceObject) {
if (typeof rec !== "object" || !rec.$ref) return rec;
return this.apiMetadata.components.fetchComponentByRef(rec.$ref)
return this.apiMetadata.components.fetchComponentByRef(rec.$ref);
}

private constructAssociation(
input: XBTEKGSOperationBioEntityObject,
output: XBTEKGSOperationBioEntityObject,
op: XBTEKGSOperationObject
op: XBTEKGSOperationObject,
) {
return {
input_id: this.removeBioLinkPrefix(input.id),
Expand All @@ -89,11 +82,11 @@ export default class Endpoint {
predicate: this.removeBioLinkPrefix(op.predicate),
qualifiers: op.qualifiers
? Object.fromEntries(
Object.entries(op.qualifiers).map(([qualifierType, qualifier]) => [
this.removeBioLinkPrefix(qualifierType),
qualifier,
]),
)
Object.entries(op.qualifiers).map(([qualifierType, qualifier]) => [
this.removeBioLinkPrefix(qualifierType),
qualifier,
]),
)
: undefined,
source: op.source,
api_name: this.apiMetadata.title,
Expand All @@ -114,7 +107,7 @@ export default class Endpoint {
private parseIndividualOperation({
op,
method,
pathParams
pathParams,
}: {
op: XBTEKGSOperationObject;
method: string;
Expand Down Expand Up @@ -145,7 +138,7 @@ export default class Endpoint {

constructEndpointInfo() {
let res = [] as SmartAPIKGOperationObject[];
["get", "post"].map((method) => {
["get", "post"].map(method => {
if (method in this.pathItemObject) {
const pathParams = this.fetchPathParams(this.pathItemObject[method]);
if (
Expand All @@ -154,16 +147,11 @@ export default class Endpoint {
) {
let operation;
let op;
for (const rec of this.pathItemObject[method][
"x-bte-kgs-operations"
]) {
for (const rec of this.pathItemObject[method]["x-bte-kgs-operations"]) {
operation = this.resolveRefIfProvided(rec);
operation = Array.isArray(operation) ? operation : [operation];
for (op of operation) {
res = [
...res,
...this.parseIndividualOperation({ op, method, pathParams }),
];
res = [...res, ...this.parseIndividualOperation({ op, method, pathParams })];
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/query_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
XBTEKGSOperationObject,
QueryOperationInterface,
XBTEParametersObject,
TransformerObject,
TransformerSet,
} from "./types";

export default class QueryOperationObject implements QueryOperationInterface {
Expand All @@ -19,7 +19,7 @@ export default class QueryOperationObject implements QueryOperationInterface {
private _tags: string[];
private _pathParams: string[];
private _templateInputs: object;
private _transformer: TransformerObject;
private _transformer: TransformerSet;

set xBTEKGSOperation(newOp: XBTEKGSOperationObject) {
this._params = newOp.parameters;
Expand Down Expand Up @@ -64,11 +64,11 @@ export default class QueryOperationObject implements QueryOperationInterface {
return this._inputSeparator;
}

get transformer(): TransformerObject {
get transformer(): TransformerSet {
return this._transformer;

Check warning on line 68 in src/parser/query_operation.ts

View check run for this annotation

Codecov / codecov/patch

src/parser/query_operation.ts#L67-L68

Added lines #L67 - L68 were not covered by tests
}

set transformer(newTransformer: TransformerObject) {
set transformer(newTransformer: TransformerSet) {
this._transformer = newTransformer;
}

Expand Down
12 changes: 8 additions & 4 deletions src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ interface KGAssociationObject {
"x-trapi"?: XTRAPIObject;
qualifiers?: {
[qualifierType: string]: string | string[];
}
};
}

export interface TransformerObject {
wrap_jq?: string;
pair_jq?: string;
wrap?: string;
pair?: string;
}

export interface TransformerSet {
[transformerPattern: string]: TransformerObject;
}

export interface QueryOperationInterface {
Expand All @@ -182,7 +186,7 @@ export interface QueryOperationInterface {
request_body: object;
supportBatch: boolean;
inputSeparator: string;
transformer: TransformerObject;
transformer: TransformerSet;
}

export interface SmartAPIKGOperationObject {
Expand Down

0 comments on commit 3d38e32

Please sign in to comment.