Skip to content

Commit

Permalink
[typescript] fix: explode: true should yield appended query params (
Browse files Browse the repository at this point in the history
#19519)

* [typescript] fix: `explode: true` should yield appended `query` params

* fix: object keys should be `set`
  • Loading branch information
joscha authored Sep 4, 2024
1 parent 8678ee8 commit f40f72c
Show file tree
Hide file tree
Showing 97 changed files with 14,183 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/configs/typescript-consolidated-explode-query.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: typescript
outputDir: samples/openapi3/client/petstore/typescript/builds/explode-query
inputSpec: modules/openapi-generator/src/test/resources/3_0/snakecase-discriminator.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
additionalProperties:
platform: node
npmName: ts-petstore-client
projectName: ts-petstore-client
moduleName: petstore
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,27 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {

// Query Params
if ({{paramName}} !== undefined) {
{{#isPrimitiveType}}
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isExplode}}
const serializedParams = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}");
{{#isArray}}
for (const serializedParam of serializedParams) {
requestContext.appendQueryParam("{{baseName}}", serializedParam);
}
{{/isArray}}
{{^isArray}}
for (const key of Object.keys(serializedParams)) {
requestContext.setQueryParam(key, serializedParams[key]);
}
{{/isArray}}
{{/isExplode}}
{{^isExplode}}
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
{{/isExplode}}
{{/isPrimitiveType}}
}
{{/queryParams}}
{{#headerParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export class RequestContext {
this.url.searchParams.set(name, value);
}

public appendQueryParam(name: string, value: string) {
this.url.searchParams.append(name, value);
}

/**
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.gitignore
AnotherFakeApi.md
DefaultApi.md
FakeApi.md
FakeClassnameTags123Api.md
PetApi.md
README.md
StoreApi.md
UserApi.md
apis/AnotherFakeApi.ts
apis/DefaultApi.ts
apis/FakeApi.ts
apis/FakeClassnameTags123Api.ts
apis/PetApi.ts
apis/StoreApi.ts
apis/UserApi.ts
apis/baseapi.ts
apis/exception.ts
auth/auth.ts
configuration.ts
git_push.sh
http/http.ts
http/isomorphic-fetch.ts
index.ts
middleware.ts
models/AdditionalPropertiesClass.ts
models/AllOfWithSingleRef.ts
models/Animal.ts
models/ApiResponse.ts
models/ArrayOfArrayOfNumberOnly.ts
models/ArrayOfNumberOnly.ts
models/ArrayTest.ts
models/Capitalization.ts
models/Cat.ts
models/Category.ts
models/ClassModel.ts
models/Client.ts
models/DeprecatedObject.ts
models/Dog.ts
models/EnumArrays.ts
models/EnumClass.ts
models/EnumTest.ts
models/FakeBigDecimalMap200Response.ts
models/FileSchemaTestClass.ts
models/Foo.ts
models/FooGetDefaultResponse.ts
models/FormatTest.ts
models/HasOnlyReadOnly.ts
models/HealthCheckResult.ts
models/List.ts
models/MapTest.ts
models/MixedPropertiesAndAdditionalPropertiesClass.ts
models/Model200Response.ts
models/ModelFile.ts
models/Name.ts
models/NullableClass.ts
models/NumberOnly.ts
models/ObjectSerializer.ts
models/ObjectWithDeprecatedFields.ts
models/Order.ts
models/OuterComposite.ts
models/OuterEnum.ts
models/OuterEnumDefaultValue.ts
models/OuterEnumInteger.ts
models/OuterEnumIntegerDefaultValue.ts
models/OuterObjectWithEnumProperty.ts
models/Pet.ts
models/ReadOnlyFirst.ts
models/Return.ts
models/SingleRefType.ts
models/SpecialModelName.ts
models/Tag.ts
models/User.ts
models/all.ts
package.json
rxjsStub.ts
servers.ts
tsconfig.json
types/ObjectParamAPI.ts
types/ObservableAPI.ts
types/PromiseAPI.ts
util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.9.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# petstore.AnotherFakeApi

All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**_123testSpecialTags**](AnotherFakeApi.md#_123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags


# **_123testSpecialTags**
> Client _123testSpecialTags(client)
To test special tags and operation ID starting with number

### Example


```typescript
import { petstore } from 'ts-petstore-client';
import * as fs from 'fs';

const configuration = petstore.createConfiguration();
const apiInstance = new petstore.AnotherFakeApi(configuration);

let body:petstore.AnotherFakeApi123testSpecialTagsRequest = {
// Client | client model
client: {
client: "client_example",
},
};

apiInstance._123testSpecialTags(body).then((data:any) => {
console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error));
```


### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**client** | **Client**| client model |


### Return type

**Client**

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | successful operation | - |

[[Back to top]](#) [[Back to API list]](README.md#documentation-for-api-endpoints) [[Back to Model list]](README.md#documentation-for-models) [[Back to README]](README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# petstore.DefaultApi

All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**fooGet**](DefaultApi.md#fooGet) | **GET** /foo |


# **fooGet**
> fooGet()

### Example


```typescript
import { petstore } from 'ts-petstore-client';
import * as fs from 'fs';

const configuration = petstore.createConfiguration();
const apiInstance = new petstore.DefaultApi(configuration);

let body:any = {};

apiInstance.fooGet(body).then((data:any) => {
console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error));
```


### Parameters
This endpoint does not need any parameter.


### Return type

void (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**0** | response | - |

[[Back to top]](#) [[Back to API list]](README.md#documentation-for-api-endpoints) [[Back to Model list]](README.md#documentation-for-models) [[Back to README]](README.md)


Loading

0 comments on commit f40f72c

Please sign in to comment.