Skip to content

Commit a6f16d7

Browse files
js2mexcasselCasselXArgeentoEvgenBabenko
authored
Release 10.0.0 (#294)
* Feature: allow passing "patch" option to "swagger2openapi" (#283) Co-authored-by: cassel <[email protected]> * Loads prettier config from user's project (#286) * fix: problem with missing HttpResponse type with --to-js option * fix: missing extractRequestBody field in type * fix(reject): fix reject and exit with code 1 if error (#295) * fix(reject): fix reject and exit with code 1 if error * feat: add a parameter to sort types and types properties (#299) Co-authored-by: rcatoio <[email protected]> * feat: add an option to disable throwing an error when request.ok is not true (#297) Co-authored-by: rcatoio <[email protected]> Co-authored-by: Sergey S. Volkov <[email protected]> * fix: fix missing `title` of object type (#303) * chore: refresh auto generated code; chore: add axios to dev deps * bump: up to 9.3.0 * bump: up to 9.3.1; fix: axios * chore: fix typo (#376) * 304 Support readOnly properties (#365) * allow mutually exclusive input options (#327) Co-authored-by: Sergey S. Volkov <[email protected]> * Update fetch-http-client.eta (#329) * BREAKING_CHANGE: add --extract-response-body option; bump: version to 9.4.0 * feat: added authorization token to headers Co-authored-by: MarcinFilipek <[email protected]> * feat: --extract-response-error option * chore: refresh code gen tests * fix: change COMPLEX_NOT_OF to COMPLEX_NOT (#356) * Fix request format and allow for files in request - With code review changes (#350) * fix pick format allow for file array in form data requests * fixed code review suggestions Co-authored-by: Daniele De Matteo <[email protected]> Co-authored-by: Sergey S. Volkov <[email protected]> * Pass through required properties to allOf/anyOf/oneOf children (#342) * Pass through required properties to allOf children * extend fix to anyOf and oneOf * fix: account for children making parent fields required Co-authored-by: Anders Cassidy <[email protected]> Co-authored-by: Daniel Playfair Cal <[email protected]> Co-authored-by: Sergey S. Volkov <[email protected]> * Add option to change main Api class name (#320) * Update api.eta * Update index.d.ts * Update index.js * Update index.js * Update config.js Co-authored-by: Sergey S. Volkov <[email protected]> * fix: missing stringifyFormItem method; bump: up version to 10.0.0 * docs: update docs, changelog, fix: problem with complex types (makeAddRequiredToChildSchema) Co-authored-by: Xavier Cassel <[email protected]> Co-authored-by: cassel <[email protected]> Co-authored-by: Adrian Wieprzkowicz <[email protected]> Co-authored-by: EvgenBabenko <[email protected]> Co-authored-by: RoCat <[email protected]> Co-authored-by: rcatoio <[email protected]> Co-authored-by: 卡色 <[email protected]> Co-authored-by: 江麻妞 <[email protected]> Co-authored-by: Kasper Moskwiak <[email protected]> Co-authored-by: Ben Watkins <[email protected]> Co-authored-by: bonukai <[email protected]> Co-authored-by: baggoedw <[email protected]> Co-authored-by: Marcus Dunn <[email protected]> Co-authored-by: Daniele De Matteo <[email protected]> Co-authored-by: Daniel Playfair Cal <[email protected]> Co-authored-by: Anders Cassidy <[email protected]> Co-authored-by: Daniel Playfair Cal <[email protected]>
1 parent 02b5a02 commit a6f16d7

File tree

99 files changed

+41116
-7725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+41116
-7725
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 100,
2+
"printWidth": 120,
33
"tabWidth": 2,
44
"trailingComma": "all"
55
}

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# next release
22

3+
# 10.0.0
4+
5+
- `--extract-response-body` option - extract response body type to data contract
6+
- `--extract-response-error` option - extract response error type to data contract
7+
- `--add-readonly` option - generate readonly properties
8+
- `authorizationToken` for axios fetch swagger schema request
9+
- fix: change COMPLEX_NOT_OF to COMPLEX_NOT (internal)
10+
- feat: improve `@deprecated` jsdoc info
11+
- feat: improve `required` field in complex data schemas (anyOf, oneOf, allOf etc)
12+
- feat: abortSignal for fetch http client
13+
- chore: improve typings in index.d.ts
14+
- fixed [Request falls if FormData attachment is File instance](https://github.com/acacode/swagger-typescript-api/issues/293)
15+
- fixed [Response format - global default or override ?](https://github.com/acacode/swagger-typescript-api/issues/251)
16+
17+
> Co-authored-by: Sergey S. Volkov <[email protected]>
18+
> Co-authored-by: Xavier Cassel <[email protected]>
19+
> Co-authored-by: cassel <[email protected]>
20+
> Co-authored-by: Adrian Wieprzkowicz <[email protected]>
21+
> Co-authored-by: EvgenBabenko <[email protected]>
22+
> Co-authored-by: RoCat <[email protected]>
23+
> Co-authored-by: rcatoio <[email protected]>
24+
> Co-authored-by: 卡色 <[email protected]>
25+
> Co-authored-by: 江麻妞 <[email protected]>
26+
> Co-authored-by: Kasper Moskwiak <[email protected]>
27+
> Co-authored-by: Ben Watkins <[email protected]>
28+
> Co-authored-by: bonukai <[email protected]>
29+
> Co-authored-by: baggoedw <[email protected]>
30+
> Co-authored-by: Marcus Dunn <[email protected]>
31+
> Co-authored-by: Daniele De Matteo <[email protected]>
32+
> Co-authored-by: Daniel Playfair Cal <[email protected]>
33+
> Co-authored-by: Anders Cassidy <[email protected]>
34+
> Co-authored-by: Daniel Playfair Cal <[email protected]>
35+
336
# 9.2.0
437

538
Features:

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Any questions you can ask [**here**](https://github.com/acacode/swagger-typescri
1919

2020
<br>
2121

22-
![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)
22+
![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)
23+
24+
👀 This project is looking for a code maintainer 👀
25+
P.S. If you are creating the PR, please check your changes with using command `npm run prepare`
26+
P.S. If you want to contribute please use branch `next`. All PRs which will have target `master` will be declined
2327

2428
## 👀 Examples
2529

@@ -38,32 +42,34 @@ Options:
3842
-n, --name <name> name of output typescript api file (default: "Api.ts")
3943
-t, --templates <path> path to folder containing templates
4044
-d, --default-as-success use "default" response status code as success response too.
41-
some swagger schemas use "default" response status code
42-
as success response type by default. (default: false)
45+
some swagger schemas use "default" response status code as success response type by default. (default: false)
4346
-r, --responses generate additional information about request responses
4447
also add typings for bad responses (default: false)
4548
--union-enums generate all "enum" types as union types (T1 | T2 | TN) (default: false)
49+
--add-readonly generate readonly properties (default: false)
4650
--route-types generate type definitions for API routes (default: false)
4751
--no-client do not generate an API class
4852
--enum-names-as-values use values in 'x-enumNames' as enum values (not only as keys) (default: false)
49-
--js generate js api module with declaration file (default: false)
50-
--extract-request-params extract request params to data contract (default: false)
51-
Also combine path params and query params into one object
52-
--extract-request-body extract request body type to data contract (default: false)
53-
--module-name-index <number> determines which path index should be used for routes separation (default: 0)
54-
(example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)
55-
--module-name-first-tag splits routes based on the first tag
53+
--extract-request-params extract request params to data contract (Also combine path params and query params into one object) (default: false)
54+
--extract-request-body extract request body type to data contract (default: false)
55+
--extract-response-body extract response body type to data contract (default: false)
56+
--extract-response-error extract response error type to data contract (default: false)
5657
--modular generate separated files for http client, data contracts, and routes (default: false)
58+
--js generate js api module with declaration file (default: false)
59+
--module-name-index <number> determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites) (default: 0)
60+
--module-name-first-tag splits routes based on the first tag (default: false)
5761
--disableStrictSSL disabled strict SSL (default: false)
5862
--disableProxy disabled proxy (default: false)
59-
--clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
6063
--axios generate axios http client (default: false)
64+
--unwrap-response-data unwrap the data item from the response (default: false)
65+
--disable-throw-on-error Do not throw an error when response.ok is not true (default: false)
6166
--single-http-client Ability to send HttpClient instance to Api constructor (default: false)
6267
--silent Output only errors to console (default: false)
6368
--default-response <type> default type for empty response schema (default: "void")
6469
--type-prefix <string> data contract name prefix (default: "")
6570
--type-suffix <string> data contract name suffix (default: "")
66-
-h, --help display help for command
71+
--clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
72+
--patch fix up small errors in the swagger source definition (default: false)
6773
```
6874

6975
Also you can use `npx`:
@@ -99,7 +105,7 @@ generateApi({
99105
toJS: false,
100106
extractRequestParams: false,
101107
extractRequestBody: false,
102-
prettier: {
108+
prettier: { // By default prettier config is load from your project
103109
printWidth: 120,
104110
tabWidth: 2,
105111
trailingComma: "all",

index.d.ts

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
interface GenerateApiParams {
2-
/**
3-
* path to swagger schema
4-
*/
5-
input: string;
6-
7-
/**
8-
* url to swagger schema
9-
*/
10-
url: string;
11-
12-
/**
13-
* swagger schema JSON
14-
*/
15-
spec: import("swagger-schema-official").Spec;
16-
1+
interface GenerateApiParamsBase {
172
/**
183
* default 'api.ts'
194
*/
@@ -25,7 +10,7 @@ interface GenerateApiParams {
2510
output?: string;
2611

2712
/**
28-
* path to folder containing templates (default: ./scr/templates)
13+
* path to folder containing templates (default: ./src/templates)
2914
*/
3015
templates?: string;
3116

@@ -88,6 +73,18 @@ interface GenerateApiParams {
8873
* extract request params to data contract (Also combine path params and query params into one object)
8974
*/
9075
extractRequestParams?: boolean;
76+
/**
77+
* extract request body type to data contract
78+
*/
79+
extractRequestBody?: boolean;
80+
/**
81+
* extract response body type to data contract
82+
*/
83+
extractResponseBody?: boolean;
84+
/**
85+
* extract response error type to data contract
86+
*/
87+
extractResponseError?: boolean;
9188
/**
9289
* prettier configuration
9390
*/
@@ -112,8 +109,40 @@ interface GenerateApiParams {
112109
* extra templates
113110
*/
114111
extraTemplates?: { name: string; path: string }[];
112+
113+
/**
114+
* fix up small errors in the swagger source definition
115+
*/
116+
patch?: boolean;
117+
/**
118+
* authorization token
119+
*/
120+
authorizationToken?: string;
121+
}
122+
123+
interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
124+
/**
125+
* path to swagger schema
126+
*/
127+
input: string;
128+
}
129+
130+
interface GenerateApiParamsFromUrl extends GenerateApiParamsBase {
131+
/**
132+
* url to swagger schema
133+
*/
134+
url: string;
135+
}
136+
137+
interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
138+
/**
139+
* swagger schema JSON
140+
*/
141+
spec: import("swagger-schema-official").Spec;
115142
}
116143

144+
export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral;
145+
117146
export interface Hooks {
118147
/** calls after parse schema component */
119148
onCreateComponent: (component: SchemaComponent) => SchemaComponent | void;
@@ -126,14 +155,9 @@ export interface Hooks {
126155
/** customize configuration object before sending it to ETA templates */
127156
onPrepareConfig?: <C extends GenerateApiConfiguration>(currentConfiguration: C) => C | void;
128157
/** customize route name as you need */
129-
onCreateRouteName?: (
130-
routeNameInfo: RouteNameInfo,
131-
rawRouteInfo: RawRouteInfo,
132-
) => RouteNameInfo | void;
158+
onCreateRouteName?: (routeNameInfo: RouteNameInfo, rawRouteInfo: RawRouteInfo) => RouteNameInfo | void;
133159
/** customize request params (path params, query params) */
134-
onCreateRequestParams?: (
135-
rawType: SchemaComponent["rawTypeData"],
136-
) => SchemaComponent["rawTypeData"] | void;
160+
onCreateRequestParams?: (rawType: SchemaComponent["rawTypeData"]) => SchemaComponent["rawTypeData"] | void;
137161
/** customize name of model type */
138162
onFormatTypeName?: (typeName: string, rawTypeName?: string) => string | void;
139163
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
@@ -210,14 +234,10 @@ export interface SchemaComponent {
210234
discriminator?: {
211235
propertyName?: string;
212236
};
213-
$parsed: ParsedSchema<
214-
SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
215-
>;
237+
$parsed: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent>;
216238
};
217239
componentName: string;
218-
typeData: ParsedSchema<
219-
SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
220-
> | null;
240+
typeData: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent> | null;
221241
}
222242

223243
export enum RequestContentKind {
@@ -323,6 +343,7 @@ export interface GenerateApiConfiguration {
323343
routeName: string;
324344
};
325345
routeNameDuplicatesMap: Map<string, string>;
346+
apiClassName: string
326347
};
327348
modelTypes: ModelType[];
328349
rawModelTypes: SchemaComponent[];
@@ -341,25 +362,16 @@ export interface GenerateApiConfiguration {
341362
formatDescription: (description: string, inline?: boolean) => string;
342363
internalCase: (value: string) => string;
343364
classNameCase: (value: string) => string;
344-
getInlineParseContent: (
345-
rawTypeData: SchemaComponent["rawTypeData"],
346-
typeName?: string,
347-
) => string;
365+
getInlineParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => string;
348366
getParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
349367
getComponentByRef: (ref: string) => SchemaComponent;
350368
parseSchema: (
351369
rawSchema: string | SchemaComponent["rawTypeData"],
352370
typeName?: string,
353371
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
354372
) => ModelType;
355-
formatters: Record<
356-
MAIN_SCHEMA_TYPES,
357-
(content: string | object | string[] | object[]) => string
358-
>;
359-
inlineExtraFormatters: Record<
360-
Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>,
361-
(schema: ModelType) => string
362-
>;
373+
formatters: Record<MAIN_SCHEMA_TYPES, (content: string | object | string[] | object[]) => string>;
374+
inlineExtraFormatters: Record<Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>, (schema: ModelType) => string>;
363375
formatModelName: (name: string) => string;
364376
fmtToJSDocLine: (line: string, params?: { eol?: boolean }) => string;
365377
_: import("lodash").LoDashStatic;
@@ -370,12 +382,7 @@ export interface GenerateApiConfiguration {
370382
export interface GenerateApiOutput {
371383
configuration: GenerateApiConfiguration;
372384
files: { name: string; content: string; declaration: { name: string; content: string } | null }[];
373-
createFile: (params: {
374-
path: string;
375-
fileName: string;
376-
content: string;
377-
withPrefix?: boolean;
378-
}) => void;
385+
createFile: (params: { path: string; fileName: string; content: string; withPrefix?: boolean }) => void;
379386
renderTemplate: (
380387
templateContent: string,
381388
data: Record<string, unknown>,
@@ -385,12 +392,4 @@ export interface GenerateApiOutput {
385392
formatTSContent: (content: string) => string;
386393
}
387394

388-
export declare function generateApi(
389-
params: Omit<GenerateApiParams, "url" | "spec">,
390-
): Promise<GenerateApiOutput>;
391-
export declare function generateApi(
392-
params: Omit<GenerateApiParams, "input" | "spec">,
393-
): Promise<GenerateApiOutput>;
394-
export declare function generateApi(
395-
params: Omit<GenerateApiParams, "input" | "url">,
396-
): Promise<GenerateApiOutput>;
395+
export declare function generateApi(params: GenerateApiParams): Promise<GenerateApiOutput>;

0 commit comments

Comments
 (0)