Skip to content

Some chores #729

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 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ jobs:
- name: Install dependencies
run: yarn install --immutable

- name: Check formatting
run: yarn format:check

- name: Run the tests
run: yarn test-all
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"files": {
"ignore": [
"package.json",
"tests/**/*.json",
"tests/**/expected.ts",
"tests/**/expected/**",
"tests/**/generated/**",
"tests/**/schema.d.ts",
"tests/**/schema.js",
"tests/**/schema.ts"
]
],
"maxSize": 10000000
},
"formatter": {
"enabled": true,
Expand Down
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface GenerateApiParamsBase {
*/
name?: string;

/**
/**
* name of the main exported class
*/
apiClassName?: string;
Expand Down Expand Up @@ -181,7 +181,7 @@ interface GenerateApiParamsBase {
extractingOptions?: Partial<ExtractingOptions>;

/** configuration for fetching swagger schema requests */
requestOptions?: null | Partial<import("node-fetch").RequestInit>;
requestOptions?: null | Partial<RequestInit>;

/** ts compiler configuration object (for --to-js option) */
compilerTsConfig?: Record<string, any>;
Expand Down Expand Up @@ -682,7 +682,7 @@ export interface GenerateApiConfiguration {
};
routeNameDuplicatesMap: Map<string, string>;
apiClassName: string;
requestOptions?: import("node-fetch").RequestInit;
requestOptions?: RequestInit;
extractingOptions: ExtractingOptions;
};
modelTypes: ModelType[];
Expand All @@ -697,7 +697,7 @@ export interface GenerateApiConfiguration {
routes: ParsedRoute[];
}[];
};
requestOptions?: null | Partial<import("node-fetch").RequestInit>;
requestOptions?: null | Partial<RequestInit>;
utils: {
formatDescription: (description: string, inline?: boolean) => string;
internalCase: (value: string) => string;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"cli:help": "node index.js -h",
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
"cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
"format": "biome format --write .",
"format:check": "biome format .",
"generate": "node tests/generate.js",
"generate-extended": "node tests/generate-extended.js",
"node": "node swagger-test-cli/generate.js",
Expand Down
29 changes: 15 additions & 14 deletions templates/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# swagger-typescript-api
# swagger-typescript-api

# templates
# templates

Templates:
- `api.ejs` - *(generates file)* Api class module (locations: [default](https://github.com/acacode/swagger-typescript-api/tree/next/templates/default/api.ejs), [modular](https://github.com/acacode/swagger-typescript-api/tree/next/templates/modular/api.ejs))
- `data-contracts.ejs` - *(generates file)* all types (data contracts) from swagger schema (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/data-contracts.ejs))
- `http-client.ejs` - *(generates file)* HttpClient class module (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/http-client.ejs))
- `procedure-call.ejs` - *(subtemplate)* route in Api class (locations: [default](https://github.com/acacode/swagger-typescript-api/tree/next/templates/default/procedure-call.ejs), [modular](https://github.com/acacode/swagger-typescript-api/tree/next/templates/modular/procedure-call.ejs))
- `route-docs.ejs` - *(generates file)* documentation for route in Api class (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-docs.ejs))
- `route-name.ejs` - *(subtemplate)* route name for route in Api class (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-name.ejs))
- `route-type.ejs` - *(`--route-types` option)* *(subtemplate)* (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-type.ejs))
- `route-types.ejs` - *(`--route-types` option)* *(subtemplate)* (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-types.ejs)) - `data-contract-jsdoc.ejs` - *(subtemplate)* generates JSDOC for data contract (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/data-contract-jsdoc.ejs))
Templates:

[//]: # (- `enum-data-contract.ejs` - *&#40;subtemplate&#41;* generates `enum` data contract &#40;locations: [base]&#40;https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/enum-data-contract.ejs&#41;&#41;)
[//]: # (- `interface-data-contract.ejs` - *&#40;subtemplate&#41;* generates `interface` data contract &#40;locations: [base]&#40;https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/interface-data-contract.ejs&#41;&#41;)
[//]: # (- `type-data-contract.ejs` - *&#40;subtemplate&#41;* generates `type` data contract &#40;locations: [base]&#40;https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/type-data-contract.ejs&#41;&#41;)
- `api.ejs` - _(generates file)_ Api class module (locations: [default](https://github.com/acacode/swagger-typescript-api/tree/next/templates/default/api.ejs), [modular](https://github.com/acacode/swagger-typescript-api/tree/next/templates/modular/api.ejs))
- `data-contracts.ejs` - _(generates file)_ all types (data contracts) from swagger schema (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/data-contracts.ejs))
- `http-client.ejs` - _(generates file)_ HttpClient class module (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/http-client.ejs))
- `procedure-call.ejs` - _(subtemplate)_ route in Api class (locations: [default](https://github.com/acacode/swagger-typescript-api/tree/next/templates/default/procedure-call.ejs), [modular](https://github.com/acacode/swagger-typescript-api/tree/next/templates/modular/procedure-call.ejs))
- `route-docs.ejs` - _(generates file)_ documentation for route in Api class (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-docs.ejs))
- `route-name.ejs` - _(subtemplate)_ route name for route in Api class (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-name.ejs))
- `route-type.ejs` - _(`--route-types` option)_ _(subtemplate)_ (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-type.ejs))
- `route-types.ejs` - _(`--route-types` option)_ _(subtemplate)_ (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/route-types.ejs)) - `data-contract-jsdoc.ejs` - _(subtemplate)_ generates JSDOC for data contract (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/data-contract-jsdoc.ejs))

