Skip to content

Commit 18bb546

Browse files
authored
[typescript-axios] Ignore unused imports when using 'withSeparateModelsAndApi' (#13204)
* Add typescript-axios/with-separate-models-and-api-inheritance sample as test for #13203 * [typescript-axios] Add // @ts-ignore to imports in models if withSeparateModelsAndApi is set * [typescript-axios] Update samples
1 parent 7e4f3c9 commit 18bb546

File tree

20 files changed

+644
-0
lines changed

20 files changed

+644
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: typescript-axios
2+
outputDir: samples/client/others/typescript-axios/with-separate-models-and-api-inheritance
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-axios/with-separate-models-and-api-inheritance.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
5+
additionalProperties:
6+
apiPackage: api
7+
modelPackage: model
8+
withSeparateModelsAndApi: true

modules/openapi-generator/src/main/resources/typescript-axios/model.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44
{{#withSeparateModelsAndApi}}{{#hasAllOf}}{{#allOf}}
5+
// May contain unused imports in some cases
6+
// @ts-ignore
57
import { {{class}} } from './{{filename}}';{{/allOf}}{{/hasAllOf}}{{#hasOneOf}}{{#oneOf}}
8+
// May contain unused imports in some cases
9+
// @ts-ignore
610
import { {{class}} } from './{{filename}}';{{/oneOf}}{{/hasOneOf}}{{^hasAllOf}}{{^hasOneOf}}{{#imports}}
11+
// May contain unused imports in some cases
12+
// @ts-ignore
713
import { {{class}} } from './{{filename}}';{{/imports}}{{/hasOneOf}}{{/hasAllOf}}{{/withSeparateModelsAndApi}}
814
{{#models}}{{#model}}
915
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{#allOf}}{{#-first}}{{>modelAllOf}}{{/-first}}{{/allOf}}{{^isEnum}}{{^oneOf}}{{^allOf}}{{>modelGeneric}}{{/allOf}}{{/oneOf}}{{/isEnum}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
openapi: 3.0.1
3+
info:
4+
title: Example
5+
version: '1'
6+
paths: {}
7+
components:
8+
schemas:
9+
BranchDto:
10+
type: object
11+
properties:
12+
name:
13+
type: string
14+
AbstractUserDto:
15+
type: object
16+
properties:
17+
username:
18+
type: string
19+
branch:
20+
"$ref": "#/components/schemas/BranchDto"
21+
type:
22+
type: string
23+
discriminator:
24+
propertyName: type
25+
mapping:
26+
internal-authenticated: "#/components/schemas/InternalAuthenticatedUserDto"
27+
remote-authenticated: "#/components/schemas/RemoteAuthenticatedUserDto"
28+
InternalAuthenticatedUserDto:
29+
type: object
30+
allOf:
31+
- "$ref": "#/components/schemas/AbstractUserDto"
32+
RemoteAuthenticatedUserDto:
33+
type: object
34+
allOf:
35+
- "$ref": "#/components/schemas/AbstractUserDto"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.gitignore
2+
.npmignore
3+
api.ts
4+
base.ts
5+
common.ts
6+
configuration.ts
7+
git_push.sh
8+
index.ts
9+
model/abstract-user-dto.ts
10+
model/branch-dto.ts
11+
model/index.ts
12+
model/internal-authenticated-user-dto.ts
13+
model/remote-authenticated-user-dto.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.1.0-SNAPSHOT
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Example
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 1
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
17+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Example
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 1
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
import { Configuration } from "./configuration";
17+
// Some imports not used depending on template conditions
18+
// @ts-ignore
19+
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
20+
21+
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
22+
23+
/**
24+
*
25+
* @export
26+
*/
27+
export const COLLECTION_FORMATS = {
28+
csv: ",",
29+
ssv: " ",
30+
tsv: "\t",
31+
pipes: "|",
32+
};
33+
34+
/**
35+
*
36+
* @export
37+
* @interface RequestArgs
38+
*/
39+
export interface RequestArgs {
40+
url: string;
41+
options: AxiosRequestConfig;
42+
}
43+
44+
/**
45+
*
46+
* @export
47+
* @class BaseAPI
48+
*/
49+
export class BaseAPI {
50+
protected configuration: Configuration | undefined;
51+
52+
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
53+
if (configuration) {
54+
this.configuration = configuration;
55+
this.basePath = configuration.basePath || this.basePath;
56+
}
57+
}
58+
};
59+
60+
/**
61+
*
62+
* @export
63+
* @class RequiredError
64+
* @extends {Error}
65+
*/
66+
export class RequiredError extends Error {
67+
name: "RequiredError" = "RequiredError";
68+
constructor(public field: string, msg?: string) {
69+
super(msg);
70+
}
71+
}

0 commit comments

Comments
 (0)