Skip to content

Commit

Permalink
Fix flatten and no doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan Shao committed Oct 17, 2024
1 parent ab37a4d commit e12f6fb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { getOptions } from "../options";
import { TypespecObject } from "../interfaces";
import { generateDecorators } from "../utils/decorators";
import { generateDocs } from "../utils/docs";
import { getModelPropertiesDeclarations } from "../utils/model-generation";
import { generateSuppressionForDocumentRequired } from "../utils/suppressions";

export function generateObject(typespecObject: TypespecObject) {
const { isFullCompatible } = getOptions();
let definitions: string[] = [];

const fixme = getFixme(typespecObject);
fixme && definitions.push(fixme);

const doc = generateDocs(typespecObject);
if (doc === '' && isFullCompatible) definitions.push(generateSuppressionForDocumentRequired());
definitions.push(doc);

const decorators = generateDecorators(typespecObject.decorators);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateSuppressionForDocumentRequired } from "../utils/suppressions";
import { TypespecParameter } from "../interfaces";
import { getOptions } from "../options";
import { generateDecorators } from "../utils/decorators";
Expand All @@ -10,12 +11,13 @@ const _ARM_PARAM_REPLACEMENTS: { [key: string]: string } = {
};

export function generateParameter(parameter: TypespecParameter): string {
const { isArm } = getOptions();
const { isArm, isFullCompatible } = getOptions();
if (isArm && _ARM_PARAM_REPLACEMENTS[parameter.name] !== undefined) {
return _ARM_PARAM_REPLACEMENTS[parameter.name];
}
const definitions: string[] = [];
const doc = generateDocs(parameter);
if (doc === '' && isFullCompatible) definitions.push(generateSuppressionForDocumentRequired());
definitions.push(doc);

const decorators = generateDecorators(parameter.decorators);
Expand Down
33 changes: 16 additions & 17 deletions packages/extensions/openapi-to-typespec/src/utils/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ export function getPropertyDecorators(element: Property | Parameter): TypespecDe
locationDecorator.arguments =
format === "multi"
? [
{
value: `#{ name: "${element.language.default.serializedName}", explode: true }`,
options: { unwrap: true },
},
]
{
value: `#{ name: "${element.language.default.serializedName}", explode: true }`,
options: { unwrap: true },
},
]
: [
{
value:
format === "csv"
? `"${element.language.default.serializedName}"`
: `{name: "${element.language.default.serializedName}", format: "${format}"}`,
options: { unwrap: true },
},
];
{
value:
format === "csv"
? `"${element.language.default.serializedName}"`
: `{name: "${element.language.default.serializedName}", format: "${format}"}`,
options: { unwrap: true },
},
];
}
}

Expand All @@ -173,10 +173,9 @@ export function getPropertyDecorators(element: Property | Parameter): TypespecDe

if (element.extensions?.["x-ms-client-flatten"] && isFullCompatible) {
decorators.push({
name: "extension",
module: "@typespec/openapi",
namespace: "TypeSpec.OpenAPI",
arguments: [{ value: `"x-ms-client-flatten"` }, { value: "true" }],
name: "Azure.ResourceManager.Private.conditionalClientFlatten",
suppressionCode: "@azure-tools/typespec-azure-core/no-private-usage",
suppressionMessage: "For backward compatibility"
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { TypespecObjectProperty } from "../interfaces";
import { getOptions } from "../options";
import { generateDecorators } from "./decorators";
import { generateDocs } from "./docs";
import { generateSuppressions } from "./suppressions";
import { generateSuppressionForDocumentRequired, generateSuppressions } from "./suppressions";
import { getFullyQualifiedName } from "./type-mapping";

export function getModelPropertiesDeclarations(properties: TypespecObjectProperty[]): string[] {
const { isFullCompatible } = getOptions();
const definitions: string[] = [];
for (const property of properties) {
const propertyDoc = generateDocs(property);
if (propertyDoc === '' && isFullCompatible) definitions.push(generateSuppressionForDocumentRequired());
propertyDoc && definitions.push(propertyDoc);
const decorators = generateDecorators(property.decorators);
decorators && definitions.push(decorators);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChoiceSchema, Property, Schema, SealedChoiceSchema } from "@autorest/codemodel";
import { Property } from "@autorest/codemodel";
import { WithSuppressDirective } from "../interfaces";
import { isChoiceSchema, isSealedChoiceSchema, isDictionarySchema, isStringSchema } from "./schemas";
import { isDictionarySchema } from "./schemas";

export function generateSuppressionForDocumentRequired(): string {
return `#suppress "@azure-tools/typespec-azure-core/documentation-required" "For backward compatibility"`;
Expand Down

0 comments on commit e12f6fb

Please sign in to comment.