Skip to content

Commit

Permalink
Release 10.0.0 (#294)
Browse files Browse the repository at this point in the history
* Feature: allow passing "patch" option to "swagger2openapi" (#283)

Co-authored-by: cassel <xavier.cassel35@gmail.com>

* 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 <rcatoio@doubletrade.com>

* feat: add an option to disable throwing an error when request.ok is not true (#297)

Co-authored-by: rcatoio <rcatoio@doubletrade.com>
Co-authored-by: Sergey S. Volkov <js2me@outlook.com>

* 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 <js2me@outlook.com>

* 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 <filipekmarcin180@gmail.com>

* 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 <daniele@kuama.net>
Co-authored-by: Sergey S. Volkov <js2me@outlook.com>

* 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 <anders.cassidy@dailypay.com>
Co-authored-by: Daniel Playfair Cal <dcal@atlassian.com>
Co-authored-by: Sergey S. Volkov <js2me@outlook.com>

* 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 <js2me@outlook.com>

* 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 <57092100+xcassel@users.noreply.github.com>
Co-authored-by: cassel <xavier.cassel35@gmail.com>
Co-authored-by: Adrian Wieprzkowicz <Argeento@users.noreply.github.com>
Co-authored-by: EvgenBabenko <evgen.babenko@gmail.com>
Co-authored-by: RoCat <catoio.romain@gmail.com>
Co-authored-by: rcatoio <rcatoio@doubletrade.com>
Co-authored-by: 卡色 <cipchk@qq.com>
Co-authored-by: 江麻妞 <50100681+jiangmaniu@users.noreply.github.com>
Co-authored-by: Kasper Moskwiak <kasper.moskwiak@gmail.com>
Co-authored-by: Ben Watkins <ben@outdatedversion.com>
Co-authored-by: bonukai <bonukai@protonmail.com>
Co-authored-by: baggoedw <92381702+baggoedw@users.noreply.github.com>
Co-authored-by: Marcus Dunn <51931484+MarcusDunn@users.noreply.github.com>
Co-authored-by: Daniele De Matteo <daniele@kuama.net>
Co-authored-by: Daniel Playfair Cal <daniel.playfair.cal@gmail.com>
Co-authored-by: Anders Cassidy <anders.cassidy@dailypay.com>
Co-authored-by: Daniel Playfair Cal <dcal@atlassian.com>
  • Loading branch information
18 people authored Aug 15, 2022
1 parent 02b5a02 commit a6f16d7
Show file tree
Hide file tree
Showing 99 changed files with 41,116 additions and 7,725 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 100,
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "all"
}
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# next release

# 10.0.0

- `--extract-response-body` option - extract response body type to data contract
- `--extract-response-error` option - extract response error type to data contract
- `--add-readonly` option - generate readonly properties
- `authorizationToken` for axios fetch swagger schema request
- fix: change COMPLEX_NOT_OF to COMPLEX_NOT (internal)
- feat: improve `@deprecated` jsdoc info
- feat: improve `required` field in complex data schemas (anyOf, oneOf, allOf etc)
- feat: abortSignal for fetch http client
- chore: improve typings in index.d.ts
- fixed [Request falls if FormData attachment is File instance](https://github.com/acacode/swagger-typescript-api/issues/293)
- fixed [Response format - global default or override ?](https://github.com/acacode/swagger-typescript-api/issues/251)

> Co-authored-by: Sergey S. Volkov <js2me@outlook.com>
> Co-authored-by: Xavier Cassel <57092100+xcassel@users.noreply.github.com>
> Co-authored-by: cassel <xavier.cassel35@gmail.com>
> Co-authored-by: Adrian Wieprzkowicz <Argeento@users.noreply.github.com>
> Co-authored-by: EvgenBabenko <evgen.babenko@gmail.com>
> Co-authored-by: RoCat <catoio.romain@gmail.com>
> Co-authored-by: rcatoio <rcatoio@doubletrade.com>
> Co-authored-by: 卡色 <cipchk@qq.com>
> Co-authored-by: 江麻妞 <50100681+jiangmaniu@users.noreply.github.com>
> Co-authored-by: Kasper Moskwiak <kasper.moskwiak@gmail.com>
> Co-authored-by: Ben Watkins <ben@outdatedversion.com>
> Co-authored-by: bonukai <bonukai@protonmail.com>
> Co-authored-by: baggoedw <92381702+baggoedw@users.noreply.github.com>
> Co-authored-by: Marcus Dunn <51931484+MarcusDunn@users.noreply.github.com>
> Co-authored-by: Daniele De Matteo <daniele@kuama.net>
> Co-authored-by: Daniel Playfair Cal <daniel.playfair.cal@gmail.com>
> Co-authored-by: Anders Cassidy <anders.cassidy@dailypay.com>
> Co-authored-by: Daniel Playfair Cal <dcal@atlassian.com>
# 9.2.0

Features:
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ Any questions you can ask [**here**](https://github.com/acacode/swagger-typescri

<br>

![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)
![](https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/components-converter-example.jpg)

👀 This project is looking for a code maintainer 👀
P.S. If you are creating the PR, please check your changes with using command `npm run prepare`
P.S. If you want to contribute please use branch `next`. All PRs which will have target `master` will be declined

## 👀 Examples

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

Also you can use `npx`:
Expand Down Expand Up @@ -99,7 +105,7 @@ generateApi({
toJS: false,
extractRequestParams: false,
extractRequestBody: false,
prettier: {
prettier: { // By default prettier config is load from your project
printWidth: 120,
tabWidth: 2,
trailingComma: "all",
Expand Down
113 changes: 56 additions & 57 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
interface GenerateApiParams {
/**
* path to swagger schema
*/
input: string;

/**
* url to swagger schema
*/
url: string;

/**
* swagger schema JSON
*/
spec: import("swagger-schema-official").Spec;

interface GenerateApiParamsBase {
/**
* default 'api.ts'
*/
Expand All @@ -25,7 +10,7 @@ interface GenerateApiParams {
output?: string;

/**
* path to folder containing templates (default: ./scr/templates)
* path to folder containing templates (default: ./src/templates)
*/
templates?: string;

Expand Down Expand Up @@ -88,6 +73,18 @@ interface GenerateApiParams {
* extract request params to data contract (Also combine path params and query params into one object)
*/
extractRequestParams?: boolean;
/**
* extract request body type to data contract
*/
extractRequestBody?: boolean;
/**
* extract response body type to data contract
*/
extractResponseBody?: boolean;
/**
* extract response error type to data contract
*/
extractResponseError?: boolean;
/**
* prettier configuration
*/
Expand All @@ -112,8 +109,40 @@ interface GenerateApiParams {
* extra templates
*/
extraTemplates?: { name: string; path: string }[];

/**
* fix up small errors in the swagger source definition
*/
patch?: boolean;
/**
* authorization token
*/
authorizationToken?: string;
}

interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
/**
* path to swagger schema
*/
input: string;
}

interface GenerateApiParamsFromUrl extends GenerateApiParamsBase {
/**
* url to swagger schema
*/
url: string;
}

interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
/**
* swagger schema JSON
*/
spec: import("swagger-schema-official").Spec;
}

export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral;

export interface Hooks {
/** calls after parse schema component */
onCreateComponent: (component: SchemaComponent) => SchemaComponent | void;
Expand All @@ -126,14 +155,9 @@ export interface Hooks {
/** customize configuration object before sending it to ETA templates */
onPrepareConfig?: <C extends GenerateApiConfiguration>(currentConfiguration: C) => C | void;
/** customize route name as you need */
onCreateRouteName?: (
routeNameInfo: RouteNameInfo,
rawRouteInfo: RawRouteInfo,
) => RouteNameInfo | void;
onCreateRouteName?: (routeNameInfo: RouteNameInfo, rawRouteInfo: RawRouteInfo) => RouteNameInfo | void;
/** customize request params (path params, query params) */
onCreateRequestParams?: (
rawType: SchemaComponent["rawTypeData"],
) => SchemaComponent["rawTypeData"] | void;
onCreateRequestParams?: (rawType: SchemaComponent["rawTypeData"]) => SchemaComponent["rawTypeData"] | void;
/** customize name of model type */
onFormatTypeName?: (typeName: string, rawTypeName?: string) => string | void;
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
Expand Down Expand Up @@ -210,14 +234,10 @@ export interface SchemaComponent {
discriminator?: {
propertyName?: string;
};
$parsed: ParsedSchema<
SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
>;
$parsed: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent>;
};
componentName: string;
typeData: ParsedSchema<
SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
> | null;
typeData: ParsedSchema<SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent> | null;
}

export enum RequestContentKind {
Expand Down Expand Up @@ -323,6 +343,7 @@ export interface GenerateApiConfiguration {
routeName: string;
};
routeNameDuplicatesMap: Map<string, string>;
apiClassName: string
};
modelTypes: ModelType[];
rawModelTypes: SchemaComponent[];
Expand All @@ -341,25 +362,16 @@ export interface GenerateApiConfiguration {
formatDescription: (description: string, inline?: boolean) => string;
internalCase: (value: string) => string;
classNameCase: (value: string) => string;
getInlineParseContent: (
rawTypeData: SchemaComponent["rawTypeData"],
typeName?: string,
) => string;
getInlineParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => string;
getParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
getComponentByRef: (ref: string) => SchemaComponent;
parseSchema: (
rawSchema: string | SchemaComponent["rawTypeData"],
typeName?: string,
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
) => ModelType;
formatters: Record<
MAIN_SCHEMA_TYPES,
(content: string | object | string[] | object[]) => string
>;
inlineExtraFormatters: Record<
Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>,
(schema: ModelType) => string
>;
formatters: Record<MAIN_SCHEMA_TYPES, (content: string | object | string[] | object[]) => string>;
inlineExtraFormatters: Record<Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>, (schema: ModelType) => string>;
formatModelName: (name: string) => string;
fmtToJSDocLine: (line: string, params?: { eol?: boolean }) => string;
_: import("lodash").LoDashStatic;
Expand All @@ -370,12 +382,7 @@ export interface GenerateApiConfiguration {
export interface GenerateApiOutput {
configuration: GenerateApiConfiguration;
files: { name: string; content: string; declaration: { name: string; content: string } | null }[];
createFile: (params: {
path: string;
fileName: string;
content: string;
withPrefix?: boolean;
}) => void;
createFile: (params: { path: string; fileName: string; content: string; withPrefix?: boolean }) => void;
renderTemplate: (
templateContent: string,
data: Record<string, unknown>,
Expand All @@ -385,12 +392,4 @@ export interface GenerateApiOutput {
formatTSContent: (content: string) => string;
}

export declare function generateApi(
params: Omit<GenerateApiParams, "url" | "spec">,
): Promise<GenerateApiOutput>;
export declare function generateApi(
params: Omit<GenerateApiParams, "input" | "spec">,
): Promise<GenerateApiOutput>;
export declare function generateApi(
params: Omit<GenerateApiParams, "input" | "url">,
): Promise<GenerateApiOutput>;
export declare function generateApi(params: GenerateApiParams): Promise<GenerateApiOutput>;
Loading

0 comments on commit a6f16d7

Please sign in to comment.