Skip to content

Commit 7ef26c9

Browse files
committed
Merge remote-tracking branch 'origin/master' into fixup_xmltree
2 parents 3346ae8 + 7af84ca commit 7ef26c9

File tree

38 files changed

+292
-80
lines changed

38 files changed

+292
-80
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Samples Go Clients
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/**'
7+
pull_request:
8+
paths:
9+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/**'
10+
11+
jobs:
12+
build:
13+
name: Build Go
14+
runs-on: windows-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
sample:
19+
- 'samples/openapi3/client/petstore/go/go-petstore-aws-signature/'
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-go@v5
23+
- run: go version
24+
- name: Install Dependencies
25+
working-directory: ${{ matrix.sample }}
26+
run: |
27+
go mod tidy
28+
- name: Run test
29+
working-directory: ${{ matrix.sample }}
30+
run: go test -mod=mod -v
31+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: go
2+
outputDir: samples/openapi3/client/petstore/go/go-petstore-aws-signature
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/go
5+
additionalProperties:
6+
enumClassPrefix: "true"
7+
packageName: petstore
8+
disallowAdditionalPropertiesIfNotPresent: false
9+
withAWSV4Signature: true
10+

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,21 +787,26 @@ private ExtendedCodegenModel processCodeGenModel(ExtendedCodegenModel cm) {
787787
.map(CodegenComposedSchemas::getOneOf)
788788
.orElse(Collections.emptyList());
789789

790+
// create a set of any non-primitive, non-array types used in the oneOf schemas which will
791+
// need to be imported.
790792
cm.oneOfModels = oneOfsList.stream()
791-
.filter(CodegenProperty::getIsModel)
793+
.filter(cp -> !cp.getIsPrimitiveType() && !cp.getIsArray())
792794
.map(CodegenProperty::getBaseType)
793795
.filter(Objects::nonNull)
794796
.collect(Collectors.toCollection(TreeSet::new));
795797

798+
// create a set of any complex, inner types used by arrays in the oneOf schema (e.g. if
799+
// the oneOf uses Array<Foo>, Foo needs to be imported).
796800
cm.oneOfArrays = oneOfsList.stream()
797801
.filter(CodegenProperty::getIsArray)
798802
.map(CodegenProperty::getComplexType)
799803
.filter(Objects::nonNull)
800804
.collect(Collectors.toCollection(TreeSet::new));
801805

806+
// create a set of primitive types used in the oneOf schemas for use in the to & from
807+
// typed JSON methods.
802808
cm.oneOfPrimitives = oneOfsList.stream()
803809
.filter(CodegenProperty::getIsPrimitiveType)
804-
.filter(Objects::nonNull)
805810
.collect(Collectors.toCollection(HashSet::new));
806811

807812
if (!cm.oneOf.isEmpty()) {
@@ -1485,6 +1490,9 @@ public class ExtendedCodegenModel extends CodegenModel {
14851490
@Getter @Setter
14861491
public Set<String> modelImports = new TreeSet<String>();
14871492

1493+
// oneOfModels, oneOfArrays & oneOfPrimitives contain a list of types used in schemas
1494+
// composed with oneOf and are used to define the import list and the to & from
1495+
// 'TypedJSON' conversion methods in the composed model classes.
14881496
@Getter @Setter
14891497
public Set<String> oneOfModels = new TreeSet<>();
14901498
@Getter @Setter

modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ include(PreTarget.cmake OPTIONAL)
9191
set(PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
9292

9393
# Add library with project file with project name as library name
94-
add_library(${pkgName} ${SRCS} ${HDRS})
94+
if(NOT BUILD_STATIC_LIBS)
95+
add_library(${pkgName} ${SRCS} ${HDRS})
96+
else()
97+
add_library(${pkgName} STATIC ${SRCS} ${HDRS})
98+
endif()
9599
# Link dependent libraries
96100
if(NOT CMAKE_VERSION VERSION_LESS 3.4)
97101
target_link_libraries(${pkgName} PRIVATE OpenSSL::SSL OpenSSL::Crypto)

modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ apiClient_t *apiClient_create() {
1111
apiClient->basePath = strdup("{{{basePath}}}");
1212
apiClient->sslConfig = NULL;
1313
apiClient->curlConfig = NULL;
14+
apiClient->curl_pre_invoke_func = NULL;
1415
apiClient->dataReceived = NULL;
1516
apiClient->dataReceivedLen = 0;
1617
apiClient->data_callback_func = NULL;
@@ -67,6 +68,7 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
6768
apiClient->curlConfig->keepidle = 120;
6869
apiClient->curlConfig->keepintvl = 60;
6970

71+
apiClient->curl_pre_invoke_func = NULL;
7072
apiClient->dataReceived = NULL;
7173
apiClient->dataReceivedLen = 0;
7274
apiClient->data_callback_func = NULL;
@@ -155,6 +157,8 @@ void apiClient_free(apiClient_t *apiClient) {
155157
apiClient->curlConfig = NULL;
156158
}
157159

160+
apiClient->curl_pre_invoke_func = NULL;
161+
158162
free(apiClient);
159163
}
160164

@@ -564,6 +568,10 @@ void apiClient_invoke(apiClient_t *apiClient,
564568
curl_easy_setopt(handle, CURLOPT_VERBOSE, apiClient->curlConfig->verbose);
565569
}
566570

571+
if(apiClient->curl_pre_invoke_func) {
572+
apiClient->curl_pre_invoke_func(handle);
573+
}
574+
567575
res = curl_easy_perform(handle);
568576

569577
curl_slist_free_all(headers);

modules/openapi-generator/src/main/resources/C-libcurl/apiClient.h.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct apiClient_t {
3232
char *basePath;
3333
sslConfig_t *sslConfig;
3434
curlConfig_t *curlConfig;
35+
void (*curl_pre_invoke_func)(CURL *);
3536
void *dataReceived;
3637
long dataReceivedLen;
3738
void (*data_callback_func)(void **, long *);

modules/openapi-generator/src/main/resources/go/client.mustache

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
"golang.org/x/oauth2"
2828
{{/hasOAuthMethods}}
2929
{{#withAWSV4Signature}}
30-
awsv4 "github.com/aws/aws-sdk-go/aws/signer/v4"
31-
awscredentials "github.com/aws/aws-sdk-go/aws/credentials"
30+
awsv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
31+
awscredentials "github.com/aws/aws-sdk-go-v2/credentials"
32+
"crypto/sha256"
33+
"encoding/hex"
3234
{{/withAWSV4Signature}}
3335
)
3436

@@ -458,13 +460,10 @@ func (c *APIClient) prepareRequest(
458460
{{#withAWSV4Signature}}
459461
// AWS Signature v4 Authentication
460462
if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok {
461-
creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, auth.SessionToken)
462-
signer := awsv4.NewSigner(creds)
463-
var reader *strings.Reader
464-
if body == nil {
465-
reader = strings.NewReader("")
466-
} else {
467-
reader = strings.NewReader(body.String())
463+
credsProvider := awscredentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken)
464+
creds, err := credsProvider.Retrieve(ctx)
465+
if err != nil {
466+
return nil, err
468467
}
469468
470469
// Define default values for region and service to maintain backward compatibility
@@ -477,8 +476,22 @@ func (c *APIClient) prepareRequest(
477476
service = "oapi"
478477
}
479478
480-
timestamp := time.Now()
481-
_, err := signer.Sign(localVarRequest, reader, service, region, timestamp)
479+
// Compute payload hash from the request body
480+
var payloadHash string
481+
if body == nil {
482+
// Empty body
483+
hash := sha256.Sum256([]byte(""))
484+
payloadHash = hex.EncodeToString(hash[:])
485+
} else {
486+
// Hash the actual body content
487+
bodyBytes := []byte(body.String())
488+
hash := sha256.Sum256(bodyBytes)
489+
payloadHash = hex.EncodeToString(hash[:])
490+
}
491+
492+
// Sign the request with the computed payload hash
493+
signer := awsv4.NewSigner()
494+
err = signer.SignHTTP(ctx, creds, localVarRequest, payloadHash, service, region, time.Now())
482495
if err != nil {
483496
return nil, err
484497
}

modules/openapi-generator/src/main/resources/go/go.mod.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
golang.org/x/oauth2 v0.27.0
99
{{/hasOAuthMethods}}
1010
{{#withAWSV4Signature}}
11-
github.com/aws/aws-sdk-go v1.34.14
11+
github.com/aws/aws-sdk-go-v2 v1.37.0
1212
{{/withAWSV4Signature}}
1313
{{#importValidator}}
1414
gopkg.in/validator.v2 v2.0.1

modules/openapi-generator/src/main/resources/rust-server-deprecated/Cargo.mustache

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ validator = { version = "0.16", features = ["derive"] }
9999

100100
# Crates included if required by the API definition
101101
{{#usesXml}}
102-
# TODO: this should be updated to point at the official crate once
103-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
104-
#serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
105102
serde-xml-rs = "0.8"
106103
{{/usesXml}}
107104
{{#apiUsesMultipart}}

modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ validator = { version = "0.20", features = ["derive"] }
9494

9595
# Crates included if required by the API definition
9696
{{#usesXml}}
97-
# TODO: this should be updated to point at the official crate once
98-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
99-
#serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
100-
serde-xml-rs = "0.8"{{/usesXml}}
97+
serde-xml-rs = "0.8"
98+
{{/usesXml}}
10199
{{#apiUsesMultipartFormData}}
102100
multipart = { version = "0.18", default-features = false, optional = true }
103101
{{/apiUsesMultipartFormData}}

0 commit comments

Comments
 (0)