From 70536dc68960962ea51071c2ed55b271968933ad Mon Sep 17 00:00:00 2001 From: Wojciech Zankowski Date: Fri, 4 Sep 2026 22:20:39 +0200 Subject: [PATCH 1/3] feature: [typescript-fetch] add model suffix support --- .../typescript-fetch-model-suffix.yaml | 9 + .../TypeScriptFetchClientCodegen.java | 24 + .../builds/model-suffix/.gitignore | 4 + .../builds/model-suffix/.npmignore | 1 + .../model-suffix/.openapi-generator-ignore | 23 + .../model-suffix/.openapi-generator/FILES | 41 ++ .../model-suffix/.openapi-generator/VERSION | 1 + .../builds/model-suffix/README.md | 124 +++++ .../docs/DashedOptionOneResource.md | 36 ++ .../docs/DashedOptionTwoResource.md | 36 ++ .../builds/model-suffix/docs/DefaultApi.md | 298 +++++++++++ .../docs/NumericSingletonEnumModelResource.md | 34 ++ .../model-suffix/docs/OptionOneResource.md | 34 ++ .../model-suffix/docs/OptionTwoResource.md | 34 ++ .../docs/SnakeOptionOneResource.md | 36 ++ .../docs/SnakeOptionTwoResource.md | 36 ++ .../builds/model-suffix/docs/TestAResource.md | 34 ++ .../docs/TestArrayResponseResource.md | 32 ++ .../builds/model-suffix/docs/TestBResource.md | 34 ++ ...TestDashedDiscriminatorResponseResource.md | 36 ++ .../docs/TestDiscriminatorResponseResource.md | 34 ++ .../model-suffix/docs/TestResponseResource.md | 36 ++ ...tSnakeCaseDiscriminatorResponseResource.md | 36 ++ .../builds/model-suffix/package.json | 21 + .../model-suffix/src/apis/DefaultApi.ts | 211 ++++++++ .../builds/model-suffix/src/apis/index.ts | 3 + .../builds/model-suffix/src/index.ts | 5 + .../src/models/DashedOptionOneResource.ts | 82 +++ .../src/models/DashedOptionTwoResource.ts | 82 +++ .../NumericSingletonEnumModelResource.ts | 75 +++ .../src/models/OptionOneResource.ts | 75 +++ .../src/models/OptionTwoResource.ts | 75 +++ .../src/models/SnakeOptionOneResource.ts | 82 +++ .../src/models/SnakeOptionTwoResource.ts | 82 +++ .../model-suffix/src/models/TestAResource.ts | 63 +++ .../src/models/TestArrayResponseResource.ts | 84 +++ .../model-suffix/src/models/TestBResource.ts | 63 +++ ...TestDashedDiscriminatorResponseResource.ts | 62 +++ .../TestDiscriminatorResponseResource.ts | 62 +++ .../src/models/TestResponseResource.ts | 72 +++ ...tSnakeCaseDiscriminatorResponseResource.ts | 62 +++ .../builds/model-suffix/src/models/index.ts | 16 + .../builds/model-suffix/src/runtime.ts | 505 ++++++++++++++++++ .../builds/model-suffix/tsconfig.esm.json | 7 + .../builds/model-suffix/tsconfig.json | 16 + 45 files changed, 2818 insertions(+) create mode 100644 bin/configs/typescript-fetch-model-suffix.yaml create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/.gitignore create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/.npmignore create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator-ignore create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/FILES create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/VERSION create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/README.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionOneResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionTwoResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DefaultApi.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/NumericSingletonEnumModelResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionOneResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionTwoResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionOneResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionTwoResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestAResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestArrayResponseResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestBResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDashedDiscriminatorResponseResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDiscriminatorResponseResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestResponseResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestSnakeCaseDiscriminatorResponseResource.md create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/package.json create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/DefaultApi.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionOneResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionTwoResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/NumericSingletonEnumModelResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionOneResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionTwoResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionOneResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionTwoResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestAResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestArrayResponseResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestBResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDashedDiscriminatorResponseResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDiscriminatorResponseResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestResponseResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestSnakeCaseDiscriminatorResponseResource.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/src/runtime.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.esm.json create mode 100644 samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.json diff --git a/bin/configs/typescript-fetch-model-suffix.yaml b/bin/configs/typescript-fetch-model-suffix.yaml new file mode 100644 index 000000000000..7fd3117d887d --- /dev/null +++ b/bin/configs/typescript-fetch-model-suffix.yaml @@ -0,0 +1,9 @@ +generatorName: typescript-fetch +outputDir: samples/client/petstore/typescript-fetch/builds/model-suffix +inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/oneOf.yaml +templateDir: modules/openapi-generator/src/main/resources/typescript-fetch +additionalProperties: + modelSuffix: Resource + npmName: '@openapitools/typescript-fetch-model-suffix' + npmVersion: 1.0.0 + snapshot: false \ No newline at end of file diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index c326ae929ab4..aa4e9ec5ccac 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -58,6 +58,8 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen { private final Logger LOGGER = LoggerFactory.getLogger(TypeScriptFetchClientCodegen.class); + private static String CLASS_NAME_SUFFIX_PATTERN = "^[a-zA-Z0-9]*$"; + public static final String NPM_REPOSITORY = "npmRepository"; public static final String WITH_INTERFACES = "withInterfaces"; public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter"; @@ -71,6 +73,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values."; public static final String IMPORT_FILE_EXTENSION_SWITCH = "importFileExtension"; public static final String IMPORT_FILE_EXTENSION_SWITCH_DESC = "File extension to use with relative imports. Set it to '.js' or '.mjs' when using [ESM](https://nodejs.org/api/esm.html)."; + public static final String MODEL_SUFFIX = "modelSuffix"; public static final String FILE_NAMING = "fileNaming"; public static final String KEBAB_CASE = "kebab-case"; public static final String CAMEL_CASE = "camelCase"; @@ -159,6 +162,7 @@ public TypeScriptFetchClientCodegen() { this.cliOptions.add(new CliOption(SAGAS_AND_RECORDS, "Setting this property to true will generate additional files for use with redux-saga and immutablejs.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(IMPORT_FILE_EXTENSION_SWITCH, IMPORT_FILE_EXTENSION_SWITCH_DESC).defaultValue("")); + this.cliOptions.add(new CliOption(MODEL_SUFFIX, "The suffix of the generated model.")); this.cliOptions.add(new CliOption(FILE_NAMING, "Naming convention for the output files: 'PascalCase', 'camelCase', 'kebab-case'.").defaultValue(this.fileNaming)); this.cliOptions.add(new CliOption(USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, "Setting this property to true will add brackets to array attribute names, e.g. my_values[].", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(VALIDATION_ATTRIBUTES, "Setting this property to true will generate the validation attributes of model properties.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); @@ -230,6 +234,21 @@ public void setStringEnums(Boolean stringEnums) { this.stringEnums = stringEnums; } + /** + * Validates that the given string value only contains alpha numeric characters. + * Throws an IllegalArgumentException, if the string contains any other characters. + * + * @param argument The name of the argument being validated. This is only used for displaying an error message. + * @param value The value that is being validated. + */ + private void validateClassSuffixArgument(String argument, String value) { + if (!value.matches(CLASS_NAME_SUFFIX_PATTERN)) { + throw new IllegalArgumentException( + String.format(Locale.ROOT, "%s class suffix only allows alphanumeric characters.", argument) + ); + } + } + /** * Set the file naming type. * @@ -335,6 +354,11 @@ public void processOpts() { additionalProperties.put("stringEnums", this.stringEnums); } + if (additionalProperties.containsKey(MODEL_SUFFIX)) { + this.modelNameSuffix = additionalProperties.get(MODEL_SUFFIX).toString(); + validateClassSuffixArgument("Model", modelNameSuffix); + } + if (additionalProperties.containsKey(FILE_NAMING)) { this.setFileNaming(additionalProperties.get(FILE_NAMING).toString()); } diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/.gitignore b/samples/client/petstore/typescript-fetch/builds/model-suffix/.gitignore new file mode 100644 index 000000000000..149b57654723 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/.npmignore b/samples/client/petstore/typescript-fetch/builds/model-suffix/.npmignore new file mode 100644 index 000000000000..42061c01a1c7 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/.npmignore @@ -0,0 +1 @@ +README.md \ No newline at end of file diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator-ignore b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/FILES new file mode 100644 index 000000000000..438e0bdc87fe --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/FILES @@ -0,0 +1,41 @@ +.gitignore +.npmignore +.openapi-generator-ignore +README.md +docs/DashedOptionOneResource.md +docs/DashedOptionTwoResource.md +docs/DefaultApi.md +docs/NumericSingletonEnumModelResource.md +docs/OptionOneResource.md +docs/OptionTwoResource.md +docs/SnakeOptionOneResource.md +docs/SnakeOptionTwoResource.md +docs/TestAResource.md +docs/TestArrayResponseResource.md +docs/TestBResource.md +docs/TestDashedDiscriminatorResponseResource.md +docs/TestDiscriminatorResponseResource.md +docs/TestResponseResource.md +docs/TestSnakeCaseDiscriminatorResponseResource.md +package.json +src/apis/DefaultApi.ts +src/apis/index.ts +src/index.ts +src/models/DashedOptionOneResource.ts +src/models/DashedOptionTwoResource.ts +src/models/NumericSingletonEnumModelResource.ts +src/models/OptionOneResource.ts +src/models/OptionTwoResource.ts +src/models/SnakeOptionOneResource.ts +src/models/SnakeOptionTwoResource.ts +src/models/TestAResource.ts +src/models/TestArrayResponseResource.ts +src/models/TestBResource.ts +src/models/TestDashedDiscriminatorResponseResource.ts +src/models/TestDiscriminatorResponseResource.ts +src/models/TestResponseResource.ts +src/models/TestSnakeCaseDiscriminatorResponseResource.ts +src/models/index.ts +src/runtime.ts +tsconfig.esm.json +tsconfig.json diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/VERSION b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/VERSION new file mode 100644 index 000000000000..32a8cfaceeb9 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.26.0-SNAPSHOT diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/README.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/README.md new file mode 100644 index 000000000000..02f767c751ff --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/README.md @@ -0,0 +1,124 @@ +# @openapitools/typescript-fetch-model-suffix@1.0.0 + +A TypeScript SDK client for the localhost API. + +## Usage + +First, install the SDK from npm. + +```bash +npm install @openapitools/typescript-fetch-model-suffix --save +``` + +Next, try it out. + + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.test(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + + +## Documentation + +### API Endpoints + +All URIs are relative to *http://localhost:3000* + +| Class | Method | HTTP request | Description +| ----- | ------ | ------------ | ------------- +*DefaultApi* | [**test**](docs/DefaultApi.md#test) | **GET** /test | +*DefaultApi* | [**testArray**](docs/DefaultApi.md#testarray) | **GET** /test-array | +*DefaultApi* | [**testDashedDiscriminator**](docs/DefaultApi.md#testdasheddiscriminator) | **GET** /test-dashed-discriminator | +*DefaultApi* | [**testDiscriminator**](docs/DefaultApi.md#testdiscriminator) | **GET** /test-discriminator | +*DefaultApi* | [**testSnakeCaseDiscriminator**](docs/DefaultApi.md#testsnakecasediscriminator) | **GET** /test-snake-case-discriminator | + + +### Models + +- [DashedOptionOneResource](docs/DashedOptionOneResource.md) +- [DashedOptionTwoResource](docs/DashedOptionTwoResource.md) +- [NumericSingletonEnumModelResource](docs/NumericSingletonEnumModelResource.md) +- [OptionOneResource](docs/OptionOneResource.md) +- [OptionTwoResource](docs/OptionTwoResource.md) +- [SnakeOptionOneResource](docs/SnakeOptionOneResource.md) +- [SnakeOptionTwoResource](docs/SnakeOptionTwoResource.md) +- [TestAResource](docs/TestAResource.md) +- [TestArrayResponseResource](docs/TestArrayResponseResource.md) +- [TestBResource](docs/TestBResource.md) +- [TestDashedDiscriminatorResponseResource](docs/TestDashedDiscriminatorResponseResource.md) +- [TestDiscriminatorResponseResource](docs/TestDiscriminatorResponseResource.md) +- [TestResponseResource](docs/TestResponseResource.md) +- [TestSnakeCaseDiscriminatorResponseResource](docs/TestSnakeCaseDiscriminatorResponseResource.md) + +### Authorization + +Endpoints do not require authorization. + + +## About + +This TypeScript SDK client supports the [Fetch API](https://fetch.spec.whatwg.org/) +and is automatically generated by the +[OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: `1.0.0` +- Package version: `1.0.0` +- Generator version: `7.26.0-SNAPSHOT` +- Build package: `org.openapitools.codegen.languages.TypeScriptFetchClientCodegen` + +The generated npm module supports the following: + +- Environments + * Node.js + * Webpack + * Browserify +- Language levels + * ES5 - you must have a Promises/A+ library installed + * ES6 +- Module systems + * CommonJS + * ES6 module system + + +## Development + +### Building + +To build the TypeScript source code, you need to have Node.js and npm installed. +After cloning the repository, navigate to the project directory and run: + +```bash +npm install +npm run build +``` + +### Publishing + +Once you've built the package, you can publish it to npm: + +```bash +npm publish +``` + +## License + +[]() diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionOneResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionOneResource.md new file mode 100644 index 000000000000..5749134600e1 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionOneResource.md @@ -0,0 +1,36 @@ + +# DashedOptionOneResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { DashedOptionOneResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies DashedOptionOneResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as DashedOptionOneResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionTwoResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionTwoResource.md new file mode 100644 index 000000000000..bd62d52879d2 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DashedOptionTwoResource.md @@ -0,0 +1,36 @@ + +# DashedOptionTwoResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { DashedOptionTwoResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies DashedOptionTwoResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as DashedOptionTwoResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DefaultApi.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DefaultApi.md new file mode 100644 index 000000000000..d89d079893e3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/DefaultApi.md @@ -0,0 +1,298 @@ +# DefaultApi + +All URIs are relative to *http://localhost:3000* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**test**](DefaultApi.md#test) | **GET** /test | | +| [**testArray**](DefaultApi.md#testarray) | **GET** /test-array | | +| [**testDashedDiscriminator**](DefaultApi.md#testdasheddiscriminator) | **GET** /test-dashed-discriminator | | +| [**testDiscriminator**](DefaultApi.md#testdiscriminator) | **GET** /test-discriminator | | +| [**testSnakeCaseDiscriminator**](DefaultApi.md#testsnakecasediscriminator) | **GET** /test-snake-case-discriminator | | + + + +## test + +> TestResponseResource test() + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.test(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**TestResponseResource**](TestResponseResource.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | OK | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## testArray + +> TestArrayResponseResource testArray() + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestArrayRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.testArray(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**TestArrayResponseResource**](TestArrayResponseResource.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | OK | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## testDashedDiscriminator + +> TestDashedDiscriminatorResponseResource testDashedDiscriminator() + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestDashedDiscriminatorRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.testDashedDiscriminator(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**TestDashedDiscriminatorResponseResource**](TestDashedDiscriminatorResponseResource.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | OK | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## testDiscriminator + +> TestDiscriminatorResponseResource testDiscriminator() + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestDiscriminatorRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.testDiscriminator(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**TestDiscriminatorResponseResource**](TestDiscriminatorResponseResource.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | OK | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## testSnakeCaseDiscriminator + +> TestSnakeCaseDiscriminatorResponseResource testSnakeCaseDiscriminator() + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from '@openapitools/typescript-fetch-model-suffix'; +import type { TestSnakeCaseDiscriminatorRequest } from '@openapitools/typescript-fetch-model-suffix'; + +async function example() { + console.log("🚀 Testing @openapitools/typescript-fetch-model-suffix SDK..."); + const api = new DefaultApi(); + + try { + const data = await api.testSnakeCaseDiscriminator(); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**TestSnakeCaseDiscriminatorResponseResource**](TestSnakeCaseDiscriminatorResponseResource.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | OK | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/NumericSingletonEnumModelResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/NumericSingletonEnumModelResource.md new file mode 100644 index 000000000000..6d5de91aa47c --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/NumericSingletonEnumModelResource.md @@ -0,0 +1,34 @@ + +# NumericSingletonEnumModelResource + + +## Properties + +Name | Type +------------ | ------------- +`kind` | number + +## Example + +```typescript +import type { NumericSingletonEnumModelResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "kind": null, +} satisfies NumericSingletonEnumModelResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as NumericSingletonEnumModelResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionOneResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionOneResource.md new file mode 100644 index 000000000000..37c2f21f6457 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionOneResource.md @@ -0,0 +1,34 @@ + +# OptionOneResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string + +## Example + +```typescript +import type { OptionOneResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, +} satisfies OptionOneResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as OptionOneResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionTwoResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionTwoResource.md new file mode 100644 index 000000000000..74879ae21f53 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/OptionTwoResource.md @@ -0,0 +1,34 @@ + +# OptionTwoResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string + +## Example + +```typescript +import type { OptionTwoResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, +} satisfies OptionTwoResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as OptionTwoResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionOneResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionOneResource.md new file mode 100644 index 000000000000..efdc1ce4faa0 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionOneResource.md @@ -0,0 +1,36 @@ + +# SnakeOptionOneResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { SnakeOptionOneResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies SnakeOptionOneResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as SnakeOptionOneResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionTwoResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionTwoResource.md new file mode 100644 index 000000000000..c969b313a9dd --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/SnakeOptionTwoResource.md @@ -0,0 +1,36 @@ + +# SnakeOptionTwoResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { SnakeOptionTwoResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies SnakeOptionTwoResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as SnakeOptionTwoResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestAResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestAResource.md new file mode 100644 index 000000000000..d0f3b27611b9 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestAResource.md @@ -0,0 +1,34 @@ + +# TestAResource + + +## Properties + +Name | Type +------------ | ------------- +`foo` | string + +## Example + +```typescript +import type { TestAResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "foo": null, +} satisfies TestAResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestAResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestArrayResponseResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestArrayResponseResource.md new file mode 100644 index 000000000000..01d7ab16f2f8 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestArrayResponseResource.md @@ -0,0 +1,32 @@ + +# TestArrayResponseResource + + +## Properties + +Name | Type +------------ | ------------- + +## Example + +```typescript +import type { TestArrayResponseResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { +} satisfies TestArrayResponseResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestArrayResponseResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestBResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestBResource.md new file mode 100644 index 000000000000..98319fb2887f --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestBResource.md @@ -0,0 +1,34 @@ + +# TestBResource + + +## Properties + +Name | Type +------------ | ------------- +`bar` | string + +## Example + +```typescript +import type { TestBResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "bar": null, +} satisfies TestBResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestBResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDashedDiscriminatorResponseResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDashedDiscriminatorResponseResource.md new file mode 100644 index 000000000000..152ab504ffc6 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDashedDiscriminatorResponseResource.md @@ -0,0 +1,36 @@ + +# TestDashedDiscriminatorResponseResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { TestDashedDiscriminatorResponseResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies TestDashedDiscriminatorResponseResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestDashedDiscriminatorResponseResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDiscriminatorResponseResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDiscriminatorResponseResource.md new file mode 100644 index 000000000000..9c7d93af0838 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestDiscriminatorResponseResource.md @@ -0,0 +1,34 @@ + +# TestDiscriminatorResponseResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string + +## Example + +```typescript +import type { TestDiscriminatorResponseResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, +} satisfies TestDiscriminatorResponseResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestDiscriminatorResponseResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestResponseResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestResponseResource.md new file mode 100644 index 000000000000..69130865fdf4 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestResponseResource.md @@ -0,0 +1,36 @@ + +# TestResponseResource + + +## Properties + +Name | Type +------------ | ------------- +`foo` | string +`bar` | string + +## Example + +```typescript +import type { TestResponseResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "foo": null, + "bar": null, +} satisfies TestResponseResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestResponseResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestSnakeCaseDiscriminatorResponseResource.md b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestSnakeCaseDiscriminatorResponseResource.md new file mode 100644 index 000000000000..20b4c401a668 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/docs/TestSnakeCaseDiscriminatorResponseResource.md @@ -0,0 +1,36 @@ + +# TestSnakeCaseDiscriminatorResponseResource + + +## Properties + +Name | Type +------------ | ------------- +`discriminatorField` | string +`someProperty` | string + +## Example + +```typescript +import type { TestSnakeCaseDiscriminatorResponseResource } from '@openapitools/typescript-fetch-model-suffix' + +// TODO: Update the object below with actual values +const example = { + "discriminatorField": null, + "someProperty": null, +} satisfies TestSnakeCaseDiscriminatorResponseResource + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TestSnakeCaseDiscriminatorResponseResource +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/package.json b/samples/client/petstore/typescript-fetch/builds/model-suffix/package.json new file mode 100644 index 000000000000..6e9aca9604ca --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/package.json @@ -0,0 +1,21 @@ +{ + "name": "@openapitools/typescript-fetch-model-suffix", + "version": "1.0.0", + "description": "OpenAPI client for @openapitools/typescript-fetch-model-suffix", + "author": "OpenAPI-Generator", + "repository": { + "type": "git", + "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" + }, + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "module": "./dist/esm/index.js", + "sideEffects": false, + "scripts": { + "build": "tsc && tsc -p tsconfig.esm.json", + "prepare": "npm run build" + }, + "devDependencies": { + "typescript": "^4.0 || ^5.0" + } +} diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/DefaultApi.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/DefaultApi.ts new file mode 100644 index 000000000000..00208f79e39b --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/DefaultApi.ts @@ -0,0 +1,211 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import * as runtime from '../runtime'; +import {type TestArrayResponseResource, TestArrayResponseResourceFromJSON,} from '../models/TestArrayResponseResource'; +import { + type TestDashedDiscriminatorResponseResource, + TestDashedDiscriminatorResponseResourceFromJSON, +} from '../models/TestDashedDiscriminatorResponseResource'; +import { + type TestDiscriminatorResponseResource, + TestDiscriminatorResponseResourceFromJSON, +} from '../models/TestDiscriminatorResponseResource'; +import {type TestResponseResource, TestResponseResourceFromJSON,} from '../models/TestResponseResource'; +import { + type TestSnakeCaseDiscriminatorResponseResource, + TestSnakeCaseDiscriminatorResponseResourceFromJSON, +} from '../models/TestSnakeCaseDiscriminatorResponseResource'; + +/** + * + */ +export class DefaultApi extends runtime.BaseAPI { + + /** + * Creates request options for test without sending the request + */ + async testRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestResponseResourceFromJSON(jsonValue)); + } + + /** + */ + async test(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testArray without sending the request + */ + async testArrayRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-array`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testArrayRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testArrayRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestArrayResponseResourceFromJSON(jsonValue)); + } + + /** + */ + async testArray(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testArrayRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testDashedDiscriminator without sending the request + */ + async testDashedDiscriminatorRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-dashed-discriminator`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testDashedDiscriminatorRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testDashedDiscriminatorRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestDashedDiscriminatorResponseResourceFromJSON(jsonValue)); + } + + /** + */ + async testDashedDiscriminator(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testDashedDiscriminatorRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testDiscriminator without sending the request + */ + async testDiscriminatorRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-discriminator`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testDiscriminatorRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testDiscriminatorRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestDiscriminatorResponseResourceFromJSON(jsonValue)); + } + + /** + */ + async testDiscriminator(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testDiscriminatorRaw(initOverrides); + return await response.value(); + } + + /** + * Creates request options for testSnakeCaseDiscriminator without sending the request + */ + async testSnakeCaseDiscriminatorRequestOpts(): Promise { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/test-snake-case-discriminator`; + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async testSnakeCaseDiscriminatorRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.testSnakeCaseDiscriminatorRequestOpts(); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TestSnakeCaseDiscriminatorResponseResourceFromJSON(jsonValue)); + } + + /** + */ + async testSnakeCaseDiscriminator(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.testSnakeCaseDiscriminatorRaw(initOverrides); + return await response.value(); + } + +} diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/index.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/index.ts new file mode 100644 index 000000000000..69c44c00fa0d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/apis/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './DefaultApi'; diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/index.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/index.ts new file mode 100644 index 000000000000..bebe8bbbe206 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/index.ts @@ -0,0 +1,5 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './runtime'; +export * from './apis/index'; +export * from './models/index'; diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionOneResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionOneResource.ts new file mode 100644 index 000000000000..18c67a3f8920 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionOneResource.ts @@ -0,0 +1,82 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface DashedOptionOneResource + */ +export interface DashedOptionOneResource { + /** + * + */ + discriminatorField: DashedOptionOneResourceDiscriminatorFieldEnum; + /** + * + */ + someProperty: string; +} + + +/** + * @export + */ +export const DashedOptionOneResourceDiscriminatorFieldEnum = { + DashedOptionOne: 'dashedOptionOne', +} as const; +export type DashedOptionOneResourceDiscriminatorFieldEnum = typeof DashedOptionOneResourceDiscriminatorFieldEnum[keyof typeof DashedOptionOneResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the DashedOptionOneResource interface. + */ +export function instanceOfDashedOptionOneResource(value: object): value is DashedOptionOneResource { + if ((!('discriminatorField' in (value as Record)) && !('discriminator-field' in (value as Record))) || ((value as Record)['discriminatorField'] === undefined && (value as Record)['discriminator-field'] === undefined)) return false; + if ((value as Record)['discriminatorField'] !== 'dashedOptionOne' && (value as Record)['discriminator-field'] !== 'dashedOptionOne') return false; + + if ((!('someProperty' in (value as Record)) && !('some-property' in (value as Record))) || ((value as Record)['someProperty'] === undefined && (value as Record)['some-property'] === undefined)) return false; + return true; +} + +export function DashedOptionOneResourceFromJSON(json: any): DashedOptionOneResource { + return DashedOptionOneResourceFromJSONTyped(json, false); +} + +export function DashedOptionOneResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): DashedOptionOneResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminator-field'], + 'someProperty': json['some-property'], + }; +} + +export function DashedOptionOneResourceToJSON(json: any): DashedOptionOneResource { + return DashedOptionOneResourceToJSONTyped(json, false); +} + +export function DashedOptionOneResourceToJSONTyped(value?: DashedOptionOneResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminator-field': value['discriminatorField'], + 'some-property': value['someProperty'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionTwoResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionTwoResource.ts new file mode 100644 index 000000000000..213a912a54db --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/DashedOptionTwoResource.ts @@ -0,0 +1,82 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface DashedOptionTwoResource + */ +export interface DashedOptionTwoResource { + /** + * + */ + discriminatorField: DashedOptionTwoResourceDiscriminatorFieldEnum; + /** + * + */ + someProperty: string; +} + + +/** + * @export + */ +export const DashedOptionTwoResourceDiscriminatorFieldEnum = { + DashedOptionTwo: 'dashedOptionTwo', +} as const; +export type DashedOptionTwoResourceDiscriminatorFieldEnum = typeof DashedOptionTwoResourceDiscriminatorFieldEnum[keyof typeof DashedOptionTwoResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the DashedOptionTwoResource interface. + */ +export function instanceOfDashedOptionTwoResource(value: object): value is DashedOptionTwoResource { + if ((!('discriminatorField' in (value as Record)) && !('discriminator-field' in (value as Record))) || ((value as Record)['discriminatorField'] === undefined && (value as Record)['discriminator-field'] === undefined)) return false; + if ((value as Record)['discriminatorField'] !== 'dashedOptionTwo' && (value as Record)['discriminator-field'] !== 'dashedOptionTwo') return false; + + if ((!('someProperty' in (value as Record)) && !('some-property' in (value as Record))) || ((value as Record)['someProperty'] === undefined && (value as Record)['some-property'] === undefined)) return false; + return true; +} + +export function DashedOptionTwoResourceFromJSON(json: any): DashedOptionTwoResource { + return DashedOptionTwoResourceFromJSONTyped(json, false); +} + +export function DashedOptionTwoResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): DashedOptionTwoResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminator-field'], + 'someProperty': json['some-property'], + }; +} + +export function DashedOptionTwoResourceToJSON(json: any): DashedOptionTwoResource { + return DashedOptionTwoResourceToJSONTyped(json, false); +} + +export function DashedOptionTwoResourceToJSONTyped(value?: DashedOptionTwoResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminator-field': value['discriminatorField'], + 'some-property': value['someProperty'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/NumericSingletonEnumModelResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/NumericSingletonEnumModelResource.ts new file mode 100644 index 000000000000..fddf0666ca17 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/NumericSingletonEnumModelResource.ts @@ -0,0 +1,75 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface NumericSingletonEnumModelResource + */ +export interface NumericSingletonEnumModelResource { + /** + * + */ + kind: NumericSingletonEnumModelResourceKindEnum; +} + + +/** + * @export + */ +export const NumericSingletonEnumModelResourceKindEnum = { + NUMBER_42: 42, +} as const; +export type NumericSingletonEnumModelResourceKindEnum = typeof NumericSingletonEnumModelResourceKindEnum[keyof typeof NumericSingletonEnumModelResourceKindEnum]; + + +/** + * Check if a given object implements the NumericSingletonEnumModelResource interface. + */ +export function instanceOfNumericSingletonEnumModelResource(value: object): value is NumericSingletonEnumModelResource { + if (!('kind' in value) || value['kind'] === undefined) return false; + + if (value['kind'] !== 42) return false; + return true; +} + +export function NumericSingletonEnumModelResourceFromJSON(json: any): NumericSingletonEnumModelResource { + return NumericSingletonEnumModelResourceFromJSONTyped(json, false); +} + +export function NumericSingletonEnumModelResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): NumericSingletonEnumModelResource { + if (json == null) { + return json; + } + return { + + 'kind': json['kind'], + }; +} + +export function NumericSingletonEnumModelResourceToJSON(json: any): NumericSingletonEnumModelResource { + return NumericSingletonEnumModelResourceToJSONTyped(json, false); +} + +export function NumericSingletonEnumModelResourceToJSONTyped(value?: NumericSingletonEnumModelResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'kind': value['kind'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionOneResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionOneResource.ts new file mode 100644 index 000000000000..c081355057d5 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionOneResource.ts @@ -0,0 +1,75 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface OptionOneResource + */ +export interface OptionOneResource { + /** + * + */ + discriminatorField: OptionOneResourceDiscriminatorFieldEnum; +} + + +/** + * @export + */ +export const OptionOneResourceDiscriminatorFieldEnum = { + OptionOne: 'optionOne', +} as const; +export type OptionOneResourceDiscriminatorFieldEnum = typeof OptionOneResourceDiscriminatorFieldEnum[keyof typeof OptionOneResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the OptionOneResource interface. + */ +export function instanceOfOptionOneResource(value: object): value is OptionOneResource { + if (!('discriminatorField' in value) || value['discriminatorField'] === undefined) return false; + if (value['discriminatorField'] !== 'optionOne') return false; + + return true; +} + +export function OptionOneResourceFromJSON(json: any): OptionOneResource { + return OptionOneResourceFromJSONTyped(json, false); +} + +export function OptionOneResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): OptionOneResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminatorField'], + }; +} + +export function OptionOneResourceToJSON(json: any): OptionOneResource { + return OptionOneResourceToJSONTyped(json, false); +} + +export function OptionOneResourceToJSONTyped(value?: OptionOneResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminatorField': value['discriminatorField'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionTwoResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionTwoResource.ts new file mode 100644 index 000000000000..ff8f9479c102 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/OptionTwoResource.ts @@ -0,0 +1,75 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface OptionTwoResource + */ +export interface OptionTwoResource { + /** + * + */ + discriminatorField: OptionTwoResourceDiscriminatorFieldEnum; +} + + +/** + * @export + */ +export const OptionTwoResourceDiscriminatorFieldEnum = { + OptionTwo: 'optionTwo', +} as const; +export type OptionTwoResourceDiscriminatorFieldEnum = typeof OptionTwoResourceDiscriminatorFieldEnum[keyof typeof OptionTwoResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the OptionTwoResource interface. + */ +export function instanceOfOptionTwoResource(value: object): value is OptionTwoResource { + if (!('discriminatorField' in value) || value['discriminatorField'] === undefined) return false; + if (value['discriminatorField'] !== 'optionTwo') return false; + + return true; +} + +export function OptionTwoResourceFromJSON(json: any): OptionTwoResource { + return OptionTwoResourceFromJSONTyped(json, false); +} + +export function OptionTwoResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): OptionTwoResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminatorField'], + }; +} + +export function OptionTwoResourceToJSON(json: any): OptionTwoResource { + return OptionTwoResourceToJSONTyped(json, false); +} + +export function OptionTwoResourceToJSONTyped(value?: OptionTwoResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminatorField': value['discriminatorField'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionOneResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionOneResource.ts new file mode 100644 index 000000000000..b9a60f4ede79 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionOneResource.ts @@ -0,0 +1,82 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface SnakeOptionOneResource + */ +export interface SnakeOptionOneResource { + /** + * + */ + discriminatorField: SnakeOptionOneResourceDiscriminatorFieldEnum; + /** + * + */ + someProperty: string; +} + + +/** + * @export + */ +export const SnakeOptionOneResourceDiscriminatorFieldEnum = { + SnakeOptionOne: 'snakeOptionOne', +} as const; +export type SnakeOptionOneResourceDiscriminatorFieldEnum = typeof SnakeOptionOneResourceDiscriminatorFieldEnum[keyof typeof SnakeOptionOneResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the SnakeOptionOneResource interface. + */ +export function instanceOfSnakeOptionOneResource(value: object): value is SnakeOptionOneResource { + if ((!('discriminatorField' in (value as Record)) && !('discriminator_field' in (value as Record))) || ((value as Record)['discriminatorField'] === undefined && (value as Record)['discriminator_field'] === undefined)) return false; + if ((value as Record)['discriminatorField'] !== 'snakeOptionOne' && (value as Record)['discriminator_field'] !== 'snakeOptionOne') return false; + + if ((!('someProperty' in (value as Record)) && !('some_property' in (value as Record))) || ((value as Record)['someProperty'] === undefined && (value as Record)['some_property'] === undefined)) return false; + return true; +} + +export function SnakeOptionOneResourceFromJSON(json: any): SnakeOptionOneResource { + return SnakeOptionOneResourceFromJSONTyped(json, false); +} + +export function SnakeOptionOneResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): SnakeOptionOneResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminator_field'], + 'someProperty': json['some_property'], + }; +} + +export function SnakeOptionOneResourceToJSON(json: any): SnakeOptionOneResource { + return SnakeOptionOneResourceToJSONTyped(json, false); +} + +export function SnakeOptionOneResourceToJSONTyped(value?: SnakeOptionOneResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminator_field': value['discriminatorField'], + 'some_property': value['someProperty'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionTwoResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionTwoResource.ts new file mode 100644 index 000000000000..46a1e94897fa --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/SnakeOptionTwoResource.ts @@ -0,0 +1,82 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface SnakeOptionTwoResource + */ +export interface SnakeOptionTwoResource { + /** + * + */ + discriminatorField: SnakeOptionTwoResourceDiscriminatorFieldEnum; + /** + * + */ + someProperty: string; +} + + +/** + * @export + */ +export const SnakeOptionTwoResourceDiscriminatorFieldEnum = { + SnakeOptionTwo: 'snakeOptionTwo', +} as const; +export type SnakeOptionTwoResourceDiscriminatorFieldEnum = typeof SnakeOptionTwoResourceDiscriminatorFieldEnum[keyof typeof SnakeOptionTwoResourceDiscriminatorFieldEnum]; + + +/** + * Check if a given object implements the SnakeOptionTwoResource interface. + */ +export function instanceOfSnakeOptionTwoResource(value: object): value is SnakeOptionTwoResource { + if ((!('discriminatorField' in (value as Record)) && !('discriminator_field' in (value as Record))) || ((value as Record)['discriminatorField'] === undefined && (value as Record)['discriminator_field'] === undefined)) return false; + if ((value as Record)['discriminatorField'] !== 'snakeOptionTwo' && (value as Record)['discriminator_field'] !== 'snakeOptionTwo') return false; + + if ((!('someProperty' in (value as Record)) && !('some_property' in (value as Record))) || ((value as Record)['someProperty'] === undefined && (value as Record)['some_property'] === undefined)) return false; + return true; +} + +export function SnakeOptionTwoResourceFromJSON(json: any): SnakeOptionTwoResource { + return SnakeOptionTwoResourceFromJSONTyped(json, false); +} + +export function SnakeOptionTwoResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): SnakeOptionTwoResource { + if (json == null) { + return json; + } + return { + + 'discriminatorField': json['discriminator_field'], + 'someProperty': json['some_property'], + }; +} + +export function SnakeOptionTwoResourceToJSON(json: any): SnakeOptionTwoResource { + return SnakeOptionTwoResourceToJSONTyped(json, false); +} + +export function SnakeOptionTwoResourceToJSONTyped(value?: SnakeOptionTwoResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'discriminator_field': value['discriminatorField'], + 'some_property': value['someProperty'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestAResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestAResource.ts new file mode 100644 index 000000000000..3f561feb5ae1 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestAResource.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface TestAResource + */ +export interface TestAResource { + /** + * + */ + foo: string; +} + +/** + * Check if a given object implements the TestAResource interface. + */ +export function instanceOfTestAResource(value: object): value is TestAResource { + if (!('foo' in value) || value['foo'] === undefined) return false; + return true; +} + +export function TestAResourceFromJSON(json: any): TestAResource { + return TestAResourceFromJSONTyped(json, false); +} + +export function TestAResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestAResource { + if (json == null) { + return json; + } + return { + + 'foo': json['foo'], + }; +} + +export function TestAResourceToJSON(json: any): TestAResource { + return TestAResourceToJSONTyped(json, false); +} + +export function TestAResourceToJSONTyped(value?: TestAResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'foo': value['foo'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestArrayResponseResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestArrayResponseResource.ts new file mode 100644 index 000000000000..f46a98f117e9 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestArrayResponseResource.ts @@ -0,0 +1,84 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type {TestAResource} from './TestAResource'; +import {instanceOfTestAResource, TestAResourceFromJSONTyped, TestAResourceToJSON,} from './TestAResource'; +import type {TestBResource} from './TestBResource'; +import {instanceOfTestBResource, TestBResourceFromJSONTyped, TestBResourceToJSON,} from './TestBResource'; + +/** + * @type TestArrayResponseResource + * + * @export + */ +export type TestArrayResponseResource = Array | Array | Array; + +export function TestArrayResponseResourceFromJSON(json: any): TestArrayResponseResource { + return TestArrayResponseResourceFromJSONTyped(json, false); +} + +export function TestArrayResponseResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestArrayResponseResource { + if (json == null) { + return json; + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'object')) { + if (json.every(item => instanceOfTestAResource(item))) { + return json.map(value => TestAResourceFromJSONTyped(value, true)); + } + if (json.every(item => instanceOfTestBResource(item))) { + return json.map(value => TestBResourceFromJSONTyped(value, true)); + } + } + } + if (Array.isArray(json)) { + if (json.every(item => typeof item === 'string')) { + return json; + } + } + if (Array.isArray(json)) { + return json; + } + return {} as any; +} + +export function TestArrayResponseResourceToJSON(json: any): any { + return TestArrayResponseResourceToJSONTyped(json, false); +} + +export function TestArrayResponseResourceToJSONTyped(value?: TestArrayResponseResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'object')) { + if (value.every(item => instanceOfTestAResource(item))) { + return value.map(value => TestAResourceToJSON(value as TestAResource)); + } + if (value.every(item => instanceOfTestBResource(item))) { + return value.map(value => TestBResourceToJSON(value as TestBResource)); + } + } + } + if (Array.isArray(value)) { + if (value.every(item => typeof item === 'string')) { + return value; + } + } + if (Array.isArray(value)) { + return value; + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestBResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestBResource.ts new file mode 100644 index 000000000000..f3b6863429d3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestBResource.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface TestBResource + */ +export interface TestBResource { + /** + * + */ + bar: string; +} + +/** + * Check if a given object implements the TestBResource interface. + */ +export function instanceOfTestBResource(value: object): value is TestBResource { + if (!('bar' in value) || value['bar'] === undefined) return false; + return true; +} + +export function TestBResourceFromJSON(json: any): TestBResource { + return TestBResourceFromJSONTyped(json, false); +} + +export function TestBResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestBResource { + if (json == null) { + return json; + } + return { + + 'bar': json['bar'], + }; +} + +export function TestBResourceToJSON(json: any): TestBResource { + return TestBResourceToJSONTyped(json, false); +} + +export function TestBResourceToJSONTyped(value?: TestBResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'bar': value['bar'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDashedDiscriminatorResponseResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDashedDiscriminatorResponseResource.ts new file mode 100644 index 000000000000..27e4aa9f65db --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDashedDiscriminatorResponseResource.ts @@ -0,0 +1,62 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type {DashedOptionOneResource} from './DashedOptionOneResource'; +import {DashedOptionOneResourceFromJSONTyped, DashedOptionOneResourceToJSON,} from './DashedOptionOneResource'; +import type {DashedOptionTwoResource} from './DashedOptionTwoResource'; +import {DashedOptionTwoResourceFromJSONTyped, DashedOptionTwoResourceToJSON,} from './DashedOptionTwoResource'; + +/** + * @type TestDashedDiscriminatorResponseResource + * + * @export + */ +export type TestDashedDiscriminatorResponseResource = { discriminatorField: 'dashedOptionOne' } & DashedOptionOneResource | { discriminatorField: 'dashedOptionTwo' } & DashedOptionTwoResource; + +export function TestDashedDiscriminatorResponseResourceFromJSON(json: any): TestDashedDiscriminatorResponseResource { + return TestDashedDiscriminatorResponseResourceFromJSONTyped(json, false); +} + +export function TestDashedDiscriminatorResponseResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestDashedDiscriminatorResponseResource { + if (json == null) { + return json; + } + switch (json['discriminator-field']) { + case 'dashedOptionOne': + return Object.assign({}, DashedOptionOneResourceFromJSONTyped(json, true), { discriminatorField: 'dashedOptionOne' } as const); + case 'dashedOptionTwo': + return Object.assign({}, DashedOptionTwoResourceFromJSONTyped(json, true), { discriminatorField: 'dashedOptionTwo' } as const); + default: + return json; + } +} + +export function TestDashedDiscriminatorResponseResourceToJSON(json: any): any { + return TestDashedDiscriminatorResponseResourceToJSONTyped(json, false); +} + +export function TestDashedDiscriminatorResponseResourceToJSONTyped(value?: TestDashedDiscriminatorResponseResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + switch (value['discriminatorField']) { + case 'dashedOptionOne': + return Object.assign({}, DashedOptionOneResourceToJSON(value), { 'discriminator-field': 'dashedOptionOne' } as const); + case 'dashedOptionTwo': + return Object.assign({}, DashedOptionTwoResourceToJSON(value), { 'discriminator-field': 'dashedOptionTwo' } as const); + default: + return value; + } +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDiscriminatorResponseResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDiscriminatorResponseResource.ts new file mode 100644 index 000000000000..c356e1b3796f --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestDiscriminatorResponseResource.ts @@ -0,0 +1,62 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type {OptionOneResource} from './OptionOneResource'; +import {OptionOneResourceFromJSONTyped, OptionOneResourceToJSON,} from './OptionOneResource'; +import type {OptionTwoResource} from './OptionTwoResource'; +import {OptionTwoResourceFromJSONTyped, OptionTwoResourceToJSON,} from './OptionTwoResource'; + +/** + * @type TestDiscriminatorResponseResource + * + * @export + */ +export type TestDiscriminatorResponseResource = { discriminatorField: 'optionOne' } & OptionOneResource | { discriminatorField: 'optionTwo' } & OptionTwoResource; + +export function TestDiscriminatorResponseResourceFromJSON(json: any): TestDiscriminatorResponseResource { + return TestDiscriminatorResponseResourceFromJSONTyped(json, false); +} + +export function TestDiscriminatorResponseResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestDiscriminatorResponseResource { + if (json == null) { + return json; + } + switch (json['discriminatorField']) { + case 'optionOne': + return Object.assign({}, OptionOneResourceFromJSONTyped(json, true), { discriminatorField: 'optionOne' } as const); + case 'optionTwo': + return Object.assign({}, OptionTwoResourceFromJSONTyped(json, true), { discriminatorField: 'optionTwo' } as const); + default: + return json; + } +} + +export function TestDiscriminatorResponseResourceToJSON(json: any): any { + return TestDiscriminatorResponseResourceToJSONTyped(json, false); +} + +export function TestDiscriminatorResponseResourceToJSONTyped(value?: TestDiscriminatorResponseResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + switch (value['discriminatorField']) { + case 'optionOne': + return Object.assign({}, OptionOneResourceToJSON(value), { 'discriminatorField': 'optionOne' } as const); + case 'optionTwo': + return Object.assign({}, OptionTwoResourceToJSON(value), { 'discriminatorField': 'optionTwo' } as const); + default: + return value; + } +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestResponseResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestResponseResource.ts new file mode 100644 index 000000000000..63da3322e335 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestResponseResource.ts @@ -0,0 +1,72 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type {TestAResource} from './TestAResource'; +import {instanceOfTestAResource, TestAResourceFromJSONTyped, TestAResourceToJSON,} from './TestAResource'; +import type {TestBResource} from './TestBResource'; +import {instanceOfTestBResource, TestBResourceFromJSONTyped, TestBResourceToJSON,} from './TestBResource'; + +/** + * @type TestResponseResource + * + * @export + */ +export type TestResponseResource = TestAResource | TestBResource | string; + +export function TestResponseResourceFromJSON(json: any): TestResponseResource { + return TestResponseResourceFromJSONTyped(json, false); +} + +export function TestResponseResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestResponseResource { + if (json == null) { + return json; + } + if (typeof json !== 'object') { + return json; + } + if (instanceOfTestAResource(json)) { + return TestAResourceFromJSONTyped(json, true); + } + if (instanceOfTestBResource(json)) { + return TestBResourceFromJSONTyped(json, true); + } + if (typeof json === 'string') { + return json; + } + return {} as any; +} + +export function TestResponseResourceToJSON(json: any): any { + return TestResponseResourceToJSONTyped(json, false); +} + +export function TestResponseResourceToJSONTyped(value?: TestResponseResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + if (typeof value !== 'object') { + return value; + } + if (instanceOfTestAResource(value)) { + return TestAResourceToJSON(value as TestAResource); + } + if (instanceOfTestBResource(value)) { + return TestBResourceToJSON(value as TestBResource); + } + if (typeof value === 'string') { + return value; + } + return {}; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestSnakeCaseDiscriminatorResponseResource.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestSnakeCaseDiscriminatorResponseResource.ts new file mode 100644 index 000000000000..2267508503c4 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/TestSnakeCaseDiscriminatorResponseResource.ts @@ -0,0 +1,62 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import type {SnakeOptionOneResource} from './SnakeOptionOneResource'; +import {SnakeOptionOneResourceFromJSONTyped, SnakeOptionOneResourceToJSON,} from './SnakeOptionOneResource'; +import type {SnakeOptionTwoResource} from './SnakeOptionTwoResource'; +import {SnakeOptionTwoResourceFromJSONTyped, SnakeOptionTwoResourceToJSON,} from './SnakeOptionTwoResource'; + +/** + * @type TestSnakeCaseDiscriminatorResponseResource + * + * @export + */ +export type TestSnakeCaseDiscriminatorResponseResource = { discriminatorField: 'snakeOptionOne' } & SnakeOptionOneResource | { discriminatorField: 'snakeOptionTwo' } & SnakeOptionTwoResource; + +export function TestSnakeCaseDiscriminatorResponseResourceFromJSON(json: any): TestSnakeCaseDiscriminatorResponseResource { + return TestSnakeCaseDiscriminatorResponseResourceFromJSONTyped(json, false); +} + +export function TestSnakeCaseDiscriminatorResponseResourceFromJSONTyped(json: any, ignoreDiscriminator: boolean): TestSnakeCaseDiscriminatorResponseResource { + if (json == null) { + return json; + } + switch (json['discriminator_field']) { + case 'snakeOptionOne': + return Object.assign({}, SnakeOptionOneResourceFromJSONTyped(json, true), { discriminatorField: 'snakeOptionOne' } as const); + case 'snakeOptionTwo': + return Object.assign({}, SnakeOptionTwoResourceFromJSONTyped(json, true), { discriminatorField: 'snakeOptionTwo' } as const); + default: + return json; + } +} + +export function TestSnakeCaseDiscriminatorResponseResourceToJSON(json: any): any { + return TestSnakeCaseDiscriminatorResponseResourceToJSONTyped(json, false); +} + +export function TestSnakeCaseDiscriminatorResponseResourceToJSONTyped(value?: TestSnakeCaseDiscriminatorResponseResource | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + switch (value['discriminatorField']) { + case 'snakeOptionOne': + return Object.assign({}, SnakeOptionOneResourceToJSON(value), { 'discriminator_field': 'snakeOptionOne' } as const); + case 'snakeOptionTwo': + return Object.assign({}, SnakeOptionTwoResourceToJSON(value), { 'discriminator_field': 'snakeOptionTwo' } as const); + default: + return value; + } +} + diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/index.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/index.ts new file mode 100644 index 000000000000..8ba58df69efe --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/models/index.ts @@ -0,0 +1,16 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './DashedOptionOneResource'; +export * from './DashedOptionTwoResource'; +export * from './NumericSingletonEnumModelResource'; +export * from './OptionOneResource'; +export * from './OptionTwoResource'; +export * from './SnakeOptionOneResource'; +export * from './SnakeOptionTwoResource'; +export * from './TestAResource'; +export * from './TestArrayResponseResource'; +export * from './TestBResource'; +export * from './TestDashedDiscriminatorResponseResource'; +export * from './TestDiscriminatorResponseResource'; +export * from './TestResponseResource'; +export * from './TestSnakeCaseDiscriminatorResponseResource'; diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/runtime.ts new file mode 100644 index 000000000000..9ad5703db110 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/src/runtime.ts @@ -0,0 +1,505 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * testing oneOf without discriminator + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +export const BASE_PATH = "http://localhost:3000".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: Date | string): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + +export function mapValues(data: any, fn: (item: any) => any) { + const result: { [key: string]: any } = {}; + for (const key of Object.keys(data)) { + result[key] = fn(data[key]); + } + return result; +} + +// Pass-through serializer for `any`-typed properties in form data. See #1877. +export function anyToJSON(value: any): any { + return value; +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if (consume.contentType?.startsWith('multipart/form-data') == true) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.esm.json b/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.esm.json new file mode 100644 index 000000000000..2c0331cce040 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "esnext", + "outDir": "dist/esm" + } +} diff --git a/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.json b/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.json new file mode 100644 index 000000000000..f1d5adffdbf7 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/model-suffix/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "declaration": true, + "target": "es6", + "module": "commonjs", + "outDir": "dist", + "rootDir": "src", + "typeRoots": [ + "node_modules/@types" + ] + }, + "exclude": [ + "dist", + "node_modules" + ] +} From f8cf2ddc42d40ff842c6a368b54d82bc887c174d Mon Sep 17 00:00:00 2001 From: Wojciech Zankowski Date: Fri, 4 Sep 2026 22:29:37 +0200 Subject: [PATCH 2/3] feature: [typescript-fetch] add model suffix support --- docs/generators/typescript-fetch.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generators/typescript-fetch.md b/docs/generators/typescript-fetch.md index a51cfe50c40d..5445fecb591f 100644 --- a/docs/generators/typescript-fetch.md +++ b/docs/generators/typescript-fetch.md @@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| |licenseName|The name of the license| |null| |modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelSuffix|The suffix of the generated model.| |null| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| From 0785758467ebde5aa8919e80e4c9385f617fd29c Mon Sep 17 00:00:00 2001 From: Wojciech Zankowski Date: Fri, 4 Sep 2026 23:32:53 +0200 Subject: [PATCH 3/3] feature: [typescript-fetch] add model suffix support - unit test --- .../TypeScriptFetchClientCodegenTest.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index 4c9c71f1f2f2..026257786c78 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -6,9 +6,6 @@ import io.swagger.v3.oas.models.media.MapSchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; -import java.util.Collections; -import java.util.Locale; -import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; import org.openapitools.codegen.config.CodegenConfigurator; @@ -25,9 +22,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -561,6 +557,22 @@ public void containsESMTSConfigFileInCaseOfES6AndNPM() { assertThat(codegen.supportingFiles()).contains(new SupportingFile("tsconfig.esm.mustache", "", "tsconfig.esm.json")); } + @Test(description = "Verify model suffix is added to model name and model filename") + public void testModelSuffixGeneration() throws IOException { + Map properties = new HashMap<>(); + properties.put(TypeScriptFetchClientCodegen.MODEL_SUFFIX, "Resource"); + + File output = generate(properties, "src/test/resources/3_0/typescript-fetch/oneOf.yaml"); + + Path modelWithSuffix = Paths.get(output + "/models/TestBResource.ts"); + TestUtils.assertFileExists(modelWithSuffix); + TestUtils.assertFileContains(modelWithSuffix, "export interface TestBResource"); + + Path discriminatorModelWithSuffix = Paths.get(output + "/models/TestDiscriminatorResponseResource.ts"); + TestUtils.assertFileExists(discriminatorModelWithSuffix); + TestUtils.assertFileContains(discriminatorModelWithSuffix, "export type TestDiscriminatorResponseResource"); + } + @Test(description = "Verify file name formatting from model name in PascalCase") public void testModelFileNameInPascalCase() { final TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();