UNPKG

@microsoft.azure/autorest.incubator

Version:
59 lines 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dictionary_1 = require("../../../common/dictionary"); const import_1 = require("../../../csharp/code-dom/import"); const namespace_1 = require("../../../csharp/code-dom/namespace"); const enum_1 = require("../../../csharp/schema/enum"); const object_1 = require("../../../csharp/schema/object"); const schema_resolver_1 = require("../../../csharp/schema/schema-resolver"); const enum_2 = require("../support/enum"); const validation = require("../validations"); const model_class_1 = require("./model-class"); class ModelsNamespace extends namespace_1.Namespace { constructor(parent, schemas, state, objectInitializer) { super('Models', parent); this.schemas = schemas; this.state = state; this.resolver = new schema_resolver_1.SchemaDefinitionResolver(); this.apply(objectInitializer); if (state.project.defaultPipeline) { this.addUsing(new import_1.Import('static Microsoft.Rest.ClientRuntime.IEventListenerExtensions')); this.addUsing(new import_1.Import('static Microsoft.Rest.ClientRuntime.HttpRequestMessageExtensions')); } this.addUsing(new import_1.Import('static Microsoft.Rest.ClientRuntime.Extensions')); // special case... hook this up before we get anywhere. state.project.modelsNamespace = this; for (const { key: schemaName, value: schema } of dictionary_1.items(schemas)) { const state = this.state.path(schemaName); // verify that the model isn't in a bad state if (validation.objectWithFormat(schema, state)) { continue; } this.resolveTypeDeclaration(schema, true, state); } } resolveTypeDeclaration(schema, required, state) { if (!schema) { throw new Error('SCHEMA MISSING?'); } const td = this.resolver.resolveTypeDeclaration(schema, required, state); if (td instanceof object_1.ObjectImplementation) { // it's a class object. // create it if necessary const mc = schema.details.csharp.classImplementation || new model_class_1.ModelClass(this, td, this.state); // this gets implicity created during class creation: return schema.details.csharp.interfaceImplementation; } if (td instanceof enum_1.EnumImplementation) { const ec = state.project.supportNamespace.findClassByName(schema.extensions['x-ms-enum'].name); if (ec.length > 0) { return schema.details.csharp.typeDeclaration = ec[0]; } return schema.details.csharp.typeDeclaration = new enum_2.EnumClass(td, state); } return td; } } ModelsNamespace.INVALID = null; exports.ModelsNamespace = ModelsNamespace; //# sourceMappingURL=namespace.js.map