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

OpenAPI3 with emitter framework (for schemas) #2547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
76dfaad
initial primitive types
timotheeguerin Oct 3, 2023
f293673
v1
timotheeguerin Oct 3, 2023
b46fd4a
progress
timotheeguerin Oct 3, 2023
7e728a7
model prop ref
timotheeguerin Oct 3, 2023
7826502
progress
timotheeguerin Oct 4, 2023
77b9ec2
Handle enums
timotheeguerin Oct 4, 2023
ba578ab
Handle unions minus visibility
timotheeguerin Oct 4, 2023
4058afe
Slight cleanup
timotheeguerin Oct 4, 2023
137303b
visibility
timotheeguerin Oct 4, 2023
e031f9a
Visibility progress
timotheeguerin Oct 4, 2023
e1b661f
Deal with visibility
timotheeguerin Oct 6, 2023
b7ef682
Fix bleed
timotheeguerin Oct 6, 2023
6ef6971
Significant progress
timotheeguerin Oct 6, 2023
0c81151
fix dup schema error
timotheeguerin Oct 6, 2023
5607d52
Merge branch 'main' of https://github.com/Microsoft/typespec into ope…
timotheeguerin Oct 6, 2023
48c827d
wip
timotheeguerin Oct 7, 2023
8ba77ac
Merge with main
timotheeguerin Oct 7, 2023
e49aba6
More
timotheeguerin Oct 7, 2023
b472367
Merge branch 'main' into openapi3/emitter-framework
timotheeguerin Oct 17, 2023
098374f
Merge branch 'main' of https://github.com/Microsoft/typespec into ope…
timotheeguerin Oct 23, 2023
b11a2c3
Regen samples and add circular ref
timotheeguerin Oct 23, 2023
f5ea145
Merge branch 'main' of https://github.com/Microsoft/typespec into ope…
timotheeguerin Oct 30, 2023
7b52ba8
fix
timotheeguerin Oct 30, 2023
0c7713a
Fix test
timotheeguerin Oct 30, 2023
456af2b
.
timotheeguerin Oct 30, 2023
533a5a1
Merge branch 'main' into openapi3/emitter-framework
timotheeguerin Oct 30, 2023
d63d84d
Merge branch 'main' into openapi3/emitter-framework
timotheeguerin Nov 2, 2023
9a57149
Merge branch 'main' into openapi3/emitter-framework
timotheeguerin Nov 6, 2023
6bfae21
changelog
timotheeguerin Nov 6, 2023
534f49c
Merge branch 'main' into openapi3/emitter-framework
timotheeguerin Nov 16, 2023
e5ac05c
cleanup cr
timotheeguerin Nov 16, 2023
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": "@typespec/compiler",
"comment": "Emitter framework: Allow passing a custom context when calling `emitType` ",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "Migrate code to use the emitter framework",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
11 changes: 10 additions & 1 deletion packages/compiler/src/emitter-framework/asset-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,16 @@ export function createAssetEmitter<T, TOptions extends object>(
return typeEmitter.writeOutput(sourceFiles);
},

emitType(type) {
getSourceFiles() {
return sourceFiles;
},

emitType(type, context?: ContextState) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to handle context's lexicalContext as well?

if (context?.referenceContext) {
incomingReferenceContext = context?.referenceContext ?? incomingReferenceContext;
incomingReferenceContextTarget = type ?? incomingReferenceContextTarget;
}

const declName =
isDeclaration(type) && type.kind !== "Namespace" ? typeEmitter.declarationName(type) : null;
const key = typeEmitterKey(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export class ArrayBuilder<T> extends Array {

push(...values: (EmitEntity<T> | Placeholder<T> | T)[]): number {
for (const v of values) {
let toPush: Placeholder<T> | T | null;
let toPush: Placeholder<T> | T | undefined;
if (v instanceof EmitterResult) {
compilerAssert(v.kind !== "circular", "Can't push a circular emit result.");

if (v.kind === "none") {
toPush = null;
toPush = undefined;
} else {
toPush = v.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ObjectBuilder<T> {
compilerAssert(v.kind !== "circular", "Can't set a circular emit result.");

if (v.kind === "none") {
this[key] = null;
this[key] = undefined;
return;
} else {
value = v.value;
Expand Down
5 changes: 4 additions & 1 deletion packages/compiler/src/emitter-framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AssetEmitter<T, TOptions extends object = Record<string, unknow
getProgram(): Program;
emitTypeReference(type: Type): EmitEntity<T>;
emitDeclarationName(type: TypeSpecDeclaration): string | undefined;
emitType(type: Type): EmitEntity<T>;
emitType(type: Type, context?: Partial<ContextState>): EmitEntity<T>;
emitProgram(options?: { emitGlobalNamespace?: boolean; emitTypeSpecNamespace?: boolean }): void;
emitModelProperties(model: Model): EmitEntity<T>;
emitModelProperty(prop: ModelProperty): EmitEntity<T>;
Expand All @@ -57,6 +57,9 @@ export interface AssetEmitter<T, TOptions extends object = Record<string, unknow
none(): NoEmit;
};
writeOutput(): Promise<void>;

/** Get source files that have been scoped. */
getSourceFiles(): SourceFile<T>[];
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
}

export interface ScopeBase<T> {
Expand Down
Loading