[//]: # "- `enum-data-contract.ejs` - *(subtemplate)* generates `enum` data contract (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/enum-data-contract.ejs))"
[//]: # "- `interface-data-contract.ejs` - *(subtemplate)* generates `interface` data contract (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/interface-data-contract.ejs))"
[//]: # "- `type-data-contract.ejs` - *(subtemplate)* generates `type` data contract (locations: [base](https://github.com/acacode/swagger-typescript-api/tree/next/templates/base/type-data-contract.ejs))"
9 changes: 4 additions & 5 deletions templates/base/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# swagger-typescript-api
# swagger-typescript-api

# templates/base
# templates/base

This templates use both for multiple api files and single api file
This templates use both for multiple api files and single api file


path prefix `@base`
path prefix `@base`
8 changes: 4 additions & 4 deletions templates/default/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# swagger-typescript-api
# swagger-typescript-api

# templates/default
# templates/default

This templates use for single api file (without `--modular` option)
This templates use for single api file (without `--modular` option)

path prefix `@default`
path prefix `@default`
8 changes: 4 additions & 4 deletions templates/modular/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# swagger-typescript-api
# swagger-typescript-api

# templates/modular
# templates/modular

This templates use for multiple api files (`--modular` option)
This templates use for multiple api files (`--modular` option)

path prefix `@modular`
path prefix `@modular`
20 changes: 10 additions & 10 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# swagger-typescript-api
# swagger-typescript-api

## 📃 EXAMPLES
## 📃 EXAMPLES

As you see above here is two folders:
1. [**`schemas`**](./schemas) -
- [**`v2.0`**](./schemas/v2.0) - schemas with Swagger 2.0
- [**`v3.0`**](./schemas/v3.0) - schemas with OA 3.0
1. [**`generated`**](./generated) -
- [**`v2.0`**](./generated/v2.0) - generated api modules for Swagger 2.0 schemas from above folder
- [**`v3.0`**](./generated/v3.0) - generated api modules for OA 3.0 schemas from above folder
As you see above here is two folders:

1. [**`schemas`**](./schemas) -
- [**`v2.0`**](./schemas/v2.0) - schemas with Swagger 2.0
- [**`v3.0`**](./schemas/v3.0) - schemas with OA 3.0
1. [**`generated`**](./generated) -
- [**`v2.0`**](./generated/v2.0) - generated api modules for Swagger 2.0 schemas from above folder
- [**`v3.0`**](./generated/v3.0) - generated api modules for OA 3.0 schemas from above folder

Most schemas taken from [apis.guru](https://apis.guru/openapi-directory/), [swagger.io github repo](https://swagger.io/), [Github api description](https://github.com/github/rest-api-description) and [up-banking](https://github.com/up-banking/api)
Most schemas taken from [apis.guru](https://apis.guru/openapi-directory/), [swagger.io github repo](https://swagger.io/), [Github api description](https://github.com/github/rest-api-description) and [up-banking](https://github.com/up-banking/api)
17 changes: 14 additions & 3 deletions tests/schemas/v2.0/another-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@
}
],
"security": [],
"consumes": ["application/x-www-form-urlencoded", "multipart/form-data"],
"consumes": [
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"tags": ["pet"]
}
},
Expand Down Expand Up @@ -263,7 +266,10 @@
}
],
"security": [],
"consumes": ["multipart/form-data", "application/x-www-form-urlencoded"],
"consumes": [
"multipart/form-data",
"application/x-www-form-urlencoded"
],
"tags": ["pet"]
}
},
Expand Down Expand Up @@ -996,7 +1002,12 @@
},
"PetNames": {
"type": "string",
"enum": ["Fluffy Hero", "Piggy Po", "Swagger Typescript Api", "UPPER_CASE"]
"enum": [
"Fluffy Hero",
"Piggy Po",
"Swagger Typescript Api",
"UPPER_CASE"
]
},
"PetIds": {
"type": "integer",
Expand Down
6 changes: 3 additions & 3 deletions tests/schemas/v2.0/api-with-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ paths:
multiple line 2
multiple line 3
produces:
- application/json
- application/json
responses:
"200":
description: |-
Expand Down Expand Up @@ -82,7 +82,7 @@ paths:
operationId: getVersionDetailsv2
summary: Show API version details
produces:
- application/json
- application/json
responses:
"200":
description: |-
Expand Down Expand Up @@ -191,4 +191,4 @@ paths:
type: string

consumes:
- application/json
- application/json
4 changes: 3 additions & 1 deletion tests/schemas/v2.0/enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
},
"SomeInterestEnum": {
"format": "int32",
"enum": [6, 2, 1, 67, 88, 122, 88, 0, 213, 12378, 123125, 32452, 1111, 66666],
"enum": [
6, 2, 1, 67, 88, 122, 88, 0, 213, 12378, 123125, 32452, 1111, 66666
],
"type": "integer",
"x-enumNames": [
"Bla",
Expand Down
44 changes: 22 additions & 22 deletions tests/schemas/v2.0/furkot-example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
swagger: '2.0'
swagger: "2.0"
schemes:
- https
host: trips.furkot.com
Expand All @@ -15,63 +15,63 @@ info:
x-apisguru-categories:
- location
x-logo:
url: 'https://api.apis.guru/v2/cache/logo/https_cdn.furkot.com_img_furkot-banner-black-4x1.svg'
url: "https://api.apis.guru/v2/cache/logo/https_cdn.furkot.com_img_furkot-banner-black-4x1.svg"
x-origin:
- format: swagger
url: 'https://help.furkot.com/widgets/furkot-api.yaml'
version: '2.0'
url: "https://help.furkot.com/widgets/furkot-api.yaml"
version: "2.0"
x-preferred: true
x-providerName: furkot.com
externalDocs:
description: Furkot API description
url: 'https://help.furkot.com/widgets/furkot-api.html'
url: "https://help.furkot.com/widgets/furkot-api.html"
produces:
- application/json
securityDefinitions:
furkot_auth_access_code:
authorizationUrl: 'https://trips.furkot.com/oauth/authorize'
authorizationUrl: "https://trips.furkot.com/oauth/authorize"
flow: accessCode
scopes:
'read:trips': list trips and stops info
tokenUrl: 'https://trips.furkot.com/pub/api/access_token'
"read:trips": list trips and stops info
tokenUrl: "https://trips.furkot.com/pub/api/access_token"
type: oauth2
furkot_auth_implicit:
authorizationUrl: 'https://trips.furkot.com/oauth/authorize'
authorizationUrl: "https://trips.furkot.com/oauth/authorize"
flow: implicit
scopes:
'read:trips': list users trips info
"read:trips": list users trips info
type: oauth2
security:
- furkot_auth_access_code:
- 'read:trips'
- "read:trips"
- furkot_auth_implicit:
- 'read:trips'
- "read:trips"
paths:
/trip:
get:
description: list user's trips
responses:
'200':
"200":
description: Successful response
schema:
items:
$ref: '#/definitions/Trip'
$ref: "#/definitions/Trip"
type: array
'/trip/{trip_id}/stop':
"/trip/{trip_id}/stop":
get:
description: 'list stops for a trip identified by {trip_id}'
description: "list stops for a trip identified by {trip_id}"
parameters:
- description: id of the trip
in: path
name: trip_id
required: true
type: string
responses:
'200':
"200":
description: Successful response
schema:
items:
$ref: '#/definitions/Step'
$ref: "#/definitions/Step"
type: array
definitions:
Step:
Expand All @@ -80,7 +80,7 @@ definitions:
description: address of the stop
type: string
arrival:
description: 'arrival at the stop in its local timezone as YYYY-MM-DDThh:mm'
description: "arrival at the stop in its local timezone as YYYY-MM-DDThh:mm"
format: date-time
type: string
coordinates:
Expand All @@ -96,7 +96,7 @@ definitions:
type: number
type: object
departure:
description: 'departure from the stop in its local timezone as YYYY-MM-DDThh:mm'
description: "departure from the stop in its local timezone as YYYY-MM-DDThh:mm"
format: date-time
type: string
name:
Expand Down Expand Up @@ -137,14 +137,14 @@ definitions:
Trip:
properties:
begin:
description: 'begin of the trip in its local timezone as YYYY-MM-DDThh:mm'
description: "begin of the trip in its local timezone as YYYY-MM-DDThh:mm"
format: date-time
type: string
description:
description: description of the trip (truncated to 200 characters)
type: string
end:
description: 'end of the trip in its local timezone as YYYY-MM-DDThh:mm'
description: "end of the trip in its local timezone as YYYY-MM-DDThh:mm"
format: date-time
type: string
id:
Expand Down
Loading