UNPKG

sofa-api

Version:

Create REST APIs with GraphQL

43 lines (42 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapToPrimitive = mapToPrimitive; exports.mapToRef = mapToRef; exports.normalizePathParamForOpenAPI = normalizePathParamForOpenAPI; function mapToPrimitive(type) { const formatMap = { Int: { type: 'integer', format: 'int32', }, Float: { type: 'number', format: 'float', }, String: { type: 'string', }, Boolean: { type: 'boolean', }, ID: { type: 'string', }, }; if (formatMap[type]) { return formatMap[type]; } } function mapToRef(type) { return `#/components/schemas/${type}`; } function normalizePathParamForOpenAPI(path) { const pathParts = path.split('/'); const normalizedPathParts = pathParts.map((part) => { if (part.startsWith(':')) { return `{${part.slice(1)}}`; } return part; }); return normalizedPathParts.join('/'); }