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

Deprecate getAssetEmitter and recommend calling createAssetEmitter directly #3516

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Deprecate getAssetEmitter and recommend calling `createAssetEmitter` directly
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/json-schema"
- "@typespec/openapi3"
---

Fix issue that could result in invalid document generation when running `tsp compile` from another directory
2 changes: 2 additions & 0 deletions packages/compiler/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,8 @@ export interface EmitContext<TOptions extends object = Record<string, never>> {
/**
* Get an asset emitter to write emitted output to disk using a TypeEmitter
*
* @deprecated call {@link createAssetEmitter} directly instead.
*
* @param TypeEmitterClass The TypeEmitter to construct your emitted output
*/
getAssetEmitter<T>(TypeEmitterClass: typeof TypeEmitter<T, TOptions>): AssetEmitter<T, TOptions>;
Expand Down
3 changes: 2 additions & 1 deletion packages/json-schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
setTypeSpecNamespace,
typespecTypeToJson,
} from "@typespec/compiler";
import { createAssetEmitter } from "@typespec/compiler/emitter-framework";
import { ValidatesRawJsonDecorator } from "../generated-defs/TypeSpec.JsonSchema.Private.js";
import {
BaseUriDecorator,
Expand Down Expand Up @@ -44,7 +45,7 @@ export type JsonSchemaDeclaration = Model | Union | Enum | Scalar;
const jsonSchemaKey = createStateSymbol("JsonSchema");

export async function $onEmit(context: EmitContext<JSONSchemaEmitterOptions>) {
const emitter = context.getAssetEmitter(JsonSchemaEmitter);
const emitter = createAssetEmitter(context.program, JsonSchemaEmitter as any, context);

if (emitter.getOptions().emitAllModels) {
emitter.emitProgram({ emitTypeSpecNamespace: false });
Expand Down
6 changes: 4 additions & 2 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,14 @@ function createOAPIEmitter(
service.type,
options.omitUnreachableTypes
);
schemaEmitter = context.getAssetEmitter(
schemaEmitter = createAssetEmitter(
program,
class extends OpenAPI3SchemaEmitter {
constructor(emitter: AssetEmitter<Record<string, any>, OpenAPI3EmitterOptions>) {
super(emitter, metadataInfo, visibilityUsage, options);
}
} as any
} as any,
context
);

const securitySchemes = getOpenAPISecuritySchemes(allHttpAuthentications);
Expand Down
Loading