Skip to content

Commit d5a680e

Browse files
[Extensions][Go][Java] Test x-auth-id-alias (OpenAPITools#6642)
Co-authored-by: Jim Schubert <[email protected]>
1 parent da9f2f7 commit d5a680e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6844
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: go-experimental
2+
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/go-experimental
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/go-experimental
5+
additionalProperties:
6+
packageName: x_auth_id_alias
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: java
2+
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8
3+
library: jersey2
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
5+
additionalProperties:
6+
artifactId: openapi3-extensions-x-auth-id-alias-jersey2-java8
7+
hideGenerationTimestamp: true

modules/openapi-generator/src/main/resources/go-experimental/api.mustache

+15-4
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,24 @@ func (r api{{operationId}}Request) Execute() ({{#returnType}}{{{.}}}, {{/returnT
252252
if r.ctx != nil {
253253
// API Key Authentication
254254
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
255-
if auth, ok := auth["{{#vendorExtensions.x-auth-id-alias}}{{.}}{{/vendorExtensions.x-auth-id-alias}}{{^vendorExtensions.x-auth-id-alias}}{{name}}{{/vendorExtensions.x-auth-id-alias}}"]; ok {
255+
{{#vendorExtensions.x-auth-id-alias}}
256+
if apiKey, ok := auth["{{.}}"]; ok {
256257
var key string
257-
if auth.Prefix != "" {
258-
key = auth.Prefix + " " + auth.Key
258+
if prefix, ok := auth["{{name}}"]; ok && prefix.Prefix != "" {
259+
key = prefix.Prefix + " " + apiKey.Key
259260
} else {
260-
key = auth.Key
261+
key = apiKey.Key
261262
}
263+
{{/vendorExtensions.x-auth-id-alias}}
264+
{{^vendorExtensions.x-auth-id-alias}}
265+
if apiKey, ok := auth["{{name}}"]; ok {
266+
var key string
267+
if apiKey.Prefix != "" {
268+
key = apiKey.Prefix + " " + apiKey.Key
269+
} else {
270+
key = apiKey.Key
271+
}
272+
{{/vendorExtensions.x-auth-id-alias}}
262273
{{#isKeyInHeader}}
263274
localVarHeaderParams["{{keyParamName}}"] = key
264275
{{/isKeyInHeader}}

samples/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ func (r apiTestClassnameRequest) Execute() (Client, *_nethttp.Response, error) {
9797
if r.ctx != nil {
9898
// API Key Authentication
9999
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
100-
if auth, ok := auth["api_key_query"]; ok {
100+
if apiKey, ok := auth["api_key_query"]; ok {
101101
var key string
102-
if auth.Prefix != "" {
103-
key = auth.Prefix + " " + auth.Key
102+
if apiKey.Prefix != "" {
103+
key = apiKey.Prefix + " " + apiKey.Key
104104
} else {
105-
key = auth.Key
105+
key = apiKey.Key
106106
}
107107
localVarQueryParams.Add("api_key_query", key)
108108
}

samples/client/petstore/go-experimental/go-petstore/api_pet.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,12 @@ func (r apiGetPetByIdRequest) Execute() (Pet, *_nethttp.Response, error) {
489489
if r.ctx != nil {
490490
// API Key Authentication
491491
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
492-
if auth, ok := auth["api_key"]; ok {
492+
if apiKey, ok := auth["api_key"]; ok {
493493
var key string
494-
if auth.Prefix != "" {
495-
key = auth.Prefix + " " + auth.Key
494+
if apiKey.Prefix != "" {
495+
key = apiKey.Prefix + " " + apiKey.Key
496496
} else {
497-
key = auth.Key
497+
key = apiKey.Key
498498
}
499499
localVarHeaderParams["api_key"] = key
500500
}

samples/client/petstore/go-experimental/go-petstore/api_store.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func (r apiGetInventoryRequest) Execute() (map[string]int32, *_nethttp.Response,
176176
if r.ctx != nil {
177177
// API Key Authentication
178178
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
179-
if auth, ok := auth["api_key"]; ok {
179+
if apiKey, ok := auth["api_key"]; ok {
180180
var key string
181-
if auth.Prefix != "" {
182-
key = auth.Prefix + " " + auth.Key
181+
if apiKey.Prefix != "" {
182+
key = apiKey.Prefix + " " + apiKey.Key
183183
} else {
184-
key = auth.Key
184+
key = apiKey.Key
185185
}
186186
localVarHeaderParams["api_key"] = key
187187
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.gitignore
2+
.travis.yml
3+
README.md
4+
api/openapi.yaml
5+
api_usage.go
6+
client.go
7+
configuration.go
8+
docs/UsageApi.md
9+
git_push.sh
10+
go.mod
11+
go.sum
12+
response.go
13+
utils.go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.0.0-SNAPSHOT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: go
2+
3+
install:
4+
- go get -d -v .
5+
6+
script:
7+
- go build -v ./
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Go API client for x_auth_id_alias
2+
3+
This specification shows how to use x-auth-id-alias extension for API keys.
4+
5+
## Overview
6+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.
7+
8+
- API version: 1.0.0
9+
- Package version: 1.0.0
10+
- Build package: org.openapitools.codegen.languages.GoClientExperimentalCodegen
11+
12+
## Installation
13+
14+
Install the following dependencies:
15+
16+
```shell
17+
go get github.com/stretchr/testify/assert
18+
go get golang.org/x/oauth2
19+
go get golang.org/x/net/context
20+
```
21+
22+
Put the package under your project folder and add the following in import:
23+
24+
```golang
25+
import sw "./x_auth_id_alias"
26+
```
27+
28+
## Configuration of Server URL
29+
30+
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
31+
32+
### Select Server Configuration
33+
34+
For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`.
35+
36+
```golang
37+
ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)
38+
```
39+
40+
### Templated Server URL
41+
42+
Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`.
43+
44+
```golang
45+
ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
46+
"basePath": "v2",
47+
})
48+
```
49+
50+
Note, enum values are always validated and all unused variables are silently ignored.
51+
52+
### URLs Configuration per Operation
53+
54+
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
55+
An operation is uniquely identifield by `"{classname}Service.{nickname}"` string.
56+
Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps.
57+
58+
```
59+
ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
60+
"{classname}Service.{nickname}": 2,
61+
})
62+
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
63+
"{classname}Service.{nickname}": {
64+
"port": "8443",
65+
},
66+
})
67+
```
68+
69+
## Documentation for API Endpoints
70+
71+
All URIs are relative to *http://petstore.swagger.io:80/v2*
72+
73+
Class | Method | HTTP request | Description
74+
------------ | ------------- | ------------- | -------------
75+
*UsageApi* | [**AnyKey**](docs/UsageApi.md#anykey) | **Get** /any | Use any API key
76+
*UsageApi* | [**BothKeys**](docs/UsageApi.md#bothkeys) | **Get** /both | Use both API keys
77+
*UsageApi* | [**KeyInHeader**](docs/UsageApi.md#keyinheader) | **Get** /header | Use API key in header
78+
*UsageApi* | [**KeyInQuery**](docs/UsageApi.md#keyinquery) | **Get** /query | Use API key in query
79+
80+
81+
## Documentation For Models
82+
83+
84+
85+
## Documentation For Authorization
86+
87+
88+
89+
### api_key
90+
91+
- **Type**: API key
92+
- **API key parameter name**: X-Api-Key
93+
- **Location**: HTTP header
94+
95+
Note, each API key must be added to a map of `map[string]APIKey` where the key is: X-Api-Key and passed in as the auth context for each request.
96+
97+
98+
### api_key_query
99+
100+
- **Type**: API key
101+
- **API key parameter name**: api_key
102+
- **Location**: URL query string
103+
104+
Note, each API key must be added to a map of `map[string]APIKey` where the key is: api_key and passed in as the auth context for each request.
105+
106+
107+
## Documentation for Utility Methods
108+
109+
Due to the fact that model structure members are all pointers, this package contains
110+
a number of utility functions to easily obtain pointers to values of basic types.
111+
Each of these functions takes a value of the given basic type and returns a pointer to it:
112+
113+
* `PtrBool`
114+
* `PtrInt`
115+
* `PtrInt32`
116+
* `PtrInt64`
117+
* `PtrFloat`
118+
* `PtrFloat32`
119+
* `PtrFloat64`
120+
* `PtrString`
121+
* `PtrTime`
122+
123+
## Author
124+
125+
126+

0 commit comments

Comments
 (0)