mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge branch 'master' into bugfix/batch
This commit is contained in:
commit
21a88a9844
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.7.2",
|
||||
"version": "0.8.0",
|
||||
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
|
||||
@ -978,6 +978,13 @@
|
||||
"Order": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bool": {
|
||||
"description": "Simple boolean enum",
|
||||
"type": "boolean",
|
||||
"enum": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
|
||||
@ -18,7 +18,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: value
|
||||
name: String(value)
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
|
||||
@ -53,7 +53,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
|
||||
return model;
|
||||
}
|
||||
|
||||
if (definition.enum) {
|
||||
if (definition.enum && definition.type !== 'boolean') {
|
||||
const enumerators = getEnum(definition.enum);
|
||||
const extendedEnumerators = extendEnum(enumerators, definition);
|
||||
if (extendedEnumerators.length) {
|
||||
|
||||
@ -18,7 +18,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: value
|
||||
name: String(value)
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
|
||||
@ -55,7 +55,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
|
||||
return model;
|
||||
}
|
||||
|
||||
if (definition.enum) {
|
||||
if (definition.enum && definition.type !== 'boolean') {
|
||||
const enumerators = getEnum(definition.enum);
|
||||
const extendedEnumerators = extendEnum(enumerators, definition);
|
||||
if (extendedEnumerators.length) {
|
||||
|
||||
@ -381,6 +381,7 @@ export { $SimpleReference } from './schemas/$SimpleReference';
|
||||
export { $SimpleString } from './schemas/$SimpleString';
|
||||
export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern';
|
||||
|
||||
export { CollectionFormatService } from './services/CollectionFormatService';
|
||||
export { ComplexService } from './services/ComplexService';
|
||||
export { DefaultsService } from './services/DefaultsService';
|
||||
export { DuplicateService } from './services/DuplicateService';
|
||||
@ -756,6 +757,10 @@ export type ModelWithEnum = {
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
statusCode?: ModelWithEnum.statusCode;
|
||||
/**
|
||||
* Simple boolean enum
|
||||
*/
|
||||
bool?: boolean;
|
||||
}
|
||||
|
||||
export namespace ModelWithEnum {
|
||||
@ -1422,6 +1427,9 @@ export const $ModelWithEnum = {
|
||||
statusCode: {
|
||||
type: 'Enum',
|
||||
},
|
||||
bool: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
};"
|
||||
`;
|
||||
@ -1722,6 +1730,47 @@ export const $SimpleStringWithPattern = {
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/services/CollectionFormatService.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import { request as __request } from '../core/request';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
|
||||
export class CollectionFormatService {
|
||||
|
||||
/**
|
||||
* @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values)
|
||||
* @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values)
|
||||
* @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values)
|
||||
* @param parameterArrayMulti This is an array parameter that is send as pipes format (pipe-separated values)
|
||||
* @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances)
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static async collectionFormat(
|
||||
parameterArrayCsv: Array<string>,
|
||||
parameterArraySsv: Array<string>,
|
||||
parameterArrayTsv: Array<string>,
|
||||
parameterArrayMulti: Array<string>,
|
||||
parameterArrayMulti: Array<string>,
|
||||
): Promise<void> {
|
||||
const result = await __request({
|
||||
method: 'GET',
|
||||
path: \`/api/v\${OpenAPI.VERSION}/collectionFormat\`,
|
||||
query: {
|
||||
'parameterArrayCSV': parameterArrayCsv,
|
||||
'parameterArraySSV': parameterArraySsv,
|
||||
'parameterArrayTSV': parameterArrayTsv,
|
||||
'parameterArrayMulti': parameterArrayMulti,
|
||||
'parameterArrayMulti': parameterArrayMulti,
|
||||
},
|
||||
});
|
||||
return result.body;
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`v2 should generate: ./test/generated/v2/services/ComplexService.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
@ -2639,6 +2688,7 @@ export { $SimpleReference } from './schemas/$SimpleReference';
|
||||
export { $SimpleString } from './schemas/$SimpleString';
|
||||
export { $SimpleStringWithPattern } from './schemas/$SimpleStringWithPattern';
|
||||
|
||||
export { CollectionFormatService } from './services/CollectionFormatService';
|
||||
export { ComplexService } from './services/ComplexService';
|
||||
export { DefaultsService } from './services/DefaultsService';
|
||||
export { DuplicateService } from './services/DuplicateService';
|
||||
@ -3136,6 +3186,10 @@ export type ModelWithEnum = {
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
statusCode?: ModelWithEnum.statusCode;
|
||||
/**
|
||||
* Simple boolean enum
|
||||
*/
|
||||
bool?: boolean;
|
||||
}
|
||||
|
||||
export namespace ModelWithEnum {
|
||||
@ -3948,6 +4002,9 @@ export const $ModelWithEnum = {
|
||||
statusCode: {
|
||||
type: 'Enum',
|
||||
},
|
||||
bool: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
};"
|
||||
`;
|
||||
@ -4238,6 +4295,47 @@ export const $SimpleStringWithPattern = {
|
||||
};"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/services/CollectionFormatService.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import { request as __request } from '../core/request';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
|
||||
export class CollectionFormatService {
|
||||
|
||||
/**
|
||||
* @param parameterArrayCsv This is an array parameter that is send as csv format (comma-separated values)
|
||||
* @param parameterArraySsv This is an array parameter that is send as ssv format (space-separated values)
|
||||
* @param parameterArrayTsv This is an array parameter that is send as tsv format (tab-separated values)
|
||||
* @param parameterArrayMulti This is an array parameter that is send as pipes format (pipe-separated values)
|
||||
* @param parameterArrayMulti This is an array parameter that is send as multi format (multiple parameter instances)
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static async collectionFormat(
|
||||
parameterArrayCsv: Array<string> | null,
|
||||
parameterArraySsv: Array<string> | null,
|
||||
parameterArrayTsv: Array<string> | null,
|
||||
parameterArrayMulti: Array<string> | null,
|
||||
parameterArrayMulti: Array<string> | null,
|
||||
): Promise<void> {
|
||||
const result = await __request({
|
||||
method: 'GET',
|
||||
path: \`/api/v\${OpenAPI.VERSION}/collectionFormat\`,
|
||||
query: {
|
||||
'parameterArrayCSV': parameterArrayCsv,
|
||||
'parameterArraySSV': parameterArraySsv,
|
||||
'parameterArrayTSV': parameterArrayTsv,
|
||||
'parameterArrayMulti': parameterArrayMulti,
|
||||
'parameterArrayMulti': parameterArrayMulti,
|
||||
},
|
||||
});
|
||||
return result.body;
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`v3 should generate: ./test/generated/v3/services/ComplexService.ts 1`] = `
|
||||
"/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
|
||||
@ -490,6 +490,71 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v{api-version}/collectionFormat": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"CollectionFormat"
|
||||
],
|
||||
"operationId": "CollectionFormat",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "This is an array parameter that is send as csv format (comma-separated values)",
|
||||
"name": "parameterArrayCSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as ssv format (space-separated values)",
|
||||
"name": "parameterArraySSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "ssv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as tsv format (tab-separated values)",
|
||||
"name": "parameterArrayTSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "tsv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as pipes format (pipe-separated values)",
|
||||
"name": "parameterArrayMulti",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "pipes"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as multi format (multiple parameter instances)",
|
||||
"name": "parameterArrayMulti",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v{api-version}/types": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -932,6 +997,13 @@
|
||||
"500 foo.bar",
|
||||
"600 foo&bar"
|
||||
]
|
||||
},
|
||||
"bool": {
|
||||
"description": "Simple boolean enum",
|
||||
"type": "boolean",
|
||||
"enum": [
|
||||
true
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -712,6 +712,86 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v{api-version}/collectionFormat": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"CollectionFormat"
|
||||
],
|
||||
"operationId": "CollectionFormat",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "This is an array parameter that is send as csv format (comma-separated values)",
|
||||
"name": "parameterArrayCSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"nullable": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as ssv format (space-separated values)",
|
||||
"name": "parameterArraySSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"nullable": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"collectionFormat": "ssv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as tsv format (tab-separated values)",
|
||||
"name": "parameterArrayTSV",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"nullable": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"collectionFormat": "tsv"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as pipes format (pipe-separated values)",
|
||||
"name": "parameterArrayMulti",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"nullable": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"collectionFormat": "pipes"
|
||||
},
|
||||
{
|
||||
"description": "This is an array parameter that is send as multi format (multiple parameter instances)",
|
||||
"name": "parameterArrayMulti",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"nullable": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"collectionFormat": "multi"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v{api-version}/types": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -1390,6 +1470,13 @@
|
||||
"500 foo.bar",
|
||||
"600 foo&bar"
|
||||
]
|
||||
},
|
||||
"bool": {
|
||||
"description": "Simple boolean enum",
|
||||
"type": "boolean",
|
||||
"enum": [
|
||||
true
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user