Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@frui.ts/generator

Package Overview
Dependencies
Maintainers
5
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frui.ts/generator - npm Package Compare versions

Comparing version 0.15.0-rc.1 to 0.15.0-rc.2

17

dist/openapi/modelProcessor.js

@@ -44,2 +44,3 @@ "use strict";

var progressBar_1 = require("../progressBar");
var apiModel_1 = __importDefault(require("./models/apiModel"));
var helpers_1 = require("./parsers/helpers");

@@ -73,11 +74,13 @@ var openApi2Parser_1 = __importDefault(require("./parsers/openApi2Parser"));

if (helpers_1.isOpenAPIv2(api)) {
return new openApi2Parser_1.default().parse(api);
var parser = new openApi2Parser_1.default();
parser.parse(api);
return new apiModel_1.default(parser.entities, parser.enums);
}
else if (helpers_1.isOpenAPIv3(api)) {
return new openApi3Parser_1.default().parse(api);
if (helpers_1.isOpenAPIv3(api)) {
var parser = new openApi3Parser_1.default();
parser.parse(api);
return new apiModel_1.default(parser.entities, parser.enums);
}
else {
console.error("Unknown api format", api);
throw new Error("Unknown api format");
}
console.error("Unknown api format", api);
throw new Error("Unknown api format");
};

@@ -84,0 +87,0 @@ return ModelProcessor;

import { OpenAPIV2 } from "openapi-types";
import ApiModel from "../models/apiModel";
import Entity from "../models/entity";
import Enum from "../models/enum";
import TypeDefinition from "../models/typeDefinition";
export default class OpenApi2Parser {
parse(api: OpenAPIV2.Document): ApiModel;
entities: Entity[];
enums: Enum[];
parse(api: OpenAPIV2.Document): void;
private parseEntity;
private parseObjectEntity;
private parseEntityProperty;
parseType(definition: OpenAPIV2.SchemaObject | OpenAPIV2.ItemsObject): TypeDefinition;
parseType(fallbackName: string, definition: OpenAPIV2.SchemaObject | OpenAPIV2.ItemsObject): TypeDefinition;
}

@@ -29,6 +29,2 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -39,3 +35,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

var util_1 = require("util");
var apiModel_1 = __importDefault(require("../models/apiModel"));
var helpers_1 = require("../../helpers");
var entityProperty_1 = __importDefault(require("../models/entityProperty"));

@@ -48,7 +44,7 @@ var enum_1 = __importDefault(require("../models/enum"));

function OpenApi2Parser() {
this.entities = [];
this.enums = [];
}
OpenApi2Parser.prototype.parse = function (api) {
var e_1, _a;
var entities = [];
var enums = [];
if (api.definitions) {

@@ -58,19 +54,3 @@ try {

var _d = __read(_c.value, 2), name_1 = _d[0], definition = _d[1];
var entity = this.parseEntity(name_1, definition);
if (!entity) {
continue;
}
if (entity instanceof enum_1.default) {
enums.push(entity);
}
else if (entity instanceof objectEntity_1.default) {
var embeddedEnums = entity.properties
.filter(function (x) { return x.type.enumValues; })
.map(function (x) { return new enum_1.default(x.type.name, x.type.enumValues); });
enums.push.apply(enums, __spread(embeddedEnums));
entities.push(entity);
}
else if (entities instanceof typeEntity_1.default) {
entities.push(entity);
}
this.parseEntity(name_1, definition);
}

@@ -86,14 +66,13 @@ }

}
return new apiModel_1.default(entities, enums);
};
OpenApi2Parser.prototype.parseEntity = function (name, definition) {
if (definition.enum) {
new enum_1.default(name, definition.enum);
this.enums.push(new enum_1.default(name, definition.enum));
}
else if (definition.properties) {
return this.parseObjectEntity(name, definition);
this.parseObjectEntity(name, definition);
}
else {
var type = this.parseType(definition);
return new typeEntity_1.default(name, type);
var type = this.parseType(name, definition);
this.entities.push(new typeEntity_1.default(name, type));
}

@@ -105,3 +84,3 @@ };

