Skip to content

Commit

Permalink
fix(apim): change swagger-jsdoc part in README file (#1145)
Browse files Browse the repository at this point in the history
* fix(apim): change swagger-jsdoc part in README file

* fix(apim): update openapi/index.js

* docs(apim): remove swagger-jsdoc recommendation

* fix(apim): fix wording according to comments
  • Loading branch information
XiaofuHuang authored May 24, 2021
1 parent 8b20032 commit 208ff56
Showing 1 changed file with 3 additions and 55 deletions.
58 changes: 3 additions & 55 deletions packages/fx-core/templates/plugins/resource/apim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,62 +50,9 @@ In the deployment step, there will be some inputs needed:
> Note: This may incur costs in your Azure Subscription if you choose to create a new instance in pervious step.
## Write OpenAPI Document
We support both yaml and json format for the OpenAPI document. You need to follow the [OpenAPI Specification](https://swagger.io/resources/open-api/), author the OpenAPI document and ensure the API schema is aligned with the Azure Functions HTTP trigger implementation.

Update the Open API document under the `openapi` folder. We support both yaml and json format for the Open API document. You need to author the Open API document and ensure the API schema is aligned with the function implementation. For how to generate the Open API document, we have the following recommendations.

### Recommended way 1: Using npm package swagger-jsdoc

- Run command: `npm install -g swagger-jsdoc`.
- Annotating source code. Read [more](https://github.com/Surnet/swagger-jsdoc/) about how to use swagger-jsdoc to annotate the source code. Below is a sample annotation.
- API annotation
```js
/**
* @openapi
* /getUserProfile:
* get:
* summary: Get User Profile
* operationId: get-user-profile
* responses:
* '200':
* $ref: "#/components/responses/getUserProfileResponse"
*/
```
- Response annotation
```js
/**
* @openapi
* components:
* responses:
* getUserProfileResponse:
* description: 200 response
* content:
* application/json:
* schema:
* type: object
* properties:
* receivedHTTPRequestBody:
* type: string
* userInfoMessage:
* type: string
* graphClientMessage:
* type: object
*/
```
- Create an OpenAPI definition file `openapi/openapi.definition.json` and input the title and version. Below is a sample definition file.
```json
{
"openapi": "3.0.1",
"info": {
"title": "{appName}",
"version": "v1"
}
}
```
- Run command `swagger-jsdoc -d ./openapi/openapi.definition.json -o ./openapi/openapi.json ./api/getUserProfile/*`. Please change the file path `./api/getUserProfile/*` according to your modification.

### Recommended way 2: OpenAPI (Swagger) Editor in VS Code.

Below is a sample swagger file for the default http trigger function. You can copy the content into `./openapi/openapi.json`, follow the [OpenAPI Specification](https://swagger.io/resources/open-api/), and change the content according to your modification (E.g. `/getUserProfile` -> `/$yourFunctionName` ).
Below is a sample swagger file for the default HTTP trigger function. You can copy the content into `./openapi/openapi.json`, and change the content according to your modification (E.g. `/getUserProfile` -> `/$yourFunctionName` ).

```json
{
Expand Down Expand Up @@ -147,6 +94,7 @@ Below is a sample swagger file for the default http trigger function. You can co
}
}
```
You can use your favorite tool to generate an OpenAPI document, such as [OpenAPI (Swagger) Editor](https://marketplace.visualstudio.com/items?itemName=42Crunch.vscode-openapi) and [swagger-jsdoc](https://github.com/Surnet/swagger-jsdoc/).

## Documentation

Expand Down

0 comments on commit 208ff56

Please sign in to comment.