pact-gen-ts
Version:
Generating pact files from typescript definitions
24 lines (23 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestBody = void 0;
const type_representation_1 = require("./type-representation");
const interaction_creator_1 = require("./interaction-creator");
const create_pact_example_object_1 = require("./create-pact-example-object");
const create_pact_matching_rules_1 = require("./create-pact-matching-rules");
const pact_annotations_1 = require("../consts/pact-annotations");
const body_1 = require("./body");
class RequestBody extends body_1.Body {
constructor(apiFunctionNode, sourceFile) {
super();
const requestBodyElement = interaction_creator_1.InteractionCreator.getParameterWithJsDocFromFunction(apiFunctionNode, pact_annotations_1.PACT_ANNOTATIONS.PACT_REQUEST_BODY) ||
interaction_creator_1.InteractionCreator.getVariableWithJsDocFromFunction(apiFunctionNode, pact_annotations_1.PACT_ANNOTATIONS.PACT_REQUEST_BODY);
if (requestBodyElement) {
const requestBodyElementType = requestBodyElement.getType();
const basicTypeRepresentationOfRequestBody = (0, type_representation_1.getTypeRepresentation)(requestBodyElementType, sourceFile);
this.body = (0, create_pact_example_object_1.changeObjectRepresentationIntoExample)(basicTypeRepresentationOfRequestBody);
this.matchingRules = (0, create_pact_matching_rules_1.changeObjectRepresentationIntoMatchingRules)(basicTypeRepresentationOfRequestBody, '$.body');
}
}
}
exports.RequestBody = RequestBody;