UNPKG

@microsoft.azure/autorest.incubator

Version:
677 lines (673 loc) 38.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const components_1 = require("../common/code-model/components"); const http_operation_1 = require("../common/code-model/http-operation"); const schema_1 = require("../common/code-model/schema"); const dictionary_1 = require("../common/dictionary"); const media_types_1 = require("../common/media-types"); const mscorlib_1 = require("../csharp/code-dom/mscorlib"); const code_model_1 = require("../common/code-model/code-model"); const common_1 = require("./common"); const Interpretations = require("./interpretations"); const known_format_1 = require("./known-format"); const OpenAPI = require("./oai3"); const todo_unimplemented = undefined; class Remodeler { constructor(modelState) { this.modelState = modelState; this.copySchema = (name, original, targetDictionary) => { // normalize/warn about incorrect usage of binary/stream combinations // OAI (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types) // indicates that format: string, type: binary is "any sequence of octets" (ie, the body should be treated as a stream of bytes) // extant autorest has been using format: object, type: file -- which is not standard OAI. // there has also been use of type: file -- which is not even remotely standard JSON Schema if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } let type = original.type; let format = original.format; if (type === 'file') { type = OpenAPI.JsonType.String; format = known_format_1.StringFormat.Binary; this.modelState.warning(`The schema type 'file' is not a OAI standard type. This has been auto-corrected to 'type:string' and 'format:binary'`, [`TypeFileNotValid`]); } if (type === schema_1.JsonType.Object && format === 'file') { type = OpenAPI.JsonType.String; format = known_format_1.StringFormat.Binary; this.modelState.warning(`The schema type 'object' with format 'file' is not a standard OAI representation. This has been auto-corrected to 'type:string' and 'format:binary'`, [`TypeObjectFormatFileNotValid`]); } if (type === undefined && original.properties) { // they have a properties, but didn't say type: object. type = OpenAPI.JsonType.Object; this.modelState.warning(`The schema '${name}' with an undefined type and decalared properties is a bit ambigious. This has been auto-corrected to 'type:object'`, [`UndefinedTypeWithSchema`]); } if (type === undefined && original.allOf) { type = OpenAPI.JsonType.Object; this.modelState.warning(`The schema '${name}' with a undefined type and using allOf is a bit ambigious. This has been auto-corrected to 'type:object'`, [`UndefinedTypeWithSchema`]); } const newSchema = new schema_1.Schema(name, { extensions: common_1.getExtensionProperties(original), type, format, title: original.title, description: original.description, nullable: original.nullable || false, readOnly: original.readOnly || false, writeOnly: original.writeOnly || false, deprecated: original.deprecated || false, required: original.required || [], // unbounded properties default: original.default, example: original.example, }); this.addOrThrow(targetDictionary, name, newSchema); switch (type) { case schema_1.JsonType.Integer: case schema_1.JsonType.Number: this.copySchemaIntegerOrNumber(original, newSchema); break; case schema_1.JsonType.Object: this.copySchemaObject(name, original, newSchema); break; case schema_1.JsonType.Array: this.copySchemaArray(name, original, newSchema); break; case schema_1.JsonType.String: this.copySchemaString(original, newSchema); break; case undefined: this.copySchemaIntegerOrNumber(original, newSchema); this.copySchemaObject(name, original, newSchema); this.copySchemaArray(name, original, newSchema); this.copySchemaString(original, newSchema); break; case schema_1.JsonType.Boolean: break; default: throw new Error(`Invalid type '${type}' in schema`); } // copy the enum list across if it's specified if (original.enum) { newSchema.enum = [...original.enum]; } newSchema.details.default.enum = Interpretations.getEnumDefinition(original); // object properties // discriminator if (original.discriminator && original.discriminator.propertyName) { newSchema.discriminator = new schema_1.Discriminator(original.discriminator.propertyName, { extensions: common_1.getExtensionProperties(original.discriminator), mapping: original.discriminator.mapping }); } // externalDocs newSchema.externalDocs = Interpretations.getExternalDocs(original.externalDocs); // XML if (original.xml) { newSchema.xml = new schema_1.XML({ extensions: common_1.getExtensionProperties(original.xml), attribute: original.xml.attribute, namespace: original.xml.namespace, name: original.xml.name, prefix: original.xml.prefix, wrapped: original.xml.wrapped, }); } if (original.not) { // ensure that the original schema is copied over already. newSchema.not = this.refOrAdd(`.${name}.not`, this.dereference(original.not), this.model.schemas, this.copySchema); } if (original.allOf) { for (let index = 0; index < original.allOf.length; index++) { newSchema.allOf.push(this.refOrAdd(`.${name}.allOf.${index}`, this.dereference(original.allOf[index]), this.model.schemas, this.copySchema)); } } if (original.anyOf) { for (let index = 0; index < original.anyOf.length; index++) { newSchema.allOf.push(this.refOrAdd(`.${name}.anyOf.${index}`, this.dereference(original.anyOf[index]), this.model.schemas, this.copySchema)); } } if (original.oneOf) { for (let index = 0; index < original.oneOf.length; index++) { newSchema.allOf.push(this.refOrAdd(`.${name}.oneOf.${index}`, this.dereference(original.oneOf[index]), this.model.schemas, this.copySchema)); } } if (original.additionalProperties !== undefined) { if (original.additionalProperties === true || original.additionalProperties === false) { newSchema.additionalProperties = original.additionalProperties; } else { newSchema.additionalProperties = this.refOrAdd(`${name}.additionalItemType`, this.dereference(original.additionalProperties), this.model.schemas, this.copySchema); } } if (original.properties) { for (const { key: propertyName, value: property } of dictionary_1.items(original.properties)) { const propertySchema = this.dereference(property); const newPropSchema = this.refOrAdd(`${name[0] == '.' ? name : '.' + name}.${propertyName}`, propertySchema, this.model.schemas, this.copySchema); newSchema.properties[propertyName] = new schema_1.Property(propertyName, { description: Interpretations.getDescription(Interpretations.getDescription('', newPropSchema), property), schema: newPropSchema, details: { default: { deprecationMessage: Interpretations.getDeprecationMessage(original), description: Interpretations.getDescription(Interpretations.getDescription('', newPropSchema), property), name: Interpretations.getName(propertyName, propertySchema.instance), required: original.required ? original.required.indexOf(propertyName) > -1 : false, } } }); } } return newSchema; }; this.copyOperation = (name, original, targetDictionary) => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const query = original.path.indexOf('?'); if (query > -1) { original.path = original.path.substring(0, query); } const newOperation = new http_operation_1.HttpOperation(name, original.path, original.method, { pathDescription: original.pathItem.description, pathSummary: original.pathItem.summary, pathExtensions: common_1.getExtensionProperties(original.pathItem), deprecated: original.operation.deprecated || false, description: Interpretations.getDescription(original.pathItem.description || '', original.operation), extensions: common_1.getExtensionProperties(original.operation), operationId: name, path: original.path, servers: Interpretations.getServers(original.operation.servers, original.pathItem.servers, this.oai.servers), externalDocs: Interpretations.getExternalDocs(original.operation.externalDocs), tags: original.operation.tags ? [...original.operation.tags] : [], summary: original.operation.summary, requestBody: original.operation.requestBody ? this.refOrAdd(`.${name}.requestBody`, this.dereference(original.operation.requestBody), this.model.http.requestBodies, this.copyRequestBody) : undefined, callbacks: todo_unimplemented, security: todo_unimplemented }); this.addOrThrow(targetDictionary, name, newOperation); if (original.operation.parameters) { for (const parameterName of original.operation.parameters) { const p = this.dereference(parameterName); newOperation.parameters.push(this.refOrAdd(`${name}.${p.instance.name}`, p, this.model.http.parameters, (n, o, t) => this.copyParameter(n, o, components_1.ImplementationLocation.Method, this.model.http.parameters))); } } if (original.pathItem.parameters) { for (const parameterName of original.pathItem.parameters) { const p = this.dereference(parameterName); newOperation.parameters.push(this.refOrAdd(`${name}.${p.instance.name}`, p, this.model.http.parameters, (n, o, t) => this.copyParameter(n, o, components_1.ImplementationLocation.Method, this.model.http.parameters))); } } // flatten response options into usable graph for (const { key: responseCode, value: ref } of dictionary_1.items(original.operation.responses)) { // for a given http response code, we can have a variety of responses newOperation.responses_new[responseCode] = new Array(); const originalResponse = this.dereference(ref); const responseObject = originalResponse.instance; if (!responseObject.content || dictionary_1.length(responseObject.content) === 0) { // the response doesn't have any body content expected newOperation.responses_new[responseCode].push(new http_operation_1.NewResponse(responseCode, responseObject.description, [], { extensions: common_1.getExtensionProperties(responseObject), headers: this.copyHeaders(name, responseObject.headers), headerSchema: this.createHeaderSchema(name, responseCode, responseObject.headers) })); } else { // Interpretation: // glob all the json responses and xml responses into categories. // todo: make consolodation configurable. const [jsons, more] = dictionary_1.items(responseObject.content).linq.bifurcate(each => media_types_1.isMediaTypeJson(each.key)); const [xmls, rest] = dictionary_1.values(more).linq.bifurcate(each => media_types_1.isMediaTypeXml(each.key)); if (jsons.length > 0) { const schema = jsons[0].value.schema; const mediaType = jsons[0].key; newOperation.responses_new[responseCode].push(new http_operation_1.NewResponse(responseCode, responseObject.description, jsons.map(v => v.key), { extensions: common_1.getExtensionProperties(responseObject), headers: this.copyHeaders(name, responseObject.headers), headerSchema: this.createHeaderSchema(name, responseCode, responseObject.headers), schema: schema ? this.refOrAdd(`.${name}.${responseCode}.${mediaType}`, this.dereference(schema), this.model.schemas, this.copySchema) : undefined })); } if (xmls.length > 0) { const schema = xmls[0].value.schema; const mediaType = xmls[0].key; newOperation.responses_new[responseCode].push(new http_operation_1.NewResponse(responseCode, responseObject.description, xmls.map(v => v.key), { extensions: common_1.getExtensionProperties(responseObject), headers: this.copyHeaders(name, responseObject.headers), headerSchema: this.createHeaderSchema(name, responseCode, responseObject.headers), schema: schema ? this.refOrAdd(`.${name}.${responseCode}.${mediaType}`, this.dereference(schema), this.model.schemas, this.copySchema) : undefined })); } for (const { key: mediaType, value: responseType } of rest) { const schema = responseType.schema; newOperation.responses_new[responseCode].push(new http_operation_1.NewResponse(responseCode, responseObject.description, rest.map(v => v.key), { extensions: common_1.getExtensionProperties(responseObject), headers: this.copyHeaders(name, responseObject.headers), headerSchema: this.createHeaderSchema(name, responseCode, responseObject.headers), schema: schema ? this.refOrAdd(`.${name}.${responseCode}.${mediaType}`, this.dereference(schema), this.model.schemas, this.copySchema) : undefined })); } } } /* old responses handling // move responses to global section. for (const responseCode of keys(original.operation.responses)) { newOperation.responses[responseCode] = this.refOrAdd(`.${name}.${responseCode}`, this.dereference(original.operation.responses[responseCode]), this.model.http.responses, this.copyResponse); } */ return newOperation; }; this.copyHeader = (headerName, original, targetDictionary) => { if (targetDictionary && targetDictionary[headerName]) { return targetDictionary[headerName]; } const newHeader = new http_operation_1.Header({ deprecated: original.deprecated || false, description: Interpretations.getDescription('', original), allowReserved: original.allowReserved ? true : false, explode: original.explode || false, extensions: common_1.getExtensionProperties(original), schema: OpenAPI.hasSchema(original) ? this.refOrAdd(`.Header.${headerName}`, this.dereference(original.schema), this.model.schemas, this.copySchema) : undefined, required: original.required || false, content: todo_unimplemented, allowEmptyValue: false // REALLY? this seems funny. }); this.addOrThrow(targetDictionary, headerName, newHeader); // TODO: not handled: Examples, Example, Content return newHeader; }; this.createHeaderSchema = (containerName, responseCode, original) => { if (original) { const code = (mscorlib_1.System.Net.HttpStatusCode[responseCode].value || '').replace('System.Net.HttpStatusCode', '') || responseCode; const schemaName = `${containerName} ${code} ResponseHeaders`; const newSchema = this.model.schemas[schemaName] || new schema_1.Schema(schemaName, { type: schema_1.JsonType.Object, details: { default: { isHeaderModel: true } } }); for (const each of dictionary_1.keys(original)) { const header = this.dereference(original[each]); const propertyName = Interpretations.getName(header.name || `${each}`, header.instance); const propertySchema = this.dereference(header.instance.schema); if (propertySchema.instance.enum && header.instance.schema) { if (header.instance.schema) { for (const { key, value } of dictionary_1.items(header.instance)) { if (key.startsWith('x-')) { propertySchema.instance[key] = value; } } } } const newPropSchema = this.refOrAdd(`${containerName[0] == '.' ? containerName : '.' + containerName}.${propertyName}`, propertySchema, this.model.schemas, this.copySchema); newPropSchema.extensions = common_1.getExtensionProperties(header.instance); newSchema.properties[propertyName] = new schema_1.Property(propertyName, { serializedName: header.name || `${each}`, description: Interpretations.getDescription(Interpretations.getDescription('', newPropSchema), header.instance), schema: newPropSchema, extensions: common_1.getExtensionProperties(header.instance), details: { default: { deprecationMessage: Interpretations.getDeprecationMessage(original), description: Interpretations.getDescription(Interpretations.getDescription('', newPropSchema), header.instance), name: Interpretations.getName(propertyName, propertySchema.instance), required: false, HeaderProperty: 'Header', } } }); } this.model.schemas[schemaName] = newSchema; return newSchema; } return undefined; }; this.copyHeaders = (containerName, original) => { return original ? dictionary_1.ToDictionary(Object.keys(original), (v) => this.refOrAdd(`.${containerName}.${v}`, this.dereference(original[v]), this.model.http.headers, this.copyHeader)) : new dictionary_1.Dictionary(); }; this.copyLinks = (containerName, original) => { return original ? dictionary_1.CopyDictionary(original, (v) => this.refOrAdd(`.${containerName}.${v}`, this.dereference(original[v]), this.model.http.links, this.copyLink)) : new dictionary_1.Dictionary(); }; this.copyEncoding = (encodingName, original) => { return new http_operation_1.Encoding({ contentType: original.contentType, headers: this.copyHeaders(encodingName, original.headers), style: original.style, explode: original.explode || original.style === OpenAPI.EncodingStyle.Form ? true : false, allowReserved: original.allowReserved || false }); }; this.copyMediaType = (mimeType, key, original) => { return new http_operation_1.MediaType({ schema: original.schema ? this.refOrAdd(key, this.dereference(original.schema), this.model.schemas, this.copySchema) : undefined, encoding: this.copyEncodings(original.encoding), extensions: common_1.getExtensionProperties(original), accepts: [mimeType] }); }; /* copyResponse = (name: string, original: OpenAPI.Response, targetDictionary: Dictionary<Response>): Response => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const response = new Response(original.description || '', { // content: this.copyMediaTypes(name, original), extensions: getExtensionProperties(original), headers: this.copyHeaders(name, original.headers), links: this.copyLinks(name, original.links), }); this.addOrThrow(targetDictionary, name, response); if (original.content) { for (const mediaType in original.content) { response.content[mediaType] = this.copyMediaType(mediaType, `${name}.${mediaType}`, original.content[mediaType]); } } return response; } */ this.copyRequestBody = (name, original, targetDictionary) => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } let rq = dictionary_1.items(original.content).linq.first(); if (dictionary_1.length(original.content) > 1) { // check to see if there are multiple possible content types (that aren't really just variations of themselves) const [jsons, more] = dictionary_1.items(original.content).linq.bifurcate(each => media_types_1.isMediaTypeJson(each.key)); const [xmls, rest] = dictionary_1.values(more).linq.bifurcate(each => media_types_1.isMediaTypeXml(each.key)); if (((jsons.length > 0 ? 1 : 0) + (xmls.length > 0 ? 1 : 0) + rest.length) > 1) { // there are mulitple possible request bodies here. // autorest does not currently support generating code that can target different request content types // we're going to pick one based on an aribitrary priority: // json, xml, or the first one in the list rq = jsons[0] || xmls[0] || rest[0]; this.modelState.warning(`The request body '${name}' has more than one possible content type specified (${dictionary_1.keys(original.content).linq.toArray().join()}) - using '${rq.key}'`, [`MultipleRequestTypesFound`]); } } if (rq) { const requestBody = new http_operation_1.RequestBody({ description: Interpretations.getDescription('', original), extensions: common_1.getExtensionProperties(original), required: original.required ? original.required : false, schema: rq.value.schema ? this.refOrAdd(`.BodyParameter.${name}`, this.dereference(rq.value.schema), this.model.schemas, this.copySchema) : undefined, contentType: rq.key }); this.addOrThrow(targetDictionary, name, requestBody); return requestBody; } throw new Error('RequestBody without schema?'); }; this.copyCallback = (name, original, targetDictionary) => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const callback = new http_operation_1.Callback(); this.addOrThrow(targetDictionary, name, callback); return callback; }; this.copyExample = (name, original, targetDictionary) => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const example = new components_1.Example(); this.addOrThrow(targetDictionary, name, example); return example; }; this.copyLink = (name, original, targetDictionary) => { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const link = new components_1.Link({ description: original.description, extensions: common_1.getExtensionProperties(original), operationId: original.operationId, operationRef: original.operationRef, parameters: todo_unimplemented, requestBody: todo_unimplemented, server: original.server ? Interpretations.copyServer(original.server) : undefined }); this.addOrThrow(targetDictionary, name, link); return link; }; this.model = new code_model_1.Model(this.oai.info.title, this.oai.info.version); } get oai() { return this.modelState.model; } dereference(item) { return common_1.dereference(this.oai, item); } copySchemaIntegerOrNumber(original, newSchema) { newSchema.multipleOf = original.multipleOf; newSchema.maximum = original.maximum; newSchema.exclusiveMaximum = original.exclusiveMaximum; newSchema.minimum = original.minimum; newSchema.exclusiveMinimum = original.exclusiveMinimum; } copySchemaObject(name, original, newSchema) { newSchema.maxProperties = original.maxProperties; newSchema.minProperties = original.minProperties; newSchema.details = { default: { description: Interpretations.getDescription('', original), name: Interpretations.getName(name, original), } }; } copySchemaArray(name, original, newSchema) { newSchema.maxItems = original.maxItems; newSchema.minItems = original.minItems; newSchema.uniqueItems = original.uniqueItems; if (original.items) { newSchema.items = this.refOrAdd(`${name}.itemType`, this.dereference(original.items), this.model.schemas, this.copySchema); } } copySchemaString(original, newSchema) { newSchema.maxLength = original.maxLength; newSchema.minLength = original.minLength; newSchema.pattern = original.pattern; } add(name, original, target, copyFunc) { // is this an alias to another model? if (original.name) { // Yes, ensure the target is in the new model // (the assumption being that the target is the right instance if it is there with the expected name.) if (target[original.name]) { // the target model is already added to this return it as the instance. return this.safeAdd(target, name, target[original.name]); } // otherwise, create the referenced type, and then add it again with our name, const actual = this.add(original.name, { instance: original.instance }, target, copyFunc); return this.safeAdd(target, name, actual); } // copy it over and add it to the model const newValue = copyFunc(name, original.instance, target); return newValue; // return this.safeAdd(target, name, copyFunc(name, original.instance, target)); } addOrThrow(target, name, item) { if (target) { if (target[name]) { throw new Error(`Duplicate Item! ${name}`); } // add it. target[name] = item; } return item; } safeAdd(target, name, item) { if (target[name] && target[name] !== item) { item = target[name]; return item; } // add it. target[name] = item; return item; } refOrAdd(nameIfInline, ref, dictionary, copyFunc) { if (!ref.name) { // inline definition - extract it out return this.add(nameIfInline, ref, dictionary, copyFunc); } // it's a reference, make sure it's in the model. if (dictionary[ref.name]) { return dictionary[ref.name]; } // it's a global instance that we haven't yet addded, add it and return the ref. return this.add(ref.name, ref, dictionary, copyFunc); } copyParameter(name, original, implementationLocation = components_1.ImplementationLocation.Client, targetDictionary) { if (targetDictionary && targetDictionary[name]) { return targetDictionary[name]; } const location = Interpretations.getParameterImplementationLocation(implementationLocation, original); const style = OpenAPI.isCookieParameter(original) ? http_operation_1.EncodingStyle.Form : /* Header must be Simple */ OpenAPI.isHeaderParameter(original) ? http_operation_1.EncodingStyle.Simple : /* Path must be Matrix|Label|Simple(default) */ OpenAPI.isPathParameter(original) ? (original.style === http_operation_1.EncodingStyle.Matrix || original.style === http_operation_1.EncodingStyle.Label ? original.style : http_operation_1.EncodingStyle.Simple) : /* Query must be DeepObject|PipeDelimited|SpaceDelimited|Form(default) */ (original.style === http_operation_1.EncodingStyle.DeepObject || original.style === http_operation_1.EncodingStyle.PipeDelimited || original.style === http_operation_1.EncodingStyle.SpaceDelimited ? original.style : http_operation_1.EncodingStyle.Form); // #HACK: the swagger2oai translator doesn't preserve this data. const paramSchema = this.dereference(original.schema); if (paramSchema.instance && paramSchema.instance) { for (const p of dictionary_1.items(original)) { const k = p.key.toString(); if (k.startsWith('x-')) { paramSchema.instance[k] = p.value; } } } const newParameter = new http_operation_1.HttpOperationParameter(original.name, original.in, location, { allowEmptyValue: (OpenAPI.isQueryParameter(original) && original.allowEmptyValue) || false, description: Interpretations.getDescription('', original), required: original.required || false, deprecated: original.deprecated || false, style, explode: original.explode || (style === http_operation_1.EncodingStyle.Form ? true : false), allowReserved: OpenAPI.isQueryParameter(original) && original.allowReserved ? true : false, schema: OpenAPI.hasSchema(original) ? this.refOrAdd(`.Parameter.${name}`, paramSchema, this.model.schemas, this.copySchema) : undefined, extensions: common_1.getExtensionProperties(original), }); this.addOrThrow(targetDictionary, name, newParameter); newParameter.details.default.name = Interpretations.getName(original.name, original); newParameter.details.default.deprecationMessage = Interpretations.getDeprecationMessage(original); newParameter.details.default.description = Interpretations.getDescription(``, original); // TODO: not handled: Examples, Example, Content return newParameter; } remodelParameters(source) { for (const parameterName in source) { this.refOrAdd(parameterName, this.dereference(source[parameterName]), this.model.http.parameters, (n, o, d) => this.copyParameter(n, o, components_1.ImplementationLocation.Client, this.model.http.parameters)); } } copyEncodings(original) { return original ? dictionary_1.CopyDictionary(original, (v) => this.copyEncoding(v, original[v])) : new dictionary_1.Dictionary(); } remodelPaths(source) { for (const path in source) { const pathItem = this.dereference(source[path]); if (!pathItem.name) { for (const method of [http_operation_1.HttpMethod.Delete, http_operation_1.HttpMethod.Get, http_operation_1.HttpMethod.Head, http_operation_1.HttpMethod.Options, http_operation_1.HttpMethod.Patch, http_operation_1.HttpMethod.Post, http_operation_1.HttpMethod.Put, http_operation_1.HttpMethod.Trace]) { const op = pathItem.instance[method]; if (op) { this.add(Interpretations.getOperationId(method, path, op), { instance: { method, path, operation: op, pathItem: pathItem.instance } }, this.model.http.operations, this.copyOperation); } } } } } /* // todo: unimplementd copySecurityScheme = (name: string, original: OpenAPI.SecurityScheme): SecurityScheme => { const securityScheme = todo_unimplemented; return securityScheme; } */ remodelT(source, target, copyFunc) { const result = new dictionary_1.Dictionary(); for (const name in source) { result[name] = this.refOrAdd(name, this.dereference(source[name]), target, copyFunc); } // if we need the set of references that we just added return result; } remodelTags(source) { for (const each of source) { this.model.tags.push(new components_1.Tag(each.name, { description: each.description, extensions: common_1.getExtensionProperties(each), externalDocs: Interpretations.getExternalDocs(each.externalDocs), })); } } remodelServers(source) { for (const each of source) { this.model.servers.push(Interpretations.copyServer(each)); } } remodelSecurity(source) { for (const each of source) { this.model.security.push(dictionary_1.CopyDictionary(each, index => each[index])); } } remodel() { if (this.oai.components) { if (this.oai.components.schemas) { this.remodelT(this.oai.components.schemas, this.model.schemas, this.copySchema); } if (this.oai.components.parameters) { this.remodelParameters(this.oai.components.parameters); } if (this.oai.components.headers) { this.remodelT(this.oai.components.headers, this.model.http.headers, this.copyHeader); } if (this.oai.components.requestBodies) { this.remodelT(this.oai.components.requestBodies, this.model.http.requestBodies, this.copyRequestBody); } /* REMOVE THIS -- response definitions are created for each operation. We don't share those. if (this.oai.components.responses) { this.remodelT(this.oai.components.responses, this.model.http.responses, this.copyResponse); } */ /* todo: not implemented if (this.oai.components.callbacks) { this.remodelT(this.oai.components.callbacks, this.model.components.callbacks, this.copyCallback, (i) => new Callback(i)); } */ if (this.oai.components.examples) { this.remodelT(this.oai.components.examples, this.model.http.examples, this.copyExample); } if (this.oai.components.links) { this.remodelT(this.oai.components.links, this.model.http.links, this.copyLink); } if (this.oai.components.securitySchemes) { // todo: unimplemented // this.remodelT(this.oai.components.securitySchemes, this.model.components.securitySchemes, this.copySecurityScheme); } } if (this.oai.paths) { this.remodelPaths(this.oai.paths); if (this.oai['x-ms-paths']) { this.remodelPaths(this.oai['x-ms-paths']); } } if (this.oai.security) { this.remodelSecurity(this.oai.security); } if (this.oai.servers) { this.remodelServers(this.oai.servers); } if (this.oai.tags) { this.remodelTags(this.oai.tags); } if (this.oai.externalDocs) { this.model.externalDocs = Interpretations.getExternalDocs(this.oai.externalDocs); } return this.model; } } exports.Remodeler = Remodeler; //# sourceMappingURL=remodeler.js.map