Skip to content

Commit

Permalink
ci: added typescript generation (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
emajo authored Mar 30, 2022
1 parent 30ef185 commit 1de6c2e
Show file tree
Hide file tree
Showing 7 changed files with 778 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/generate-typescript-axios.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Generate TypeScript SDK
on:
repository_dispatch:
types: [generate-typescript-axios]

jobs:
generate-typescript-sdk:
runs-on: ubuntu-latest
env:
GIT_REPO_ID: fattureincloud-ts-sdk
GIT_USER_ID: fattureincloud
steps:

- id: checkout
name: Checkout repo
uses: actions/checkout@v2
with:
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}

- id: checkout-ts
name: Checkout TypeScript repo
env:
GIT_REPO_PATH: '${{ env.GIT_USER_ID }}/${{ env.GIT_REPO_ID }}'
uses: actions/checkout@v2
with:
path: ./generated/typescript-axios
ref: master
repository: ${{ env.GIT_REPO_PATH }}
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}

- id: init-git
name: Init GIT
run: |
git config --global user.email "[email protected]"
git config --global user.name "fattureincloud-bot"
- id: setup-node
name: Setup Node.js
uses: actions/setup-node@v2

- id: setup-java
name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'

- id: setup-libraries
name: Install libraries
run: |
npm install -g yarn
yarn global add @apidevtools/swagger-cli @openapitools/openapi-generator-cli standard-version
sudo add-apt-repository ppa:rmescandon/yq -y
sudo apt update
sudo apt install yq -y
cd ./scripts/
yarn
cd ../generated/typescript-axios/scripts
yarn
- id: bump-typescript-sdk-version
name: Bump C# SDK
env:
OPENAPI_VERSION: ${{ github.event.client_payload.version }}
run: |
echo "openapi_version=$OPENAPI_VERSION"
BUMP_TYPE=$(node ./scripts/sdk-version-checker.js ./generated/typescript-axios/sdk-version.yaml $OPENAPI_VERSION)
cd ./generated/typescript-axios
if [ "$BUMP_TYPE" == "patch" ];then
echo 'Bumping the SDK patch version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as patch
elif [ "$BUMP_TYPE" == "openapi" ];then
echo 'Using the openapi version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as $OPENAPI_VERSION
else
echo "Something bad happened - impossible to bump C# SDK version. value=$BUMP_TYPE"
fi
SDK_VERSION=$(yq e '.info.version' ./sdk-version.yaml)
echo "sdk_version=$SDK_VERSION" >> $GITHUB_ENV
echo "openapi_version=$OPENAPI_VERSION" >> $GITHUB_ENV
- id: delete-old-files
name: Delete old files
run: |
rm -rf ./generated/typescript-axios/src
rm -rf ./generated/typescript-axios/docs
rm -rf ./generated/typescript-axios-docs
- id: generate-typescript-axios
name: Generate TypeScript SDK
env:
PACKAGE_NAME: "@fattureincloud/fattureincloud-ts-sdk"
APP_NAME: "FattureInCloud"
run: |
SDK_VERSION=${{ env.sdk_version }}
echo "${{ env.sdk_version }}"
RELEASE_NOTE="\"bumping version to $SDK_VERSION\""
USER_AGENT="$APP_NAME/${{ env.sdk_version }}/TypeScript-SDK"
openapi-generator-cli generate -i ./openapi.yaml -g typescript-axios -o generated/typescript-axios/ -t ./templates/typescript-axios --additional-properties=npmName=${PACKAGE_NAME},npmVersion=${SDK_VERSION},supportsES6=true,withNodeImports=true,withSeparateModelsAndApi=true,apiPackage=src/api,modelPackage=src/models,withInterfaces=true --git-repo-id=${GIT_REPO_ID} --git-user-id=${GIT_USER_ID} --release-note=${RELEASE_NOTE} --http-user-agent=${USER_AGENT}
- id: generate-typescript-axios-docs
name: Generate Docs
run: openapi-generator-cli generate -i ./openapi.yaml -g javascript -o generated/typescript-axios-docs/ -t ./templates/typescript-axios-docs

- id: move-docs
name: Moving Docs To The Right Folder
run: mv ./generated/typescript-axios-docs/docs ./generated/typescript-axios

- id: create-pr
name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
path: ./generated/typescript-axios
branch: "devel-${{ env.sdk_version }}"
token: "${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}"
delete-branch: true
base: master
commit-message: "chore: bumping version to ${{ env.sdk_version }}"
title: "Updating SDK to ${{ env.sdk_version }}"
body: "New SDK verson ${{ env.sdk_version }} generated by Github Action from OpenAPI Spec ${{ env.openapi_version }}"
76 changes: 76 additions & 0 deletions templates/typescript-axios-docs/api_doc.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# {{classname}}{{#description}}

