Skip to content

Release 10.0.0 #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
be7dacf
Feature: allow passing "patch" option to "swagger2openapi" (#283)
xcassel Sep 20, 2021
97d945f
Loads prettier config from user's project (#286)
Argeento Sep 20, 2021
7d9b393
fix: problem with missing HttpResponse type with --to-js option
js2me Sep 20, 2021
4b24048
fix: missing extractRequestBody field in type
js2me Sep 20, 2021
2d090e7
fix(reject): fix reject and exit with code 1 if error (#295)
EvgenBabenko Sep 23, 2021
4627926
feat: add a parameter to sort types and types properties (#299)
RoCat Oct 4, 2021
5e24567
feat: add an option to disable throwing an error when request.ok is n…
RoCat Oct 4, 2021
8a1f994
fix: fix missing `title` of object type (#303)
cipchk Oct 7, 2021
56c8ed4
chore: refresh auto generated code; chore: add axios to dev deps
js2me Oct 22, 2021
7f643ee
bump: up to 9.3.0
js2me Oct 22, 2021
5817a95
bump: up to 9.3.1; fix: axios
js2me Oct 28, 2021
bf6fa61
chore: fix typo (#376)
jiangmaniu Aug 15, 2022
0a3d332
304 Support readOnly properties (#365)
kmoskwiak Aug 15, 2022
537e250
allow mutually exclusive input options (#327)
OutdatedVersion Aug 15, 2022
de1a7f3
Update fetch-http-client.eta (#329)
bonukai Aug 15, 2022
7092297
BREAKING_CHANGE: add --extract-response-body option; bump: version to…
js2me Aug 15, 2022
b2d876f
Merge remote-tracking branch 'origin/next' into next
js2me Aug 15, 2022
119dbd8
feat: added authorization token to headers
js2me Aug 15, 2022
cc6a0c8
feat: --extract-response-error option
js2me Aug 15, 2022
73a1b68
chore: refresh code gen tests
js2me Aug 15, 2022
3334480
fix: change COMPLEX_NOT_OF to COMPLEX_NOT (#356)
baggoedw Aug 15, 2022
f6c9046
Fix request format and allow for files in request - With code review …
MarcusDunn Aug 15, 2022
5a09a7a
Pass through required properties to allOf/anyOf/oneOf children (#342)
hedgepigdaniel Aug 15, 2022
8fd3126
Add option to change main Api class name (#320)
bonukai Aug 15, 2022
5f9190b
fix: missing stringifyFormItem method; bump: up version to 10.0.0
js2me Aug 15, 2022
72dd88f
docs: update docs, changelog, fix: problem with complex types (makeAd…
js2me Aug 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
> 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]>

# 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