Skip to content

Commit

Permalink
doc: fix incorrect example of @statusCode (#3230)
Browse files Browse the repository at this point in the history
## Issue Description
There is a example of `TypeSpec.http.@statusCode`
[here](https://typespec.io/docs/next/libraries/http/reference/decorators#@TypeSpec.Http.statusCode).
However, the property name is missing in this example. Due to this, the
code did not work as expected.

```
op read(): {@statuscode: 200, @Body pet: Pet}
op create(): {@statuscode: 201 | 202}
```

Instead, specifying the property name as follows made it work correctly:

```
op read(): {
  @statuscode _: 200;
  @Body pet: Widget;
};
op create(): {
  @statuscode _: 201 | 202;
};
```

## Fix Description
- Corrected examples of `TypeSpec.http.@statusCode` in the reference and
documentation.

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
  • Loading branch information
4 people committed Jun 3, 2024
1 parent de2baab commit 26e44b2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
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: internal
packages:
- "@typespec/http"
---

doc: fix incorrect example of `@statusCode`
9 changes: 7 additions & 2 deletions docs/libraries/http/reference/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,13 @@ None
#### Examples

```typespec
op read(): {@statusCode: 200, @body pet: Pet}
op create(): {@statusCode: 201 | 202}
op read(): {
@statusCode _: 200;
@body pet: Pet;
};
op create(): {
@statusCode _: 201 | 202;
};
```

### `@useAuth` {#@TypeSpec.Http.useAuth}
Expand Down
9 changes: 7 additions & 2 deletions packages/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,13 @@ None
##### Examples

```typespec
op read(): {@statusCode: 200, @body pet: Pet}
op create(): {@statusCode: 201 | 202}
op read(): {
@statusCode _: 200;
@body pet: Pet;
};
op create(): {
@statusCode _: 201 | 202;
};
```

#### `@useAuth`
Expand Down
9 changes: 7 additions & 2 deletions packages/http/generated-defs/TypeSpec.Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import type {
*
* @example
* ```typespec
* op read(): {@statusCode: 200, @body pet: Pet}
* op create(): {@statusCode: 201 | 202}
* op read(): {
* @statusCode _: 200;
* @body pet: Pet;
* };
* op create(): {
* @statusCode _: 201 | 202;
* };
* ```
*/
export type StatusCodeDecorator = (context: DecoratorContext, target: ModelProperty) => void;
Expand Down
9 changes: 7 additions & 2 deletions packages/http/lib/http-decorators.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ extern dec bodyIgnore(target: ModelProperty);
* @example
*
* ```typespec
* op read(): {@statusCode: 200, @body pet: Pet}
* op create(): {@statusCode: 201 | 202}
* op read(): {
* @statusCode _: 200;
* @body pet: Pet;
* };
* op create(): {
* @statusCode _: 201 | 202;
* };
* ```
*/
extern dec statusCode(target: ModelProperty);
Expand Down

0 comments on commit 26e44b2

Please sign in to comment.