mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Adds Auth Handling in Jetbrains template
* Reformats OpenDOTA Json spec
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
## {{#notes}}{{notes}}{{/notes}}
|
||||
# @name {{operationId}}
|
||||
{{httpMethod}} {{basePath}}{{#lambda.doubleMustache}}{{path}}{{/lambda.doubleMustache}}
|
||||
{{#authMethods}}{{#isBasicBasic}}Authorization: Basic {{#lambda.doubleMustache}}{username}{{/lambda.doubleMustache}} {{#lambda.doubleMustache}}{password}{{/lambda.doubleMustache}}
|
||||
{{/isBasicBasic}}{{#isBasicBearer}}Authorization: {{#lambda.doubleMustache}}{token}{{/lambda.doubleMustache}}
|
||||
{{/isBasicBearer}}{{#isApiKey}}{{keyParamName}} {{#lambda.doubleMustache}}{apiKey}{{/lambda.doubleMustache}}
|
||||
{{/isApiKey}}{{/authMethods}}
|
||||
{{#consumes}}Content-Type: {{{mediaType}}}
|
||||
{{/consumes}}
|
||||
{{#bodyParams}}
|
||||
|
||||
@@ -7,14 +7,12 @@ import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static org.openapitools.codegen.TestUtils.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JetbrainsHttpClientClientCodegenTest {
|
||||
|
||||
@@ -61,4 +59,28 @@ public class JetbrainsHttpClientClientCodegenTest {
|
||||
|
||||
assertFileContentEquals(path, Paths.get("src/test/resources/3_0/jetbrains-http-client/BasicResult.http"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthIsPresent() throws IOException {
|
||||
|
||||
// TODO : test various combinations of auth types
|
||||
|
||||
File output = Files.createTempDirectory("jetbrains-http-client-test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("jetbrains-http-client")
|
||||
.setInputSpec("src/test/resources/3_0/jetbrains-http-client/BasicWithAuth.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(clientOptInput).generate();
|
||||
files.forEach(File::deleteOnExit);
|
||||
|
||||
Path path = Paths.get(output + "/Apis/BasicApi.http");
|
||||
assertFileExists(path);
|
||||
|
||||
assertFileContains(path, "Authorization: Basic {{username}} {{password}}", "X-API-Key {{apiKey}}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Basic
|
||||
version: '1.0'
|
||||
description: Sample API
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: 'https://www.apache.org/licenses/LICENSE-2.0'
|
||||
servers:
|
||||
- url: 'http://localhost:5001/v1'
|
||||
description: dev server
|
||||
- url: 'http://localhost:5001/v1'
|
||||
description: test server
|
||||
paths:
|
||||
'/users/{userId}':
|
||||
get:
|
||||
summary: Get User
|
||||
description: Get User Info by User ID
|
||||
operationId: get-users-userId
|
||||
tags:
|
||||
- basic
|
||||
security:
|
||||
- BasicAuth: []
|
||||
- ApiKeyAuth: []
|
||||
parameters:
|
||||
- description: Unique identifier of the user
|
||||
name: userId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: User Found
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/User'
|
||||
examples:
|
||||
Get User Alice Smith (json):
|
||||
value:
|
||||
id: 142
|
||||
firstName: Alice
|
||||
lastName: Smith
|
||||
email: alice.smith@gmail.com
|
||||
dateOfBirth: '1997-10-31'
|
||||
emailVerified: true
|
||||
signUpDate: '2019-08-24'
|
||||
application/xml:
|
||||
schema:
|
||||
$ref: '#/components/schemas/User'
|
||||
examples:
|
||||
Get User Alice Smith (xml):
|
||||
value:
|
||||
id: 143
|
||||
firstName: Alice
|
||||
lastName: Smith
|
||||
email: alice.smith@gmail.com
|
||||
dateOfBirth: '1997-10-31'
|
||||
emailVerified: true
|
||||
signUpDate: '2019-08-24'
|
||||
'404':
|
||||
description: User Not Found
|
||||
components:
|
||||
securitySchemes:
|
||||
ApiKeyAuth:
|
||||
in: header
|
||||
name: X-API-Key
|
||||
type: apiKey
|
||||
BasicAuth:
|
||||
scheme: basic
|
||||
type: http
|
||||
schemas:
|
||||
User:
|
||||
title: User
|
||||
type: object
|
||||
description: ''
|
||||
x-examples:
|
||||
Alice Smith:
|
||||
id: 144
|
||||
firstName: Alice
|
||||
lastName: Smith
|
||||
email: alice.smith@gmail.com
|
||||
dateOfBirth: '1997-10-31'
|
||||
emailVerified: true
|
||||
signUpDate: '2019-08-24'
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
description: Unique identifier for the given user.
|
||||
firstName:
|
||||
type: string
|
||||
lastName:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
dateOfBirth:
|
||||
type: string
|
||||
format: date
|
||||
example: '1997-10-31'
|
||||
emailVerified:
|
||||
type: boolean
|
||||
description: Set to true if the user's email has been verified.
|
||||
createDate:
|
||||
type: string
|
||||
format: date
|
||||
description: The date that the user was created.
|
||||
required:
|
||||
- id
|
||||
- firstName
|
||||
- lastName
|
||||
- email
|
||||
- emailVerified
|
||||
tags:
|
||||
- name: basic
|
||||
description: Basic tag
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user