Skip to content

Commit 9320b2a

Browse files
authored
Add base OpenAI TypeSpec specification (#585)
Add base TypeSpec
1 parent 73d0c5d commit 9320b2a

File tree

105 files changed

+60828
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+60828
-32
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ artifacts
178178
# Temporary typespec folders for typespec generation
179179
TempTypeSpecFiles/
180180

181-
# Base specification files
182-
specification/base/
181+
# Azure specification files
182+
specification/base/entrypoints/azure.v1
183+
specification/base/entrypoints/sdk.dotnet.azure
184+
specification/base/typespec.azure
185+
specification/base/typespec.azure.v1
183186

184187
# Generator default TypeSpec output
185188
codegen/tsp-output/

scripts/Invoke-CodeGen.ps1

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[CmdletBinding(DefaultParameterSetName = 'GitHub')]
1+
[CmdletBinding(DefaultParameterSetName = 'Default')]
22
param(
33
[Parameter(Mandatory = $true, ParameterSetName = 'GitHub')]
44
[string]$GitHubOwner,
@@ -214,42 +214,54 @@ $codegenFolderPath = Join-Path $repoRootPath "codegen"
214214

215215
$scriptStartTime = Get-Date
216216

217-
$shouldDownload = $true
218-
if (Test-Path $baseSpecificationFolderPath) {
219-
Write-Host "Base specification already exists at: $baseSpecificationFolderPath"
217+
if ($PSCmdlet.ParameterSetName -eq 'Default') {
218+
if (-not (Test-Path $baseSpecificationFolderPath)) {
219+
Write-Error "Base specification path does not exist: $baseSpecificationFolderPath"
220+
throw "Default specification path not found"
221+
}
222+
223+
Write-Host "Using existing base specification at: $baseSpecificationFolderPath"
220224
Write-Host ""
225+
}
226+
else {
227+
$shouldDownload = $true
221228

222-
if ($Force) {
223-
Write-Host "Overwriting existing base specification..."
229+
if (Test-Path $baseSpecificationFolderPath) {
230+
Write-Host "Base specification already exists at: $baseSpecificationFolderPath"
224231
Write-Host ""
225-
Remove-Item -Path $baseSpecificationFolderPath -Recurse -Force
226-
}
227-
else {
228-
$shouldDownload = $false
232+
233+
if ($Force) {
234+
Write-Host "Overwriting existing base specification..."
235+
Write-Host ""
236+
Remove-Item -Path $baseSpecificationFolderPath -Recurse -Force
237+
}
238+
else {
239+
$shouldDownload = $false
240+
}
229241
}
230-
}
231242

232-
if ($shouldDownload) {
233-
Write-Host "Retrieving base specification..."
234-
Write-Host ""
243+
if ($shouldDownload) {
244+
Write-Host "Retrieving base specification..."
245+
Write-Host ""
235246

236-
if ($PSCmdlet.ParameterSetName -eq 'GitHub') {
237-
$success = Get-GitHubRepoContent -GitHubOwner $GitHubOwner `
238-
-GitHubRepository $GitHubRepository `
239-
-CommitHash $CommitHash `
240-
-GitHubToken $GitHubToken `
241-
-SubdirectoryPath "openai-in-typespec" `
242-
-Destination $baseSpecificationFolderPath
243-
}
244-
elseif ($PSCmdlet.ParameterSetName -eq 'Local') {
245-
$success = Get-LocalRepoContent -LocalRepositoryPath $LocalRepositoryPath `
246-
-SubdirectoryPath "openai-in-typespec" `
247-
-Destination $baseSpecificationFolderPath
248-
}
247+
if ($PSCmdlet.ParameterSetName -eq 'GitHub') {
248+
$success = Get-GitHubRepoContent -GitHubOwner $GitHubOwner `
249+
-GitHubRepository $GitHubRepository `
250+
-CommitHash $CommitHash `
251+
-GitHubToken $GitHubToken `
252+
-SubdirectoryPath "openai-in-typespec" `
253+
-Destination $baseSpecificationFolderPath
254+
}
255+
elseif ($PSCmdlet.ParameterSetName -eq 'Local') {
256+
$success = Get-LocalRepoContent -LocalRepositoryPath $LocalRepositoryPath `
257+
-SubdirectoryPath "openai-in-typespec" `
258+
-Destination $baseSpecificationFolderPath
259+
}
249260

250-
if (-not $success) {
251-
Write-Error "Failed to get repository contents."
252-
throw "Repository content retrieval failed."
261+
if (-not $success) {
262+
Write-Error "Failed to get repository contents."
263+
throw "Repository content retrieval failed."
264+
}
253265
}
254266
}
255267

specification/base/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

specification/base/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codegen_blackhole/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Import order matters. Somehow, importing the server decorated namespace afterwards,
2+
// will cause the the `description` field to be missing in the generated OpenAPI spec.
3+
import "./specialized-types.tsp";
4+
import "../../typespec/servers/rest.tsp";
5+
import "../../typespec";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace OpenAI;
2+
3+
// .NET code generation doesn't yet support many-to-one mappings of discriminators; here, we substitute one-to-one
4+
// model mappings that would unnecessarily complicate OpenAPI emission.
5+
6+
@discriminator("type")
7+
model ComparisonFilter {
8+
type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
9+
key: string;
10+
value: string | float32 | boolean;
11+
}
12+
13+
model ComparisonFilterEquals extends ComparisonFilter {
14+
type: "eq";
15+
}
16+
model ComparisonFilterNotEquals extends ComparisonFilter {
17+
type: "ne";
18+
}
19+
model ComparisonFilterGreaterThan extends ComparisonFilter {
20+
type: "gt";
21+
}
22+
model ComparisonFilterGreaterThanOrEquals extends ComparisonFilter {
23+
type: "gte";
24+
}
25+
model ComparisonFilterLessThan extends ComparisonFilter {
26+
type: "lt";
27+
}
28+
model ComparisonFilterLessThanOrEquals extends ComparisonFilter {
29+
type: "lte";
30+
}
31+
32+
@discriminator("type")
33+
model CompoundFilter {
34+
type: "and" | "or";
35+
filters: (ComparisonFilter | CompoundFilter)[];
36+
}
37+
model CompoundFilterAnd extends CompoundFilter {
38+
type: "and";
39+
}
40+
model CompoundFilterOr extends CompoundFilter {
41+
type: "or";
42+
}
43+
44+
alias VectorStoreFileAttributes = Record<unknown>;

0 commit comments

Comments
 (0)