Skip to content

Commit

Permalink
move func from compiler to openapi3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Zhang committed Aug 30, 2024
1 parent 06f9fdc commit 4b99815
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
3 changes: 0 additions & 3 deletions packages/compiler/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export {
getMinValueAsNumeric,
getMinValueExclusive,
getMinValueExclusiveAsNumeric,
getXmlNs,
isXmlAttribute,
isXmlUnwrapped,
type Discriminator,
} from "./intrinsic-type-state.js";
export {
Expand Down
27 changes: 0 additions & 27 deletions packages/compiler/src/core/intrinsic-type-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ function createStateSymbol(name: string) {
return Symbol.for(`TypeSpec.${name}`);
}

function createXmlStateSymbol(name: string) {
return Symbol.for(`@typespec/xml/${name}`);
}

const stateKeys = {
minValues: createStateSymbol("minValues"),
maxValues: createStateSymbol("maxValues"),
Expand All @@ -29,13 +25,6 @@ const stateKeys = {

discriminator: createStateSymbol("discriminator"),
};

const XmlStateKeys = {
attribute: createXmlStateSymbol("attribute"),
unwrapped: createXmlStateSymbol("unwrapped"),
nsDeclaration: createXmlStateSymbol("nsDeclaration"),
};

// #region @minValue

export function setMinValue(program: Program, target: Type, value: Numeric): void {
Expand Down Expand Up @@ -160,22 +149,6 @@ export function getMaxItems(program: Program, target: Type): number | undefined
}
// #endregion @maxItems

// #region @xml object
export function isXmlAttribute(program: Program, target: Type): boolean {
return program.stateSet(XmlStateKeys.attribute).has(target);
}
export function isXmlUnwrapped(program: Program, target: Type): boolean {
return program.stateSet(XmlStateKeys.unwrapped).has(target);
}
export function getXmlNs(program: Program, target: Type): XmlNamespace | undefined {
return program.stateMap(XmlStateKeys.nsDeclaration).get(target);
}
export interface XmlNamespace {
readonly namespace: string;
readonly prefix: string;
}
// #endregion @xml object

// #region doc

/** @internal */
Expand Down
30 changes: 30 additions & 0 deletions packages/openapi3/src/intrinsic-type-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Contains all intrinsic data setter or getter
// Anything that the TypeSpec check might should be here.

import { Type, type Program } from "@typespec/compiler";

function createXmlStateSymbol(name: string) {
return Symbol.for(`@typespec/xml/${name}`);
}

const XmlStateKeys = {
attribute: createXmlStateSymbol("attribute"),

This comment has been minimized.

Copy link
@timotheeguerin

timotheeguerin Aug 30, 2024

Member

Why are you redefining this you shouldn’t need this entire file

unwrapped: createXmlStateSymbol("unwrapped"),
nsDeclaration: createXmlStateSymbol("nsDeclaration"),
};

// #region @xml object
export function isXmlAttribute(program: Program, target: Type): boolean {
return program.stateSet(XmlStateKeys.attribute).has(target);
}
export function isXmlUnwrapped(program: Program, target: Type): boolean {
return program.stateSet(XmlStateKeys.unwrapped).has(target);
}
export function getXmlNs(program: Program, target: Type): XmlNamespace | undefined {
return program.stateMap(XmlStateKeys.nsDeclaration).get(target);
}
export interface XmlNamespace {
readonly namespace: string;
readonly prefix: string;
}
// #endregion @xml object
6 changes: 2 additions & 4 deletions packages/openapi3/src/schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ import {
getPattern,
getSummary,
getTypeName,
getXmlNs,
ignoreDiagnostics,
isArrayModelType,
isNeverType,
isNullType,
isSecret,
isTemplateDeclaration,
isXmlAttribute,
isXmlUnwrapped,
resolveEncodedName,
serializeValueAsJson,
} from "@typespec/compiler";
Expand Down Expand Up @@ -77,6 +74,7 @@ import {
} from "@typespec/openapi";
import { getOneOf, getRef } from "./decorators.js";
import { applyEncoding } from "./encoding.js";
import { getXmlNs, isXmlAttribute, isXmlUnwrapped } from "./intrinsic-type-state.js";
import { OpenAPI3EmitterOptions, reportDiagnostic } from "./lib.js";
import { ResolvedOpenAPI3EmitterOptions } from "./openapi.js";
import { getSchemaForStdScalars } from "./std-scalar-schemas.js";
Expand Down Expand Up @@ -838,7 +836,7 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter<
"deprecated"
);

this.#attachXmlObject(program, type as ModelProperty, schema);
//this.#attachXmlObject(program, type as ModelProperty, schema);

this.#attachExtensions(program, type, schema);

Expand Down

0 comments on commit 4b99815

Please sign in to comment.