in lib/transform/pathRegexTransformer.ts [102:160]
transform(spec, { schemaValidator, jsonLoader }) {
let basePathPrefix = spec.basePath ?? "";
if (basePathPrefix.endsWith("/")) {
basePathPrefix = basePathPrefix.substr(0, basePathPrefix.length - 1);
}
const msParameterizedHost = spec[xmsParameterizedHost];
const hostTemplate = msParameterizedHost?.hostTemplate ?? "";
const hostParams = msParameterizedHost?.parameters;
traverseSwagger(spec, {
onPath: (path, pathTemplate) => {
let pathStr = pathTemplate;
const queryIdx = pathTemplate.indexOf("?");
if (queryIdx !== -1) {
// path in x-ms-paths has query part we need to match
const queryMatch = urlParse(pathStr, true).query;
const querySchema: Schema = { type: "object", properties: {}, required: [] };
for (const queryKey of Object.keys(queryMatch)) {
const queryVal = queryMatch[queryKey];
querySchema.required!.push(queryKey);
querySchema.properties![queryKey] = {
enum: typeof queryVal === "string" ? [queryVal] : queryVal,
};
}
path._validateQuery = schemaValidator.compile(querySchema);
pathStr = pathTemplate.substr(0, queryIdx);
}
const pathParams = new Map<string, PathParameter>();
const collectPathParams = (params?: Parameter[]) => {
if (params !== undefined) {
for (const p of params) {
const param = jsonLoader.resolveRefObj(p);
if (param.in === "path") {
pathParams.set(param.name, param);
}
}
}
};
collectPathParams(hostParams);
collectPathParams(path.parameters);
for (const httpMethod of lowerHttpMethods) {
collectPathParams(path[httpMethod]?.parameters);
}
path._pathRegex = buildPathRegex(hostTemplate, basePathPrefix, pathStr, pathParams);
},
onOperation: (operation) => {
if (operation.externalDocs !== undefined) {
operation.externalDocs = undefined;
}
},
onResponse: (response) => {
if (response.examples !== undefined) {
response.examples = undefined;
}
},
});
},