if (!definition.properties) {
return undefined;
return;
}

@@ -111,10 +90,12 @@ var properties = Object.entries(definition.properties).map(function (x) { return _this.parseEntityProperty(name, x[0], x[1]); });

(_a = definition.required) === null || _a === void 0 ? void 0 : _a.forEach(function (property) { return entity.addPropertyRestriction(property, restriction_1.default.required, true); });
return entity;
this.entities.push(entity);
};
OpenApi2Parser.prototype.parseEntityProperty = function (entityName, name, definition) {
var type = this.parseType(definition);
OpenApi2Parser.prototype.parseEntityProperty = function (entityName, propertyName, definition) {
var fallbackTypeName = entityName + helpers_1.pascalCase(propertyName);
var type = this.parseType(fallbackTypeName, definition);
if (type.enumValues) {
type.name = name;
type.name = fallbackTypeName;
this.enums.push(new enum_1.default(type.name, type.enumValues));
}
var property = new entityProperty_1.default(name, type);
var property = new entityProperty_1.default(propertyName, type);
property.description = definition.description;

@@ -133,3 +114,3 @@ property.example = definition.example;

};
OpenApi2Parser.prototype.parseType = function (definition) {
OpenApi2Parser.prototype.parseType = function (fallbackName, definition) {
if (definition.$ref) {

@@ -143,6 +124,14 @@ return {

if (typeName === "array" && definition.items) {
var type = this.parseType(definition.items);
var type = this.parseType(fallbackName + "Item", definition.items);
type.isArray = true;
return type;
}
if (typeName === "object") {
var entityName = helpers_1.pascalCase(fallbackName);
this.parseObjectEntity(entityName, definition);
return {
name: entityName,
isEntity: true,
};
}
if (typeName === "string" && definition.enum) {

@@ -149,0 +138,0 @@ return {

import { OpenAPIV3 } from "openapi-types";
import ApiModel from "../models/apiModel";
import Entity from "../models/entity";
import Enum from "../models/enum";
import TypeDefinition from "../models/typeDefinition";
export default class OpenApi3Parser {
parse(api: OpenAPIV3.Document): ApiModel;
entities: Entity[];
enums: Enum[];
parse(api: OpenAPIV3.Document): void;
private parseEntity;
private parseObjectEntity;
private parseEntityProperty;
parseType(definition: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject): TypeDefinition;
parseType(fallbackName: string, definition: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject): TypeDefinition;
}

@@ -37,3 +37,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var apiModel_1 = __importDefault(require("../models/apiModel"));
var helpers_1 = require("../../helpers");
var entityProperty_1 = __importDefault(require("../models/entityProperty"));

@@ -44,5 +44,7 @@ var enum_1 = __importDefault(require("../models/enum"));

var typeEntity_1 = __importDefault(require("../models/typeEntity"));
var helpers_1 = require("./helpers");
var helpers_2 = require("./helpers");
var OpenApi3Parser = (function () {
function OpenApi3Parser() {
this.entities = [];
this.enums = [];
}

@@ -52,4 +54,2 @@ OpenApi3Parser.prototype.parse = function (api) {

var _b;
var entities = [];
var enums = [];
if ((_b = api.components) === null || _b === void 0 ? void 0 : _b.schemas) {

@@ -59,22 +59,6 @@ try {

var _e = __read(_d.value, 2), name_1 = _e[0], definition = _e[1];
if (helpers_1.isReferenceObject(definition)) {
if (helpers_2.isReferenceObject(definition)) {
continue;
}
var entity = this.parseEntity(name_1, definition);
if (!entity) {
continue;
}
if (entity instanceof enum_1.default) {
enums.push(entity);
}
else if (entity instanceof objectEntity_1.default) {
var embeddedEnums = entity.properties
.filter(function (x) { return x.type.enumValues; })
.map(function (x) { return new enum_1.default(x.type.name, x.type.enumValues); });
enums.push.apply(enums, __spread(embeddedEnums));
entities.push(entity);
}
else if (entity instanceof typeEntity_1.default) {
entities.push(entity);
}
this.parseEntity(name_1, definition);
}

@@ -90,14 +74,13 @@ }

}
return new apiModel_1.default(entities, enums);
};
OpenApi3Parser.prototype.parseEntity = function (name, definition) {
if (definition.enum) {
new enum_1.default(name, definition.enum);
this.enums.push(new enum_1.default(name, definition.enum));
}
else if (definition.type === "object") {
return this.parseObjectEntity(name, definition);
this.parseObjectEntity(name, definition);
}
else {
var type = this.parseType(definition);
return new typeEntity_1.default(name, type);
var type = this.parseType(name, definition);
this.entities.push(new typeEntity_1.default(name, type));
}

@@ -109,3 +92,3 @@ };

if (!definition.properties) {
return undefined;
return;
}

@@ -115,11 +98,13 @@ var properties = Object.entries(definition.properties).map(function (x) { return _this.parseEntityProperty(name, x[0], x[1]); });

(_a = definition.required) === null || _a === void 0 ? void 0 : _a.forEach(function (property) { return entity.addPropertyRestriction(property, restriction_1.default.required, true); });
return entity;
this.entities.push(entity);
};
OpenApi3Parser.prototype.parseEntityProperty = function (entityName, name, definition) {
var type = this.parseType(definition);
OpenApi3Parser.prototype.parseEntityProperty = function (entityName, propertyName, definition) {
var fallbackTypeName = entityName + helpers_1.pascalCase(propertyName);
var type = this.parseType(fallbackTypeName, definition);
if (type.enumValues) {
type.name = name;
type.name = fallbackTypeName;
this.enums.push(new enum_1.default(type.name, type.enumValues));
}
var property = new entityProperty_1.default(name, type);
if (helpers_1.isSchemaObject(definition)) {
var property = new entityProperty_1.default(propertyName, type);
if (helpers_2.isSchemaObject(definition)) {
property.description = definition.description;

@@ -139,5 +124,5 @@ property.example = definition.example;

};
OpenApi3Parser.prototype.parseType = function (definition) {
OpenApi3Parser.prototype.parseType = function (fallbackName, definition) {
var _this = this;
if (helpers_1.isReferenceObject(definition)) {
if (helpers_2.isReferenceObject(definition)) {
return {

@@ -149,7 +134,15 @@ name: getReferencedEntityName(definition.$ref),

var typeName = definition.type;
if (helpers_1.isArraySchemaObject(definition)) {
var type = this.parseType(definition.items);
if (helpers_2.isArraySchemaObject(definition)) {
var type = this.parseType(fallbackName + "Item", definition.items);
type.isArray = true;
return type;
}
if (typeName === "object") {
var entityName = helpers_1.pascalCase(fallbackName);
this.parseObjectEntity(entityName, definition);
return {
name: entityName,
isEntity: true,
};
}
if (typeName === "string" && definition.enum) {

@@ -170,6 +163,6 @@ return {

var composed = Object.assign.apply(Object, __spread([{}], definition.allOf));
return this.parseType(composed);
return this.parseType(fallbackName, composed);
}
if (definition.oneOf) {
var innerTypes = definition.oneOf.map(function (x) { return _this.parseType(x); });
var innerTypes = definition.oneOf.map(function (x, i) { return _this.parseType(fallbackName + i, x); });
if (innerTypes.length === 1) {

@@ -176,0 +169,0 @@ return innerTypes[0];

@@ -6,3 +6,3 @@ {

},
"version": "0.15.0-rc.1",
"version": "0.15.0-rc.2",
"description": "Frui.ts code generator",

@@ -56,3 +56,3 @@ "keywords": [

},
"gitHead": "94f63f6550f4893c2bbf0ca038560fb2f4b6f2aa"
"gitHead": "c9efd19043d893e3d6d72f90f7429f778c02df22"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc