Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apim): change swagger-jsdoc part in README file #1145

Merged
merged 4 commits into from
May 24, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 function implementation.
dooriya marked this conversation as resolved.
Show resolved Hide resolved

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 way to generate 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/).
dooriya marked this conversation as resolved.
Show resolved Hide resolved
dooriya marked this conversation as resolved.
Show resolved Hide resolved

## Documentation

Expand Down