@ovotech/laminar-cli
Advanced tools
Comparing version 0.9.2 to 0.9.3
@@ -9,5 +9,3 @@ "use strict"; | ||
const title = (str) => str.replace(/^./, (first) => first.toUpperCase()); | ||
const documentation = (summary, description) => summary || description | ||
? [summary, description].filter((item) => item !== undefined).join('\n') | ||
: undefined; | ||
const documentation = (summary, description) => summary || description ? [summary, description].filter((item) => item !== undefined).join('\n') : undefined; | ||
const cleanIdentifierName = (str) => str.replace(/[^0-9a-zA-Z_$]+/g, ''); | ||
@@ -30,5 +28,3 @@ const pathToIdentifier = (path) => path.split('/').map(cleanIdentifierName).map(title).join(''); | ||
const param = traverse_1.getReferencedObject(paramOrRef, traverse_1.isParameterObject, node.context); | ||
const paramNode = param.schema | ||
? convert_schema_1.convertSchema(node.context, param.schema) | ||
: ts_compose_1.document(node.context, ts_compose_1.Type.Any); | ||
const paramNode = param.schema ? convert_schema_1.convertSchema(node.context, param.schema) : ts_compose_1.document(node.context, ts_compose_1.Type.Any); | ||
const params = (_a = node.in[toParamLocation(param.in)]) !== null && _a !== void 0 ? _a : []; | ||
@@ -62,6 +58,3 @@ return { | ||
name, | ||
type: ts_compose_1.Type.Referance('OapiSecurityResolver', [ | ||
ts_compose_1.Type.Referance('R'), | ||
ts_compose_1.Type.Referance('TAuthInfo'), | ||
]), | ||
type: ts_compose_1.Type.Referance('OapiSecurityResolver', [ts_compose_1.Type.Referance('R'), ts_compose_1.Type.Referance('TAuthInfo')]), | ||
})); | ||
@@ -105,7 +98,3 @@ }); | ||
}); | ||
return ts_compose_1.document(typeContext, ts_compose_1.Type.Referance('ResponseOapi', [ | ||
(_a = typeSchema.type) !== null && _a !== void 0 ? _a : ts_compose_1.Type.Unknown, | ||
typeStatus, | ||
typeString, | ||
])); | ||
return ts_compose_1.document(typeContext, ts_compose_1.Type.Referance('ResponseOapi', [(_a = typeSchema.type) !== null && _a !== void 0 ? _a : ts_compose_1.Type.Unknown, typeStatus, typeString])); | ||
}); | ||
@@ -121,5 +110,3 @@ return ts_compose_1.document(mediaTypesContext, items); | ||
const requestBody = traverse_1.getReferencedObject(requestBodyOrRef, traverse_1.isRequestBodyObject, context); | ||
const schema = requestBody.content['application/json'] | ||
? requestBody.content['application/json'].schema | ||
: {}; | ||
const schema = requestBody.content['application/json'] ? requestBody.content['application/json'].schema : {}; | ||
const node = schema ? convert_schema_1.convertSchema(context, schema) : ts_compose_1.document(context, ts_compose_1.Type.Any); | ||
@@ -130,3 +117,3 @@ return ts_compose_1.document(node.context, ts_compose_1.Type.TypeLiteral({ | ||
}; | ||
exports.convertOapi = (context, api) => { | ||
const convertOapi = (context, api) => { | ||
var _a, _b, _c; | ||
@@ -139,6 +126,3 @@ const paths = ts_compose_1.mapWithContext(context, Object.entries(api.paths), (pathContext, [path, pathApiOrRef]) => { | ||
const astParams = operation.parameters || parameters | ||
? convertParameters(methodContext, [ | ||
...(parameters !== null && parameters !== void 0 ? parameters : []), | ||
...((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), | ||
]) | ||
? convertParameters(methodContext, [...(parameters !== null && parameters !== void 0 ? parameters : []), ...((_a = operation.parameters) !== null && _a !== void 0 ? _a : [])]) | ||
: ts_compose_1.document(methodContext, ts_compose_1.Type.TypeLiteral()); | ||
@@ -194,5 +178,3 @@ const astRequestBody = operation.requestBody | ||
...(requestInterface | ||
? [ | ||
ts_compose_1.Type.Referance(requestIdentifier, security ? [ts_compose_1.Type.Referance('TAuthInfo')] : undefined), | ||
] | ||
? [ts_compose_1.Type.Referance(requestIdentifier, security ? [ts_compose_1.Type.Referance('TAuthInfo')] : undefined)] | ||
: [ts_compose_1.Type.Referance('RequestOapi')]), | ||
@@ -214,5 +196,3 @@ ts_compose_1.Type.Referance('R'), | ||
}); | ||
return ts_compose_1.document(ts_compose_1.withIdentifier(requestInterface | ||
? ts_compose_1.withIdentifier(responseAst.context, requestInterface) | ||
: responseAst.context, pathType), methodSignature); | ||
return ts_compose_1.document(ts_compose_1.withIdentifier(requestInterface ? ts_compose_1.withIdentifier(responseAst.context, requestInterface) : responseAst.context, pathType), methodSignature); | ||
}); | ||
@@ -275,6 +255,3 @@ return ts_compose_1.document(methods.context, ts_compose_1.Type.Prop({ | ||
name: 'config', | ||
type: ts_compose_1.Type.Referance('Config', [ | ||
ts_compose_1.Type.Referance('R'), | ||
...(security ? [ts_compose_1.Type.Referance('TAuthInfo')] : []), | ||
]), | ||
type: ts_compose_1.Type.Referance('Config', [ts_compose_1.Type.Referance('R'), ...(security ? [ts_compose_1.Type.Referance('TAuthInfo')] : [])]), | ||
}), | ||
@@ -290,5 +267,7 @@ ], | ||
}; | ||
exports.oapiTs = async (api) => { | ||
exports.convertOapi = convertOapi; | ||
const oapiTs = async (api) => { | ||
const { schema, refs } = await json_schema_1.compile(api); | ||
return ts_compose_1.printDocument(exports.convertOapi({ root: schema, refs }, schema)); | ||
}; | ||
exports.oapiTs = oapiTs; |
@@ -11,8 +11,10 @@ "use strict"; | ||
const helpers_1 = require("../../helpers"); | ||
exports.processFile = async (fileName) => { | ||
const processFile = async (fileName) => { | ||
const { context, uris, value } = await helpers_1.toContext(fileName); | ||
return { content: ts_compose_1.printDocument(convert_1.convertOapi(context, value)), uris }; | ||
}; | ||
exports.toFiles = (uris) => uris.filter((uri) => uri.startsWith('file://')).map((uri) => uri.substring('file://'.length)); | ||
exports.apiCommand = (logger = console) => commander | ||
exports.processFile = processFile; | ||
const toFiles = (uris) => uris.filter((uri) => uri.startsWith('file://')).map((uri) => uri.substring('file://'.length)); | ||
exports.toFiles = toFiles; | ||
const apiCommand = (logger = console) => commander | ||
.createCommand('api') | ||
@@ -60,1 +62,2 @@ .description('Convert openapi schemas to typescript types') | ||
}); | ||
exports.apiCommand = apiCommand; |
@@ -9,5 +9,3 @@ "use strict"; | ||
const isStatusOk = (status) => Number(status) >= 200 && Number(status) <= 300; | ||
const documentation = (summary, description) => summary || description | ||
? [summary, description].filter((item) => item !== undefined).join('\n') | ||
: undefined; | ||
const documentation = (summary, description) => summary || description ? [summary, description].filter((item) => item !== undefined).join('\n') : undefined; | ||
const title = (str) => str.replace(/^./, (first) => first.toUpperCase()); | ||
@@ -27,5 +25,3 @@ const cleanIdentifierName = (str) => str.replace(/[^0-9a-zA-Z_$]+/g, ''); | ||
var _a; | ||
const astParams = param.schema | ||
? convert_schema_1.convertSchema(context, param.schema) | ||
: ts_compose_1.document(context, ts_compose_1.Type.Unknown); | ||
const astParams = param.schema ? convert_schema_1.convertSchema(context, param.schema) : ts_compose_1.document(context, ts_compose_1.Type.Unknown); | ||
return ts_compose_1.document((_a = astParams === null || astParams === void 0 ? void 0 : astParams.context) !== null && _a !== void 0 ? _a : context, { | ||
@@ -39,5 +35,3 @@ name: param.name, | ||
return ts_compose_1.mapWithContext(context, parameters, (context, param) => { | ||
const astParams = param.schema | ||
? convert_schema_1.convertSchema(context, param.schema) | ||
: ts_compose_1.document(context, ts_compose_1.Type.Unknown); | ||
const astParams = param.schema ? convert_schema_1.convertSchema(context, param.schema) : ts_compose_1.document(context, ts_compose_1.Type.Unknown); | ||
return ts_compose_1.document(astParams.context, ts_compose_1.Type.Prop({ | ||
@@ -86,7 +80,3 @@ name: param.in === 'header' ? param.name.toLowerCase() : param.name, | ||
const responseTypes = astResponses.items.filter(isTypeNode); | ||
return ts_compose_1.document(astResponses.context, responseTypes.length === 0 | ||
? undefined | ||
: responseTypes.length == 1 | ||
? responseTypes[0] | ||
: ts_compose_1.Type.Union(responseTypes)); | ||
return ts_compose_1.document(astResponses.context, responseTypes.length === 0 ? undefined : responseTypes.length == 1 ? responseTypes[0] : ts_compose_1.Type.Union(responseTypes)); | ||
}; | ||
@@ -105,3 +95,3 @@ const convertRequestBody = (context, requestBodyOrRef) => { | ||
}; | ||
exports.convertOapi = (context, api) => { | ||
const convertOapi = (context, api) => { | ||
const paths = ts_compose_1.mapWithContext(context, Object.entries(api.paths), (pathContext, [path, pathApiOrRef]) => { | ||
@@ -112,6 +102,3 @@ const { parameters, description, summary, ...methodsApiOrRef } = pathApiOrRef; | ||
var _a; | ||
const combinedParameters = [ | ||
...(parameters !== null && parameters !== void 0 ? parameters : []), | ||
...((_a = operation.parameters) !== null && _a !== void 0 ? _a : []), | ||
].map((item) => traverse_1.getReferencedObject(item, traverse_1.isParameterObject, methodContext)); | ||
const combinedParameters = [...(parameters !== null && parameters !== void 0 ? parameters : []), ...((_a = operation.parameters) !== null && _a !== void 0 ? _a : [])].map((item) => traverse_1.getReferencedObject(item, traverse_1.isParameterObject, methodContext)); | ||
const requestName = `${method.toUpperCase()} ${path}`; | ||
@@ -187,7 +174,3 @@ const pathItems = convertPathParams(methodContext, path, combinedParameters); | ||
module: 'axios', | ||
named: [ | ||
{ name: 'AxiosRequestConfig' }, | ||
{ name: 'AxiosInstance' }, | ||
{ name: 'AxiosResponse' }, | ||
], | ||
named: [{ name: 'AxiosRequestConfig' }, { name: 'AxiosInstance' }, { name: 'AxiosResponse' }], | ||
}), ts_compose_1.Type.Interface({ | ||
@@ -219,1 +202,2 @@ name: 'AxiosOapiInstance', | ||
}; | ||
exports.convertOapi = convertOapi; |
@@ -12,6 +12,7 @@ "use strict"; | ||
const helpers_1 = require("../../helpers"); | ||
exports.processFile = async (file) => { | ||
const processFile = async (file) => { | ||
const { context, value } = await helpers_1.toContext(file); | ||
return ts_compose_1.printDocument(convert_1.convertOapi(context, value)); | ||
}; | ||
exports.processFile = processFile; | ||
const parseSchema = (type, content) => { | ||
@@ -27,3 +28,3 @@ switch (type) { | ||
}; | ||
exports.axiosCommand = (logger = console) => commander | ||
const axiosCommand = (logger = console) => commander | ||
.createCommand('axios') | ||
@@ -46,1 +47,2 @@ .description('Convert openapi schemas to typescript types for axios') | ||
}); | ||
exports.axiosCommand = axiosCommand; |
@@ -13,3 +13,3 @@ "use strict"; | ||
const convert_schema_1 = require("../../convert-schema"); | ||
exports.processFile = async (file, name) => { | ||
const processFile = async (file, name) => { | ||
const { schema, refs } = await json_schema_1.compile(file); | ||
@@ -19,2 +19,3 @@ const converted = convert_schema_1.convertSchema({ root: schema, refs }, schema); | ||
}; | ||
exports.processFile = processFile; | ||
const parseSchema = (type, content) => { | ||
@@ -30,3 +31,3 @@ switch (type) { | ||
}; | ||
exports.jsonSchemaCommand = (logger = console) => commander | ||
const jsonSchemaCommand = (logger = console) => commander | ||
.createCommand('json-schema') | ||
@@ -50,1 +51,2 @@ .description('Convert json schema to typescript types') | ||
}); | ||
exports.jsonSchemaCommand = jsonSchemaCommand; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const json_shema_1 = require("./json-shema"); | ||
exports.laminarCommand = (output = console) => commander | ||
const laminarCommand = (output = console) => commander | ||
.createCommand('laminar') | ||
@@ -31,1 +31,2 @@ .version('0.9.2') | ||
.addCommand(json_shema_1.jsonSchemaCommand(output)); | ||
exports.laminarCommand = laminarCommand; |
@@ -52,5 +52,3 @@ "use strict"; | ||
: null; | ||
const convertConst = (context, schema) => traverse_1.isSchemaObject(schema) && schema.const !== undefined | ||
? ts_compose_1.document(context, ts_compose_1.Type.Literal(schema.const)) | ||
: null; | ||
const convertConst = (context, schema) => traverse_1.isSchemaObject(schema) && schema.const !== undefined ? ts_compose_1.document(context, ts_compose_1.Type.Literal(schema.const)) : null; | ||
const convertRef = (context, schema) => { | ||
@@ -86,5 +84,3 @@ var _a; | ||
const converted = exports.convertSchema(context, schema.additionalProperties); | ||
return ts_compose_1.document(converted.context, areAllPropertiesRequired(schema) | ||
? converted.type | ||
: ts_compose_1.Type.Union([converted.type, ts_compose_1.Type.Undefined])); | ||
return ts_compose_1.document(converted.context, areAllPropertiesRequired(schema) ? converted.type : ts_compose_1.Type.Union([converted.type, ts_compose_1.Type.Undefined])); | ||
} | ||
@@ -161,5 +157,3 @@ else if (schema.additionalProperties !== false) { | ||
else { | ||
const value = schema.items | ||
? exports.convertSchema(context, schema.items) | ||
: ts_compose_1.document(context, ts_compose_1.Type.Any); | ||
const value = schema.items ? exports.convertSchema(context, schema.items) : ts_compose_1.document(context, ts_compose_1.Type.Any); | ||
return ts_compose_1.document(value.context, ts_compose_1.Type.Array(value.type)); | ||
@@ -187,6 +181,8 @@ } | ||
]; | ||
exports.convertSchema = (context, schema) => converters.reduce((node, converter) => node || converter(context, schema), null) || ts_compose_1.document(context, ts_compose_1.Type.Any); | ||
exports.schemaTs = async (api) => { | ||
const convertSchema = (context, schema) => converters.reduce((node, converter) => node || converter(context, schema), null) || ts_compose_1.document(context, ts_compose_1.Type.Any); | ||
exports.convertSchema = convertSchema; | ||
const schemaTs = async (api) => { | ||
const { schema, refs } = await json_schema_1.compile(api); | ||
return ts_compose_1.printDocument(exports.convertSchema({ root: schema, refs }, schema)); | ||
}; | ||
exports.schemaTs = schemaTs; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const YAML = require("yaml"); | ||
exports.toString = async (stream) => { | ||
const toString = async (stream) => { | ||
let str = ''; | ||
@@ -16,3 +16,4 @@ return new Promise((resolve, reject) => { | ||
}; | ||
exports.toContext = async (fileName) => { | ||
exports.toString = toString; | ||
const toContext = async (fileName) => { | ||
const { schema, uris, refs } = await json_schema_1.compile(fileName); | ||
@@ -26,3 +27,4 @@ const { value } = await json_schema_1.ensureValid({ | ||
}; | ||
exports.parseSchema = (type, content) => { | ||
exports.toContext = toContext; | ||
const parseSchema = (type, content) => { | ||
switch (type) { | ||
@@ -37,1 +39,2 @@ case 'json': | ||
}; | ||
exports.parseSchema = parseSchema; |
@@ -10,4 +10,7 @@ "use strict"; | ||
Object.defineProperty(exports, "convertSchema", { enumerable: true, get: function () { return convert_schema_2.convertSchema; } }); | ||
exports.apiContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_1.convertOapi({ root: schema, refs }, schema)); | ||
exports.axiosContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_2.convertOapi({ root: schema, refs }, schema)); | ||
exports.schemaContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_schema_1.convertSchema({ root: schema, refs }, schema)); | ||
const apiContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_1.convertOapi({ root: schema, refs }, schema)); | ||
exports.apiContent = apiContent; | ||
const axiosContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_2.convertOapi({ root: schema, refs }, schema)); | ||
exports.axiosContent = axiosContent; | ||
const schemaContent = ({ schema, refs }) => ts_compose_1.printDocument(convert_schema_1.convertSchema({ root: schema, refs }, schema)); | ||
exports.schemaContent = schemaContent; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getReferencedObject = exports.isSchemaObject = exports.isSecuritySchemaObject = exports.isParameterObject = exports.isRequestBodyObject = exports.isMediaTypeObject = exports.isResponseObject = exports.isReferenceObject = void 0; | ||
exports.isReferenceObject = (item) => typeof item === 'object' && !!item && '$ref' in item; | ||
exports.isResponseObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'description' in item; | ||
exports.isMediaTypeObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'schema' in item; | ||
exports.isRequestBodyObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'content' in item; | ||
exports.isParameterObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'in' in item && 'name' in item; | ||
exports.isSecuritySchemaObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'type' in item; | ||
exports.isSchemaObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item; | ||
exports.getReferencedObject = (item, guard, context) => { | ||
const isReferenceObject = (item) => typeof item === 'object' && !!item && '$ref' in item; | ||
exports.isReferenceObject = isReferenceObject; | ||
const isResponseObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'description' in item; | ||
exports.isResponseObject = isResponseObject; | ||
const isMediaTypeObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'schema' in item; | ||
exports.isMediaTypeObject = isMediaTypeObject; | ||
const isRequestBodyObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'content' in item; | ||
exports.isRequestBodyObject = isRequestBodyObject; | ||
const isParameterObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'in' in item && 'name' in item; | ||
exports.isParameterObject = isParameterObject; | ||
const isSecuritySchemaObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item && 'type' in item; | ||
exports.isSecuritySchemaObject = isSecuritySchemaObject; | ||
const isSchemaObject = (item) => !exports.isReferenceObject(item) && typeof item === 'object' && !!item; | ||
exports.isSchemaObject = isSchemaObject; | ||
const getReferencedObject = (item, guard, context) => { | ||
if (exports.isReferenceObject(item)) { | ||
@@ -26,1 +33,2 @@ if (!context.refs[item.$ref]) { | ||
}; | ||
exports.getReferencedObject = getReferencedObject; |
{ | ||
"name": "@ovotech/laminar-cli", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"main": "dist/index.js", | ||
@@ -13,15 +13,15 @@ "types": "dist/index.d.ts", | ||
"@ovotech/laminar": "^0.9.1", | ||
"@types/jest": "^26.0.14", | ||
"@types/node": "^14.11.1", | ||
"@typescript-eslint/eslint-plugin": "^4.1.1", | ||
"@typescript-eslint/parser": "^4.1.1", | ||
"axios": "^0.19.2", | ||
"eslint": "^7.9.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"jest": "^26.4.2", | ||
"pg": "^8.3.3", | ||
"prettier": "^2.1.2", | ||
"ts-jest": "^26.4.0", | ||
"@types/jest": "^26.0.16", | ||
"@types/node": "^14.14.10", | ||
"@typescript-eslint/eslint-plugin": "^4.9.0", | ||
"@typescript-eslint/parser": "^4.9.0", | ||
"axios": "^0.21.0", | ||
"eslint": "^7.14.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"jest": "^26.6.3", | ||
"pg": "^8.5.1", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2" | ||
"typescript": "^4.1.2" | ||
}, | ||
@@ -57,10 +57,10 @@ "bin": { | ||
"dependencies": { | ||
"@ovotech/json-schema": "^0.5.3", | ||
"@ovotech/ts-compose": "^0.15.0", | ||
"@ovotech/json-schema": "^0.5.4", | ||
"@ovotech/ts-compose": "^0.16.0", | ||
"chalk": "^4.0.0", | ||
"commander": "^6.1.0", | ||
"commander": "^6.2.0", | ||
"openapi-schemas": "^2.0.3", | ||
"openapi3-ts": "^2.0.0" | ||
}, | ||
"gitHead": "4915997d657f76fcfb20288755e4a5943f786464" | ||
"gitHead": "d1fc26b961d81894472591e0105ad21f20dc7c7d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64991
991
+ Added@ovotech/ts-compose@0.16.0(transitive)
- Removed@ovotech/ts-compose@0.15.0(transitive)
Updated@ovotech/json-schema@^0.5.4
Updated@ovotech/ts-compose@^0.16.0
Updatedcommander@^6.2.0