Skip to content

Commit

Permalink
chore: updating templates for typescript-axios sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
valmoz authored and fattureincloud-bot committed Jul 1, 2024
1 parent e338610 commit 0d149ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 125 deletions.
117 changes: 25 additions & 92 deletions templates/openapi-generator/typescript-axios/README.mustache
Original file line number Diff line number Diff line change
@@ -1,113 +1,46 @@
# 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:
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:

- API version: {{appVersion}}
- Package version: {{npmVersion}}
Environment
* Node.js
* Webpack
* Browserify

Language level
* ES5 - you must have a Promises/A+ library installed
* ES6

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}}
It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))

## Installation
### Building

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

Using npm:

```shell
npm install {{{npmName}}}
To build and compile the typescript sources to javascript use:
```

Using yarn:

```shell
yarn add {{{npmName}}}
npm install
npm run build
```

## Getting Started

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

```javascript
import { Configuration, ArchiveApi , CreateArchiveDocumentRequest } from '@fattureincloud/fattureincloud-ts-sdk';
First build the package then run `npm publish`

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

let apiInstance = new ArchiveApi(apiConfig);
let companyId = 12345; // Number | The ID of the company.
navigate to the folder of your consuming project and run one of the following commands.

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

apiInstance.createArchiveDocument(companyId, createArchiveDocumentRequest).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
npm install {{npmName}}@{{npmVersion}} --save
```

## Documentation for API Endpoints

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

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

## Documentation for Models

{{#models}}{{#model}} - [{{classname}}](docs/{{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}}
_unPublished (not recommended):_

{{/authMethods}}
```
npm install PATH_TO_GENERATED_PACKAGE --save
```
13 changes: 7 additions & 6 deletions templates/openapi-generator/typescript-axios/apiInner.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import globalAxios from 'axios';
// URLSearchParams not necessarily used
// @ts-ignore
import { URL, URLSearchParams } from 'url';
{{#multipartFormData}}
import FormData from 'form-data'
{{/multipartFormData}}
{{/withNodeImports}}
// Some imports not used depending on template conditions
// @ts-ignore
Expand Down Expand Up @@ -187,14 +189,14 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{#isArray}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{#contentType}}
{{#contentType}}
localVarFormParams.append('{{baseName}}', new Blob([JSON.stringify({{paramName}})], { type: "{{contentType}}", }));
{{/contentType}}
{{^contentType}}
{{/contentType}}
{{^contentType}}
{{paramName}}.forEach((element) => {
localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', element as any);
localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', element as any);
})
{{/contentType}}
{{/contentType}}
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
localVarFormParams.{{#multipartFormData}}append{{/multipartFormData}}{{^multipartFormData}}set{{/multipartFormData}}('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}));
Expand All @@ -220,7 +222,6 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{#consumes.0}}
localVarHeaderParameter['Content-Type'] = '{{{mediaType}}}';
{{/consumes.0}}
localVarHeaderParameter['User-Agent'] = 'FattureInCloud/{{{npmVersion}}}/TypeScript-SDK';
{{/bodyParam}}
setSearchParams(localVarUrlObj, localVarQueryParameter);
Expand Down
2 changes: 0 additions & 2 deletions templates/openapi-generator/typescript-axios/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
export * from "./api";
export * from "./configuration";
{{#withSeparateModelsAndApi}}export * from "./{{tsModelPackage}}";{{/withSeparateModelsAndApi}}
export * from "./src/filter";
export * from "./src/oauth2";
35 changes: 11 additions & 24 deletions templates/openapi-generator/typescript-axios/package.mustache
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
{
"name": "{{npmName}}",
"version": "{{npmVersion}}",
"description": "TypeScript SDK for the Fatture in Cloud API",
"author": "Fatture in Cloud API Team",
"description": "OpenAPI client for {{npmName}}",
"author": "OpenAPI-Generator Contributors",
"repository": {
"type": "git",
"url": "https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}.git"
},
"keywords": [
"axios",
"typescript",
"openapi-client",
"openapi-generator",
"{{npmName}}"
],
"license": "MIT",
"license": "Unlicense",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
{{#supportsES6}}
"module": "./dist/esm/index.js",
"sideEffects": false,
{{/supportsES6}}
"scripts": {
"build": "tsc {{#supportsES6}}&& tsc -p tsconfig.esm.json{{/supportsES6}}",
"prepare": "npm run build",
"test": "mocha -r ts-node/register 'test/**/*.ts'"
"build": "tsc{{#supportsES6}} && tsc -p tsconfig.esm.json{{/supportsES6}}",
"prepare": "npm run build"
},
"dependencies": {
"axios": "^1.6.1",
"form-data": "^4.0.0"
"axios": "^1.6.1"
},
"devDependencies": {
"@types/node": "12.11.5 - 12.20.42",
"typescript": "^4.0 || ^5.0",
"ts-node": "^10.7.0",
"chai": "^4.3.6",
"@types/chai": "^4.3.0",
"mocha": "^8.0.1",
"@types/mocha": "^9.1.0",
"sinon": "^7.2.0",
"@types/sinon": "^10.0.11",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.14.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0"
"typescript": "^4.0 || ^5.0"
}{{#npmRepository}},{{/npmRepository}}
{{#npmRepository}}
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"declaration": true,
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
"module": "commonjs",
"esModuleInterop": true,
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
Expand Down

0 comments on commit 0d149ea

Please sign in to comment.