Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ artifacts
# Temporary typespec folders for typespec generation
TempTypeSpecFiles/

# Base specification files
specification/base/
# Azure specification files
specification/base/entrypoints/azure.v1
specification/base/entrypoints/sdk.dotnet.azure
specification/base/typespec.azure
specification/base/typespec.azure.v1

# Generator default TypeSpec output
codegen/tsp-output/
Expand Down
72 changes: 42 additions & 30 deletions scripts/Invoke-CodeGen.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[CmdletBinding(DefaultParameterSetName = 'GitHub')]
[CmdletBinding(DefaultParameterSetName = 'Default')]
param(
[Parameter(Mandatory = $true, ParameterSetName = 'GitHub')]
[string]$GitHubOwner,
Expand Down Expand Up @@ -214,42 +214,54 @@ $codegenFolderPath = Join-Path $repoRootPath "codegen"

$scriptStartTime = Get-Date

$shouldDownload = $true
if (Test-Path $baseSpecificationFolderPath) {
Write-Host "Base specification already exists at: $baseSpecificationFolderPath"
if ($PSCmdlet.ParameterSetName -eq 'Default') {
if (-not (Test-Path $baseSpecificationFolderPath)) {
Write-Error "Base specification path does not exist: $baseSpecificationFolderPath"
throw "Default specification path not found"
}

Write-Host "Using existing base specification at: $baseSpecificationFolderPath"
Write-Host ""
}
else {
$shouldDownload = $true

if ($Force) {
Write-Host "Overwriting existing base specification..."
if (Test-Path $baseSpecificationFolderPath) {
Write-Host "Base specification already exists at: $baseSpecificationFolderPath"
Write-Host ""
Remove-Item -Path $baseSpecificationFolderPath -Recurse -Force
}
else {
$shouldDownload = $false

if ($Force) {
Write-Host "Overwriting existing base specification..."
Write-Host ""
Remove-Item -Path $baseSpecificationFolderPath -Recurse -Force
}
else {
$shouldDownload = $false
}
}
}

if ($shouldDownload) {
Write-Host "Retrieving base specification..."
Write-Host ""
if ($shouldDownload) {
Write-Host "Retrieving base specification..."
Write-Host ""

if ($PSCmdlet.ParameterSetName -eq 'GitHub') {
$success = Get-GitHubRepoContent -GitHubOwner $GitHubOwner `
-GitHubRepository $GitHubRepository `
-CommitHash $CommitHash `
-GitHubToken $GitHubToken `
-SubdirectoryPath "openai-in-typespec" `
-Destination $baseSpecificationFolderPath
}
elseif ($PSCmdlet.ParameterSetName -eq 'Local') {
$success = Get-LocalRepoContent -LocalRepositoryPath $LocalRepositoryPath `
-SubdirectoryPath "openai-in-typespec" `
-Destination $baseSpecificationFolderPath
}
if ($PSCmdlet.ParameterSetName -eq 'GitHub') {
$success = Get-GitHubRepoContent -GitHubOwner $GitHubOwner `
-GitHubRepository $GitHubRepository `
-CommitHash $CommitHash `
-GitHubToken $GitHubToken `
-SubdirectoryPath "openai-in-typespec" `
-Destination $baseSpecificationFolderPath
}
elseif ($PSCmdlet.ParameterSetName -eq 'Local') {
$success = Get-LocalRepoContent -LocalRepositoryPath $LocalRepositoryPath `
-SubdirectoryPath "openai-in-typespec" `
-Destination $baseSpecificationFolderPath
}

if (-not $success) {
Write-Error "Failed to get repository contents."
throw "Repository content retrieval failed."
if (-not $success) {
Write-Error "Failed to get repository contents."
throw "Repository content retrieval failed."
}
}
}

Expand Down
1 change: 1 addition & 0 deletions specification/base/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
1 change: 1 addition & 0 deletions specification/base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codegen_blackhole/
5 changes: 5 additions & 0 deletions specification/base/entrypoints/sdk.dotnet/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Import order matters. Somehow, importing the server decorated namespace afterwards,
// will cause the the `description` field to be missing in the generated OpenAPI spec.
import "./specialized-types.tsp";
import "../../typespec/servers/rest.tsp";
import "../../typespec";
44 changes: 44 additions & 0 deletions specification/base/entrypoints/sdk.dotnet/specialized-types.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace OpenAI;

// .NET code generation doesn't yet support many-to-one mappings of discriminators; here, we substitute one-to-one
// model mappings that would unnecessarily complicate OpenAPI emission.

@discriminator("type")
model ComparisonFilter {
type: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
key: string;
value: string | float32 | boolean;
}

model ComparisonFilterEquals extends ComparisonFilter {
type: "eq";
}
model ComparisonFilterNotEquals extends ComparisonFilter {
type: "ne";
}
model ComparisonFilterGreaterThan extends ComparisonFilter {
type: "gt";
}
model ComparisonFilterGreaterThanOrEquals extends ComparisonFilter {
type: "gte";
}
model ComparisonFilterLessThan extends ComparisonFilter {
type: "lt";
}
model ComparisonFilterLessThanOrEquals extends ComparisonFilter {
type: "lte";
}

@discriminator("type")
model CompoundFilter {
type: "and" | "or";
filters: (ComparisonFilter | CompoundFilter)[];
}
model CompoundFilterAnd extends CompoundFilter {
type: "and";
}
model CompoundFilterOr extends CompoundFilter {
type: "or";
}

alias VectorStoreFileAttributes = Record<unknown>;
Loading