Skip to content

Commit dff9bb5

Browse files
authored
Refactor repo and add initial codegen (#538)
1 parent 6a50608 commit dff9bb5

File tree

2,064 files changed

+9700
-6683
lines changed

Some content is hidden

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

2,064 files changed

+9700
-6683
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ jobs:
114114
${{ github.workspace }}/build-artifacts/packages/*.nupkg
115115
--source https://api.nuget.org/v3/index.json
116116
--api-key ${{ secrets.NUGET_API_KEY }}
117-
--skip-duplicate
117+
--skip-duplicate

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,11 @@ TempTypeSpecFiles/
181181
# Artifacts from the generator
182182
tspCodeModel.json
183183
Configuration.json
184+
185+
# Base specification files
186+
specification/base/
187+
188+
# Generator default TypeSpec output
189+
codegen/tsp-output/
190+
codegen/temp/
191+
codegen/emitter/temp/tsconfig.tsbuildinfo

api/OpenAI.net8.0.cs

Lines changed: 2 additions & 829 deletions
Large diffs are not rendered by default.

api/OpenAI.netstandard2.0.cs

Lines changed: 2 additions & 125 deletions
Large diffs are not rendered by default.

codegen/emitter/src/emitter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { EmitContext } from "@typespec/compiler";
2+
3+
import {
4+
$onEmit as $OnMGCEmit,
5+
CSharpEmitterOptions
6+
} from "@typespec/http-client-csharp";
7+
8+
export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
9+
context.options["generator-name"] = "OpenAILibraryGenerator";
10+
context.options["emitter-extension-path"] = import.meta.url;
11+
await $OnMGCEmit(context);
12+
}

codegen/emitter/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./emitter.js";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35327.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI.Library.Plugin", "src\OpenAI.Library.Plugin.csproj", "{E46178E4-F3F0-4E2F-8D42-A7F021B23E63}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E46178E4-F3F0-4E2F-8D42-A7F021B23E63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E46178E4-F3F0-4E2F-8D42-A7F021B23E63}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E46178E4-F3F0-4E2F-8D42-A7F021B23E63}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E46178E4-F3F0-4E2F-8D42-A7F021B23E63}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<RootNamespace>OpenAI.Microsoft.Generator.CSharp.ClientModel.Plugin</RootNamespace>
7+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250626.7" />
12+
</ItemGroup>
13+
14+
<!-- Copy output to package dist path for local execution and -->
15+
<Target Name="CopyForNpmPackage" AfterTargets="Build">
16+
<Message Text="Copying output to dist path" Importance="high" />
17+
<ItemGroup>
18+
<SourceDir Include="$(OutputPath)**\*.*" />
19+
</ItemGroup>
20+
<Copy SourceFiles="@(SourceDir)" DestinationFolder="$(MSBuildThisFileDirectory)..\..\dist\generator\%(RecursiveDir)" />
21+
<Copy SourceFiles="..\..\..\node_modules\@typespec\http-client-csharp\dist\generator\Microsoft.TypeSpec.Generator.runtimeconfig.json" DestinationFolder="$(MSBuildThisFileDirectory)..\..\dist\generator" />
22+
</Target>
23+
24+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using Microsoft.TypeSpec.Generator;
4+
using Microsoft.TypeSpec.Generator.ClientModel;
5+
using OpenAILibraryPlugin.Visitors;
6+
7+
namespace OpenAILibraryPlugin
8+
{
9+
[Export(typeof(CodeModelGenerator))]
10+
[ExportMetadata("GeneratorName", nameof(OpenAILibraryGenerator))]
11+
public class OpenAILibraryGenerator : ScmCodeModelGenerator
12+
{
13+
private static OpenAILibraryGenerator? s_instance;
14+
internal static OpenAILibraryGenerator Instance => s_instance ?? throw new InvalidOperationException("OpenAILibraryGenerator was not initialized.");
15+
16+
[ImportingConstructor]
17+
public OpenAILibraryGenerator(GeneratorContext context) : base(context)
18+
{
19+
s_instance = this;
20+
}
21+
22+
protected override void Configure()
23+
{
24+
base.Configure();
25+
AddVisitor(new ConstructorFixupVisitor());
26+
AddVisitor(new KindRenameVisitor());
27+
AddVisitor(new VisibilityVisitor());
28+
AddVisitor(new ContentInnerCollectionDefinedVisitor());
29+
AddVisitor(new NonAbstractPublicTypesVisitor());
30+
AddVisitor(new PageOrderRemovalVisitor(this));
31+
AddVisitor(new OmittedTypesVisitor());
32+
AddVisitor(new InvariantFormatAdditionalPropertiesVisitor());
33+
AddVisitor(new OpenAILibraryVisitor());
34+
AddVisitor(new VirtualMessageCreationVisitor());
35+
AddVisitor(new ProhibitedNamespaceVisitor());
36+
AddVisitor(new ExplicitConversionFromClientResultVisitor());
37+
AddVisitor(new ImplicitConversionToBinaryContentVisitor());
38+
AddVisitor(new ModelSerializationVisitor());
39+
AddVisitor(new ExperimentalAttributeVisitor());
40+
AddVisitor(new ModelDirectoryVisitor());
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)