Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Openapi to Typespec] Detect Arm and Fix unsupported char type #4989

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("") && input.includes("resource-manager")) {
joheredi marked this conversation as resolved.
Show resolved Hide resolved
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
Loading