Skip to content

Commit

Permalink
Arm library generated TS decorator signatures (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Jul 18, 2024
1 parent 5a4f789 commit 6058195
Show file tree
Hide file tree
Showing 17 changed files with 775 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ property to the type of the Azure Resource Manager resource.

#### Target

`Operation | Model`
`Operation`

#### Parameters

Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-azure-resource-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ property to the type of the Azure Resource Manager resource.

##### Target

`Operation | Model`
`Operation`

##### Parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { DecoratorContext, Enum, Model, ModelProperty, Union } from "@typespec/compiler";

/**
* Marks an enum as representing the valid `common-types` versions.
*/
export type ArmCommonTypesVersionsDecorator = (context: DecoratorContext, target: Enum) => void;

/**
*
*
*
* @param definitionName Definition name
* @param version Azure Resource Manager Version
* @param referenceFile Reference file
*/
export type ArmCommonParameterDecorator = (
context: DecoratorContext,
target: ModelProperty,
definitionName?: string,
version?: unknown | unknown | string,
referenceFile?: string
) => void;

/**
*
*
*
* @param definitionName Definition name
* @param version Azure Resource Manager Version
* @param referenceFile Reference file
*/
export type ArmCommonDefinitionDecorator = (
context: DecoratorContext,
target: Model | Enum | Union,
definitionName?: string,
version?: unknown | unknown | string,
referenceFile?: string
) => void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import type { DecoratorContext, Model, ModelProperty, Operation, Type } from "@typespec/compiler";

/**
*
*
*
* @param propertyName Name of the property to omit
*/
export type ResourceBaseParametersOfDecorator = (
context: DecoratorContext,
target: Model,
propertyName: Model
) => void;

/**
*
*
*
* @param values Values
*/
export type ResourceParameterBaseForDecorator = (
context: DecoratorContext,
target: ModelProperty,
values: Type
) => void;

/**
* This decorator is used to identify Azure Resource Manager resource. In generated
* swagger definition, it will be marked with `x-ms-azure-resource`.
*
* It is *not* meant to be used directly by a spec author,
*/
export type AzureResourceBaseDecorator = (context: DecoratorContext, target: Model) => void;

/**
* Omit a property in the target model.
*
* @internal
*
*
* @param propertyName Name of the property to omit
*/
export type OmitIfEmptyDecorator = (
context: DecoratorContext,
target: Model,
propertyName: string
) => void;

/**
* Please DO NOT USE in RestAPI specs.
* Internal decorator that deprecated direct usage of `x-ms-client-flatten` OpenAPI extension.
* It will programatically enabled/disable client flattening with
*
* @flattenProperty with autorest
* emitter flags to maintain compatibility in swagger.
*/
export type ConditionalClientFlattenDecorator = (
context: DecoratorContext,
target: ModelProperty
) => void;

/**
*
*
*
* @param resource Resource model
*/
export type AssignProviderNameValueDecorator = (
context: DecoratorContext,
target: ModelProperty,
resource: Model
) => void;

/**
* Update the Azure Resource Manager provider namespace for a given entity.
*/
export type ArmUpdateProviderNamespaceDecorator = (
context: DecoratorContext,
target: Operation
) => void;

/**
* This decorator is used to identify Azure Resource Manager resource types and extract their
* metadata. It is *not* meant to be used directly by a spec author, it instead
* gets implicitly applied when the spec author defines a model type in this form:
*
* `model Server is TrackedResource<ServerProperties>;`
*
* The `TrackedResource<Resource>` type (and other associated base types) use the
* `@armResource` decorator, so it also gets applied to the type which absorbs the
* `TrackedResource<Resource>` definition by using the `is` keyword.
*
* @param properties Azure Resource Manager resource properties
*/
export type ArmResourceInternalDecorator = (
context: DecoratorContext,
target: Model,
properties: Model
) => void;

/**
* Provides default name decoration on resource name property with
* camelcased and pluralized key and segment name
*/
export type DefaultResourceKeySegmentNameDecorator = (
context: DecoratorContext,
target: ModelProperty,
armResource: Model,
keyName: string,
segment: string
) => void;

/**
* Provides strict contraint type check.
*
* Due to TypeSpec language and all optional properties of `Foundations.Resource`,
* the `Resource extends Foundations.Resource` on many of the standard ARM templates is
* essentially equal to `Resource extends {}` and does not enforce the containt.
*
* Note, this is intended for internal use only for now.
*/
export type EnforceConstraintDecorator = (
context: DecoratorContext,
target: Operation | Model,
sourceType: Model,
constraintType: Model
) => void;

/**
* Marks the operation as being a collection action
*
* @param resourceType Resource
* @param parentTypeName : Parent type name.
* @param parentFriendlyTypeName Friendly name for parent.
* @param applyOperationRename If true, apply both doc and operation name update
*/
export type ArmRenameListByOperationDecorator = (
context: DecoratorContext,
target: Operation,
resourceType: Model,
parentTypeName?: string,
parentFriendlyTypeName?: string,
applyOperationRename?: boolean
) => void;

/**
* Please DO NOT USE in RestAPI specs.
* This decorator is used to adjust optionality on ARM Resource's `properties` field for brownfield service conversion.
*/
export type ArmResourcePropertiesOptionalityDecorator = (
context: DecoratorContext,
target: ModelProperty,
isOptional: boolean
) => void;
Loading

0 comments on commit 6058195

Please sign in to comment.