@luvio/generator-ts
Advanced tools
Comparing version 3.5.1 to 3.5.2
@@ -8,3 +8,3 @@ /** | ||
import * as url from 'url'; | ||
import { ConsoleFileParserLogger, toCamelCase, toPascalCase } from '@luvio/utils'; | ||
import { ConsoleFileParserLogger, toCamelCase, toPascalCase, toScreamingSnakeCase } from '@luvio/utils'; | ||
import { parseUrl } from '@luvio/model'; | ||
@@ -344,2 +344,34 @@ import * as path from 'path'; | ||
function jsonSchemaFor(type) { | ||
var _a; | ||
if (type.type === 'union' || type.type === 'any') { | ||
throw new Error(`unsupported type: ${type.type}`); | ||
} | ||
else if (((_a = type.inherits) === null || _a === void 0 ? void 0 : _a.length) > 0) { | ||
throw new Error('type inheritance is not supported'); | ||
} | ||
const schemaType = type.type | ||
.replace(/^(date|time|datetime|datetime-only)$/, 'string') | ||
.replace('double', 'number') | ||
.replace('nil', 'null'); | ||
const result = code `{type:'${schemaType}'`; | ||
if (type.type === 'object') { | ||
const required = []; | ||
result.push(`,properties:{`); | ||
Object.entries(type.properties).forEach((entry, i) => { | ||
const [propName, propType] = entry; | ||
if (propType.required) { | ||
required.push(`'${propName}'`); | ||
} | ||
result.push(code `${i > 0 ? ',' : ''}${propName}:${jsonSchemaFor(propType.type)}`); | ||
}); | ||
result.push(`},required:[${required.join(',')}],additionalProperties:false`); | ||
} | ||
else if (type.type === 'array') { | ||
result.push(code `,items:${jsonSchemaFor(type.items)}`); | ||
} | ||
result.push(`}`); | ||
return result; | ||
} | ||
function typeDefinitionFor(t, options = {}) { | ||
@@ -617,2 +649,7 @@ var _a, _b; | ||
}; | ||
const JSON_SCHEMA = { | ||
module: '@luvio/jsonschema-validate', | ||
exportedSymbol: 'JSONSchema', | ||
isType: true, | ||
}; | ||
const MEDIATYPE_APP_JSON = 'application/json'; | ||
@@ -870,3 +907,4 @@ const HEADER_CONTENT_TYPE = 'Content-Type'; | ||
const outputType = getPayloadForMediaType(response.payloads); | ||
file.push(code `export class ${className} extends ${NETWORK_COMMAND}<${commandConfigType},${this.typeDefinitionFor(outputType)},${FETCH_SERVICE}>{`, this.generateFetch({ | ||
const schemaConfigConst = toScreamingSnakeCase(`${commandConfigType.exportedSymbol}Schema`); | ||
file.push(code `export const ${schemaConfigConst}: ${JSON_SCHEMA} = ${jsonSchemaFor(configType)};`, code `export class ${className} extends ${NETWORK_COMMAND}<${commandConfigType},${this.typeDefinitionFor(outputType)},${FETCH_SERVICE}>{`, this.generateFetch({ | ||
endpoint, | ||
@@ -886,2 +924,7 @@ operation, | ||
}, | ||
commandSchemaConfigConst: { | ||
filename, | ||
exportedSymbol: schemaConfigConst, | ||
isType: false, | ||
}, | ||
}; | ||
@@ -899,2 +942,2 @@ } | ||
export { Code, FILE_PER_TYPE, File, SINGLE_FILE, amfAPIService, asAPIService, code, fileService, isImportableReference, operationCommandService, typeDeclarationService, typeDefinitionFor, writeFiles }; | ||
export { Code, FILE_PER_TYPE, File, SINGLE_FILE, amfAPIService, asAPIService, code, fileService, isImportableReference, jsonSchemaFor, operationCommandService, typeDeclarationService, typeDefinitionFor, writeFiles }; |
@@ -13,2 +13,3 @@ import type { Service, TypeOf } from '@luvio/utils'; | ||
commandClass: ImportableReference; | ||
commandSchemaConfigConst: ImportableReference; | ||
}; | ||
@@ -15,0 +16,0 @@ export type OperationCommandService = Service<OperationCommandServiceInfo.NAME, { |
@@ -0,2 +1,3 @@ | ||
export * from './json-schema'; | ||
export * from './type-declarations'; | ||
export * from './type-definition'; |
{ | ||
"name": "@luvio/generator-ts", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Luvio TypeScript code generation", | ||
@@ -24,4 +24,4 @@ "repository": { | ||
"dependencies": { | ||
"@luvio/model": "^3.5.1", | ||
"@luvio/utils": "^3.5.1", | ||
"@luvio/model": "^3.5.2", | ||
"@luvio/utils": "^3.5.2", | ||
"prettier": "^2.7.1" | ||
@@ -28,0 +28,0 @@ }, |
50536
25
1312
Updated@luvio/model@^3.5.2
Updated@luvio/utils@^3.5.2