@autorest/openapi-to-typespec
Version:
Autorest plugin to scaffold a Typespec definition from an OpenAPI document
86 lines • 3.44 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvelopeAugmentedDecorator = exports.getEnvelopeProperty = void 0;
const library_type_mapping_1 = require("./library-type-mapping");
const knownEnvelopes = {
sku: {
serializedName: "sku",
required: false,
isReadOnly: false,
schema: library_type_mapping_1.skuLibraryType,
envelopeName: "Azure.ResourceManager.ResourceSkuProperty",
},
plan: {
serializedName: "plan",
required: false,
isReadOnly: false,
schema: library_type_mapping_1.planLibraryType,
envelopeName: "Azure.ResourceManager.ResourcePlanProperty",
},
extendedLocation: {
serializedName: "extendedLocation",
required: false,
isReadOnly: true,
schema: library_type_mapping_1.extendedLocationLibraryType,
envelopeName: "Azure.ResourceManager.ExtendedLocationProperty",
},
zones: {
serializedName: "zones",
required: false,
isReadOnly: false,
schema: {
name: "_",
type: "array",
elementType: () => ({ name: "string", type: "primitive", schema: (schema) => schema.type === "string" }),
},
envelopeName: "Azure.ResourceManager.AvailabilityZonesProperty",
},
identity: {
serializedName: "identity",
required: false,
isReadOnly: false,
schema: library_type_mapping_1.managedServiceIdentityLibraryType,
envelopeName: "Azure.ResourceManager.ManagedServiceIdentityProperty",
},
eTag: {
serializedName: "eTag",
required: false,
isReadOnly: true,
schema: { name: "string", type: "primitive", schema: (schema) => schema.type === "string" },
envelopeName: "Azure.ResourceManager.EntityTagProperty",
},
};
function getEnvelopeProperty(property) {
var _a, _b;
for (const key of Object.keys(knownEnvelopes)) {
const envelope = knownEnvelopes[key];
if (property.serializedName.toLowerCase() === envelope.serializedName.toLowerCase() &&
((_a = property.required) !== null && _a !== void 0 ? _a : false) === envelope.required &&
((_b = property.readOnly) !== null && _b !== void 0 ? _b : false) === envelope.isReadOnly &&
(0, library_type_mapping_1.isEquivalent)(property.schema, envelope.schema)) {
return {
kind: "spread",
model: {
kind: "template",
name: envelope.envelopeName,
},
};
}
}
}
exports.getEnvelopeProperty = getEnvelopeProperty;
function getEnvelopeAugmentedDecorator(schema, property) {
for (const key of Object.keys(knownEnvelopes)) {
const envelope = knownEnvelopes[key];
if (property.serializedName.toLowerCase() === envelope.serializedName.toLowerCase() &&
property.serializedName !== envelope.serializedName) {
return {
name: "encodedName",
target: `${schema.resourceMetadata[0].SwaggerModelName}.${envelope.serializedName}`,
arguments: ["application/json", property.serializedName], // Currently we only support application/json
};
}
}
}
exports.getEnvelopeAugmentedDecorator = getEnvelopeAugmentedDecorator;
//# sourceMappingURL=envelope-property.js.map
;