openapi-ts-json-schema
Version:
Generate TypeScript-first JSON schemas from OpenAPI definitions
19 lines (18 loc) • 660 B
JavaScript
import path from 'node:path';
import { filenamify } from './index.js';
/**
* Generate schema internal id
*/
const TRALING_SLASH_REGEX = /\/$/;
export function makeId({ schemaRelativeDirName, schemaName, }) {
const normalizedSchemaRelativeDirName = '/' +
path
.normalize(schemaRelativeDirName)
// Supporting targets dot notation
.replaceAll('.', '/')
// Replace windows backslashes \
.replaceAll('\\', '/')
.replace(TRALING_SLASH_REGEX, '');
// Shall we replace '/' with a different separator?
return normalizedSchemaRelativeDirName + '/' + filenamify(schemaName);
}