зеркало из https://github.com/Azure/autorest.git
Feature: Support string format for server variables (#3952)
This commit is contained in:
Родитель
b9770b81f0
Коммит
e61eee0c3b
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"packageName": "@autorest/modelerfour",
|
||||||
|
"comment": "Allow server variables to provide a string format(url, uri, etc.)",
|
||||||
|
"type": "patch"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packageName": "@autorest/modelerfour",
|
||||||
|
"email": "tiguerin@microsoft.com"
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"packageName": "@azure-tools/oai2-to-oai3",
|
||||||
|
"comment": "When converting x-ms-parameterized-host parameters to server variables keep format as x-format",
|
||||||
|
"type": "patch"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packageName": "@azure-tools/oai2-to-oai3",
|
||||||
|
"email": "tiguerin@microsoft.com"
|
||||||
|
}
|
|
@ -1657,13 +1657,7 @@ export class ModelerFour {
|
||||||
// scenario 3 : single parameterized value
|
// scenario 3 : single parameterized value
|
||||||
|
|
||||||
for (const { key: variableName, value: variable } of items(server.variables).where((each) => !!each.key)) {
|
for (const { key: variableName, value: variable } of items(server.variables).where((each) => !!each.key)) {
|
||||||
const sch = variable.enum
|
const sch = this.getServerVariableSchema(variableName, variable);
|
||||||
? this.processChoiceSchema(variableName, <OpenAPI.Schema>{
|
|
||||||
type: "string",
|
|
||||||
enum: variable.enum,
|
|
||||||
description: variable.description || `${variableName} - server parameter`,
|
|
||||||
})
|
|
||||||
: this.stringSchema;
|
|
||||||
|
|
||||||
const clientdefault = variable.default ? variable.default : undefined;
|
const clientdefault = variable.default ? variable.default : undefined;
|
||||||
|
|
||||||
|
@ -1768,6 +1762,23 @@ export class ModelerFour {
|
||||||
return baseUri;
|
return baseUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getServerVariableSchema(variableName: string, variable: OpenAPI.ServerVariable) {
|
||||||
|
if (variable.enum) {
|
||||||
|
return this.processChoiceSchema(variableName, <OpenAPI.Schema>{
|
||||||
|
type: "string",
|
||||||
|
enum: variable.enum,
|
||||||
|
description: variable.description || `${variableName} - server parameter`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable["x-format"]) {
|
||||||
|
return this.processSchema(`${variableName}`, {
|
||||||
|
type: JsonType.String,
|
||||||
|
format: variable["x-format"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.stringSchema;
|
||||||
|
}
|
||||||
processApiVersionParameterForProfile() {
|
processApiVersionParameterForProfile() {
|
||||||
throw new Error("Profile Support for API Verison Parameters not implemented.");
|
throw new Error("Profile Support for API Verison Parameters not implemented.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ export class Oai2ToOai3 {
|
||||||
case "in":
|
case "in":
|
||||||
case "required":
|
case "required":
|
||||||
case "type":
|
case "type":
|
||||||
|
case "format":
|
||||||
case "name":
|
case "name":
|
||||||
// turn these into x-* properties
|
// turn these into x-* properties
|
||||||
param[`x-${key}`] = originalParameter[key];
|
param[`x-${key}`] = originalParameter[key];
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
{
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "{UriParam}{EnumParam}{StringParam}",
|
||||||
|
"variables": {
|
||||||
|
"StringParam": {
|
||||||
|
"x-name": "StringParam",
|
||||||
|
"x-in": "path",
|
||||||
|
"description": "Parameter that is a generic string",
|
||||||
|
"x-required": true,
|
||||||
|
"x-type": "string",
|
||||||
|
"default": "https://api.cognitive.microsoft.com",
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"x-ms-original": {
|
||||||
|
"$ref": "#/components/parameters/StringParam"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UrlParam": {
|
||||||
|
"x-name": "UrlParam",
|
||||||
|
"x-in": "path",
|
||||||
|
"description": "Parameter that is formatted as url",
|
||||||
|
"x-required": true,
|
||||||
|
"x-type": "string",
|
||||||
|
"default": "https://api.cognitive.microsoft.com",
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"x-ms-original": {
|
||||||
|
"$ref": "#/components/parameters/UrlParam"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"EnumParam": {
|
||||||
|
"x-name": "EnumParam",
|
||||||
|
"x-in": "path",
|
||||||
|
"description": "Shared endpoint param.",
|
||||||
|
"x-required": true,
|
||||||
|
"x-type": "string",
|
||||||
|
"enum": [
|
||||||
|
"v1",
|
||||||
|
"v2"
|
||||||
|
],
|
||||||
|
"default": "v1",
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"x-ms-original": {
|
||||||
|
"$ref": "#/components/parameters/EnumParam"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"$schema": "https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json",
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"x-ms-metadata": {
|
||||||
|
"apiVersions": [
|
||||||
|
"test-0.1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"title": "Test",
|
||||||
|
"description": "test",
|
||||||
|
"version": "test-0.1"
|
||||||
|
},
|
||||||
|
"paths": {},
|
||||||
|
"components": {
|
||||||
|
"parameters": {
|
||||||
|
"StringParam": {
|
||||||
|
"name": "StringParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Parameter that is a generic string",
|
||||||
|
"required": true,
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"schema": {
|
||||||
|
"default": "https://api.cognitive.microsoft.com",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"UrlParam": {
|
||||||
|
"name": "UrlParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Parameter that is formatted as url",
|
||||||
|
"required": true,
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"schema": {
|
||||||
|
"default": "https://api.cognitive.microsoft.com",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"EnumParam": {
|
||||||
|
"name": "EnumParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Shared endpoint param.",
|
||||||
|
"required": true,
|
||||||
|
"x-ms-parameter-location": "client",
|
||||||
|
"schema": {
|
||||||
|
"enum": [
|
||||||
|
"v1",
|
||||||
|
"v2"
|
||||||
|
],
|
||||||
|
"default": "v1",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json",
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"x-ms-metadata": {
|
||||||
|
"apiVersions": ["test-0.1"]
|
||||||
|
},
|
||||||
|
"title": "Test",
|
||||||
|
"description": "test",
|
||||||
|
"version": "test-0.1"
|
||||||
|
},
|
||||||
|
"x-ms-parameterized-host": {
|
||||||
|
"hostTemplate": "{UriParam}{EnumParam}{StringParam}",
|
||||||
|
"useSchemePrefix": false,
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"$ref": "#/parameters/StringParam"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "#/parameters/UrlParam"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "#/parameters/EnumParam"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"paths": {},
|
||||||
|
"definitions": {},
|
||||||
|
"parameters": {
|
||||||
|
"StringParam": {
|
||||||
|
"name": "StringParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Parameter that is a generic string",
|
||||||
|
"required": true,
|
||||||
|
"type": "string",
|
||||||
|
"default": "https://api.cognitive.microsoft.com"
|
||||||
|
},
|
||||||
|
"UrlParam": {
|
||||||
|
"name": "UrlParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Parameter that is formatted as url",
|
||||||
|
"required": true,
|
||||||
|
"type": "string",
|
||||||
|
"default": "https://api.cognitive.microsoft.com"
|
||||||
|
},
|
||||||
|
"EnumParam": {
|
||||||
|
"name": "EnumParam",
|
||||||
|
"in": "path",
|
||||||
|
"description": "Shared endpoint param.",
|
||||||
|
"required": true,
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["v1", "v2"],
|
||||||
|
"default": "v1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,4 +49,9 @@ describe("Scenario testings", () => {
|
||||||
// The expected result is the parmaeter to be included/expanded in the OpenAPI3 server property.
|
// The expected result is the parmaeter to be included/expanded in the OpenAPI3 server property.
|
||||||
await expectInputsMatchSnapshots("cross-file-parameterized-host-refs", ["swagger.json", "other.json"]);
|
await expectInputsMatchSnapshots("cross-file-parameterized-host-refs", ["swagger.json", "other.json"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Convert parameterized host parameters to server variables", async () => {
|
||||||
|
// The expected result is the parmaeter to be included/expanded in the OpenAPI3 server property.
|
||||||
|
await expectInputsMatchSnapshots("parameterized-host-parameters", ["swagger.json"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче