Skip to content

Commit

Permalink
fix(docs): display optional return in docs (#6248)
Browse files Browse the repository at this point in the history
## Checklist

Fixes: #2543

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
tsuf239 authored Apr 16, 2024
1 parent 9348f9a commit ffdc6b0
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 245 deletions.
15 changes: 12 additions & 3 deletions apps/jsii-docgen/src/docgen/transpile/wing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ const formatSignature = (
name: string,
inputs: string[],
returns?: string,
isInflight?: boolean
isInflight?: boolean,
isOptionalReturn?: boolean
) => {
return `${isInflight ? "inflight " : ""}${name}(${formatArguments(inputs)})${
returns ? ": " + returns : ""
returns ? ": " + `${returns}${isOptionalReturn ? "?" : ""}` : ""
}`;
};

Expand Down Expand Up @@ -207,9 +208,11 @@ export class WingTranspile extends transpile.TranspileBase {
: formatInvocation(type, inputs, name);

let returnType: transpile.TranspiledTypeReference | undefined;
let isReturnOptional: boolean = false;
if (reflect.Initializer.isInitializer(callable)) {
returnType = this.typeReference(callable.parentType.reference);
} else if (reflect.Method.isMethod(callable)) {
isReturnOptional = callable.returns.optional;
returnType = this.typeReference(callable.returns.type);
}
const returns = returnType?.toString(typeToString);
Expand All @@ -220,7 +223,13 @@ export class WingTranspile extends transpile.TranspileBase {
import: formatImport(type),
parameters,
signatures: [
formatSignature(name, inputs, returns, isInflightMethod(callable.docs)),
formatSignature(
name,
inputs,
returns,
isInflightMethod(callable.docs),
isReturnOptional
),
],
invocations: [invocation],
returnType,
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/04-standard-library/aws/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ Key of the object.
##### `tryGet` <a name="tryGet" id="@winglang/sdk.cloud.IBucketClient.tryGet"></a>

```wing
inflight tryGet(key: str, options?: BucketTryGetOptions): str
inflight tryGet(key: str, options?: BucketTryGetOptions): str?
```

Get an object from the bucket if it exists If the bytes returned are not a valid UTF-8 string, an error is thrown.
Expand All @@ -365,7 +365,7 @@ Additional get options.
##### `tryGetJson` <a name="tryGetJson" id="@winglang/sdk.cloud.IBucketClient.tryGetJson"></a>

```wing
inflight tryGetJson(key: str): Json
inflight tryGetJson(key: str): Json?
```

Gets an object from the bucket if it exists, parsing it as Json.
Expand Down Expand Up @@ -633,7 +633,7 @@ new aws.FunctionRef(functionArn: str);
##### `invoke` <a name="invoke" id="@winglang/sdk.cloud.IFunctionClient.invoke"></a>

```wing
inflight invoke(payload?: str): str
inflight invoke(payload?: str): str?
```

Invokes the function with a payload and waits for the result.
Expand Down Expand Up @@ -784,7 +784,7 @@ Retrieve the approximate number of messages in the queue.
##### `pop` <a name="pop" id="@winglang/sdk.cloud.IQueueClient.pop"></a>

```wing
inflight pop(): str
inflight pop(): str?
```

Pop a message from the queue.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/04-standard-library/cloud/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ Inflight client for `IApiEndpointHandler`.
##### `handle` <a name="handle" id="@winglang/sdk.cloud.IApiEndpointHandlerClient.handle"></a>
```wing
inflight handle(request: ApiRequest): ApiResponse
inflight handle(request: ApiRequest): ApiResponse?
```
Inflight that will be called when a request is made to the endpoint.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/04-standard-library/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ Key of the object.
##### `tryGet` <a name="tryGet" id="@winglang/sdk.cloud.IBucketClient.tryGet"></a>

```wing
inflight tryGet(key: str, options?: BucketTryGetOptions): str
inflight tryGet(key: str, options?: BucketTryGetOptions): str?
```

Get an object from the bucket if it exists If the bytes returned are not a valid UTF-8 string, an error is thrown.
Expand All @@ -621,7 +621,7 @@ Additional get options.
##### `tryGetJson` <a name="tryGetJson" id="@winglang/sdk.cloud.IBucketClient.tryGetJson"></a>

```wing
inflight tryGetJson(key: str): Json
inflight tryGetJson(key: str): Json?
```

Gets an object from the bucket if it exists, parsing it as Json.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/04-standard-library/cloud/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Add an environment variable to the function.
##### `invoke` <a name="invoke" id="@winglang/sdk.cloud.IFunctionClient.invoke"></a>
```wing
inflight invoke(payload?: str): str
inflight invoke(payload?: str): str?
```
Invokes the function with a payload and waits for the result.
Expand Down Expand Up @@ -439,7 +439,7 @@ Inflight client for `IFunctionHandler`.
##### `handle` <a name="handle" id="@winglang/sdk.cloud.IFunctionHandlerClient.handle"></a>
```wing
inflight handle(event?: str): str
inflight handle(event?: str): str?
```
Entrypoint function that will be called when the cloud function is invoked.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/04-standard-library/cloud/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Retrieve the approximate number of messages in the queue.
##### `pop` <a name="pop" id="@winglang/sdk.cloud.IQueueClient.pop"></a>

```wing
inflight pop(): str
inflight pop(): str?
```

Pop a message from the queue.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/04-standard-library/cloud/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ Inflight client for `IServiceHandler`.
##### `handle` <a name="handle" id="@winglang/sdk.cloud.IServiceHandlerClient.handle"></a>

```wing
handle(): IServiceStopHandler
handle(): IServiceStopHandler?
```

Handler to run when the service starts.
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/04-standard-library/ex/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ the key.
##### `get` <a name="get" id="@winglang/sdk.ex.IRedisClient.get"></a>

```wing
inflight get(key: str): str
inflight get(key: str): str?
```

Get value at given key.
Expand All @@ -78,7 +78,7 @@ the key to get.
##### `hget` <a name="hget" id="@winglang/sdk.ex.IRedisClient.hget"></a>

```wing
inflight hget(key: str, field: str): str
inflight hget(key: str, field: str): str?
```

Returns the value associated with field in the hash stored at key.
Expand Down Expand Up @@ -313,7 +313,7 @@ Removes the specified key.
##### `get` <a name="get" id="@winglang/sdk.ex.RedisClientBase.get"></a>

```wing
get(key: str): str
get(key: str): str?
```

Get value at given key.
Expand All @@ -327,7 +327,7 @@ Get value at given key.
##### `hget` <a name="hget" id="@winglang/sdk.ex.RedisClientBase.hget"></a>

```wing
hget(key: str, field: str): str
hget(key: str, field: str): str?
```

Returns the value associated with field in the hash stored at key.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/04-standard-library/ex/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ List all rows in the table.
##### `tryGet` <a name="tryGet" id="@winglang/sdk.ex.ITableClient.tryGet"></a>

```wing
inflight tryGet(key: str): Json
inflight tryGet(key: str): Json?
```

Get a row from the table if exists, by primary key.
Expand Down
Loading

0 comments on commit ffdc6b0

Please sign in to comment.