{{.}}{{/description}}

All URIs are relative to *{{basePath}}*

Method | HTTP request | Description
------------- | ------------- | -------------
{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}}
{{/operation}}{{/operations}}

{{#operations}}
{{#operation}}

## {{operationId}}

> {{#returnType}}{{.}} {{/returnType}}{{operationId}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}})

{{summary}}{{#notes}}

{{.}}{{/notes}}

### Example

```javascript
import { Configuration, {{{classname}}} {{#optionalParams}}{{^isPrimitiveType}}, {{{dataType}}}{{/isPrimitiveType}}{{/optionalParams}} } from '@fattureincloud/fattureincloud-ts-sdk';

// Configure OAuth2 access token for authorization: {{{name}}}
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN"
});

let apiInstance = new {{{classname}}}(apiConfig);
{{#requiredParams}}
let {{{paramName}}}{{^isPrimitiveType}}: {{{dataType}}}{{/isPrimitiveType}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/requiredParams}}
{{#optionalParams}}
{{#-first}}

{{/-first}}
let {{{paramName}}}{{^isPrimitiveType}}: {{{dataType}}}{{/isPrimitiveType}} = {{{example}}}{{^-last}},{{/-last}} // {{{dataType}}} | {{{description}}}
{{#-last}}

{{/-last}}
{{/optionalParams}}
apiInstance.{{{operationId}}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}{{{paramName}}}{{/-last}}{{/optionalParams}}).then(({{#returnType}}data{{/returnType}}) => {
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
}, (error) => {
console.error(error);
});

```

### Parameters

{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
{{#allParams}} **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^required}}[optional] {{/required}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}}
{{/allParams}}

### Return type

{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}

### Authorization

{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}

### HTTP request headers

- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}

{{/operation}}
{{/operations}}
26 changes: 26 additions & 0 deletions templates/typescript-axios-docs/model_doc.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#models}}{{#model}}{{#isEnum}}# {{classname}}

## Enum

{{#allowableValues}}{{#enumVars}}
* `{{name}}` (value: `{{{value}}}`)
{{/enumVars}}{{/allowableValues}}
{{/isEnum}}{{^isEnum}}# {{classname}}

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}}
{{/vars}}
{{#vars}}{{#isEnum}}


## Enum: {{datatypeWithEnum}}

{{#allowableValues}}{{#enumVars}}
* `{{name}}` (value: `{{{value}}}`)
{{/enumVars}}{{/allowableValues}}

{{/isEnum}}{{/vars}}
{{/isEnum}}{{/model}}{{/models}}
113 changes: 113 additions & 0 deletions templates/typescript-axios/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# FattureInCloud TypeScript SDK

[![NPM](https://img.shields.io/npm/v/@fattureincloud/fattureincloud-ts-sdk?color=g)](https://www.npmjs.com/package/@fattureincloud/fattureincloud-ts-sdk) ![unit tests](https://github.com/fattureincloud/fattureincloud-ts-sdk/actions/workflows/validate.yml/badge.svg)

{{npmName}} - TypeScript/JavaScript client for Fatture in Cloud API.

## {{npmName}}@{{npmVersion}}

This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{appVersion}}
- Package version: {{npmVersion}}

Module system
* CommonJS
* ES6 module system

It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))


{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Installation

### For [Node.js](https://nodejs.org/)

Using npm:

```shell
npm install {{{npmName}}}
```

Using yarn:

```shell
yarn add {{{npmName}}}
```

## Getting Started

Please follow the [installation](#installation) instruction and execute the following TS code:

```javascript
import { Configuration, ArchiveApi , CreateArchiveDocumentRequest } from '@fattureincloud/fattureincloud-ts-sdk';

// Configure OAuth2 access token for authorization:
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN"
});

let apiInstance = new ArchiveApi(apiConfig);
let companyId = 12345; // Number | The ID of the company.

let createArchiveDocumentRequest: CreateArchiveDocumentRequest = {"data":{"date":"2021-08-20","category":"Altri documenti","description":"spesa 1","attachment_token":"ibfjdbf94ey9w94g3w894qbasrga"}} // CreateArchiveDocumentRequest | The Archive Document.

apiInstance.createArchiveDocument(companyId, createArchiveDocumentRequest).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```

## Documentation for API Endpoints

All URIs are relative to *{{basePath}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation for Models

{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md)
{{/model}}{{/models}}

## Documentation for Authorization

{{^authMethods}}
All endpoints do not require authorization.
{{/authMethods}}
{{#authMethods}}
{{#last}} Authentication schemes defined for the API:{{/last}}

### {{name}}

{{#isApiKey}}

- **Type**: API key
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}

- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - _{{scope}}_: {{description}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}
Loading

0 comments on commit 1de6c2e

Please sign in to comment.