Skip to content

Commit

Permalink
[Openapi to Typespec] Detect Arm and Fix unsupported char type (#4989)
Browse files Browse the repository at this point in the history
* Currently SchemaType.Char is unsupported, mapping it to string to fix
the problem
* Automatically detect when a swagger is ARM
Fixes #4991
  • Loading branch information
joheredi authored Jul 12, 2024
1 parent fa08f8c commit d665678
Show file tree
Hide file tree
Showing 11 changed files with 8,299 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Support char type from swagger and Automatically detect ARM specs",
"type": "minor"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
17 changes: 15 additions & 2 deletions packages/extensions/openapi-to-typespec/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ export function getGuessResourceKey(session: Session<CodeModel>) {
}

export function getIsArm(session: Session<CodeModel>) {
const isArm = session.configuration["isArm"] ?? false;
return isArm !== false;
if (session.configuration["isArm"] !== undefined) {
// If isArm is explicitly set, use it.
return Boolean(session.configuration["isArm"]);
}

const inputs = session.configuration["inputFileUris"] as string[];

for (const input of inputs) {
if (input.includes("resource-manager")) {
return true;
}
}

// by default is isArm is not explicitly set, we assume it is DataPlane.
return false;
}

export function getIsAzureSpec(session: Session<CodeModel>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const typespecTypes = new Map<string, string>([
[SchemaType.DateTime, "utcDateTime"],
[SchemaType.UnixTime, "plainTime"],
[SchemaType.String, "string"],
[SchemaType.Char, "string"],
[SchemaType.Time, "plainTime"],
[SchemaType.Uuid, "string"],
[SchemaType.Uri, "url"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ title: "Azure Compute resource management API."
clear-output-folder: false
guessResourceKey: false
isAzureSpec: true
isArm: true
namespace: "Microsoft.Compute"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ title: "Azure Sphere resource management API."
clear-output-folder: false
guessResourceKey: false
isAzureSpec: true
isArm: true
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ clear-output-folder: false
namespace: "Azure.Keyvault"
tag: package-preview-7.4-preview.1
guessResourceKey: false
isArm: false
```
10 changes: 10 additions & 0 deletions packages/extensions/openapi-to-typespec/test/search/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```yaml
library-name: Search
namespace: Azure.Search
isAzureSpec: true
require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/search/data-plane/Azure.Search/readme.md
#tag: package-preview-2023-06
modelerfour:
flatten-payloads: false
deserialize-null-collection-as-null-value: true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* PLEASE DO NOT REMOVE - USED FOR CONVERTER METRICS
* Generated by package: @autorest/openapi-to-typespec
* Version: Not generated in test
* Date: Not generated in test
*/
import "@typespec/rest";
import "@typespec/http";
import "./routes.tsp";

using TypeSpec.Rest;
using TypeSpec.Http;
using TypeSpec.Versioning;
/**
* Client that can be used to manage and query indexes and documents, as well as
* manage other resources, on a search service.
*/
@service({
title: "SearchClient",
})
@versioned(Versions)
@server(
"{endpoint}",
"Client that can be used to manage and query indexes and documents, as well as manage other resources, on a search service.",
{
/**
* The name of the index.
*/
indexName: string,

endpoint: string,
}
)
namespace Azure.Search;

/**
* The available API versions.
*/
enum Versions {
/**
* The 2024-07-01 API version.
*/
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2024_07_01: "2024-07-01",
}
Loading

0 comments on commit d665678

Please sign in to comment.