Skip to content

Latest commit

 

History

History
181 lines (135 loc) · 3.06 KB

built-in-directives.md

File metadata and controls

181 lines (135 loc) · 3.06 KB

Autorest built-in directives

Autorest provides a set of built-in directives for common scenarios to simplify things.

Those directives are defined here

Selection

Selecting operation

directive:
  - where-operation: <operationId>
    transform: ... # Your transform code

  - where-operation-match: <fullregex with // and flags>
    transform: ... # Your transform code

Examples:

- where-operation: MyOperation
  transform: $["x-marked"] = true

- where-operation-match: /mygroup_.*/i
  transform: $["x-marked"] = true

Selecting model

directive:
  - where-model: <modelName>
    transform: ... # Your transform code

Transforms

Remove operation

directive:
  - remove-operation: <operationId>

  - remove-operation-match: <regex>

Examples:

directive:
  # Remove operation with operationId: Foo_Get
  - remove-operation: Foo_Get

  # Remove all operations with matching operationIds
  - remove-operation-match: /^foo_g.*/i

Rename operation

directive:
  - rename-operation:
      from: <operationId>
      to: <new-operationId>

Examples:

directive:
  # Rename operation with operationId: Foo_Get to Bar_Get
  - rename-operation:
      from: Foo_Get
      to: Bar_Get

Remove model

directive:
  - remove-model: <name>

Examples:

directive:
  # Remove model named MyModel
  - remove-model: MyModel

Rename model

directive:
  - rename-model:
      from: <name>
      to: <new-name>

Examples:

directive:
  # Rename model named MyModel to NewModel
  - rename-model:
      from: MyModel
      to: NewModel

Remove property

Remove the property on a model, to be used with where-model

directive:
  - where-model: <model-name>
    remove-property: <property-name>

Examples:

directive:
  # Remove property foo on model named MyModel
  - where-model: MyModel
    remove-property: foo

Rename property

Rename the property on a model(Rename the actual property name and doesn't change x-ms-client-name.), to be used with where-model

directive:
  - where-model: <model-name>
    rename-property:
      from: <property-name>
      to: <new-property-name>

Examples:

directive:
  # Rename property foo to bar on model named MyModel
  - where-model: MyModel
    rename-property:
      from: foo
      to: bar

Remove parameter

Remove a parameter. To be used with where-operation or where: '$.paths..' for all operations.

directive:
  - remove-parameter:
      in: <type> # header,query,cookie(Same options allowed in OpenAPI)
      name: <name> # Name of the parameter

Examples:

directive:
  # Remove header named myHeader on operation Foo_Get
  - where-operation: Foo_Get
    remove-parameter:
      in: header
      name: myHeader

  # Remove query parmeter named page on all operations
  - where: "$.paths..*"
    remove-parameter:
      in: header
      name: page