Skip to content

Commit 0708816

Browse files
authored
Merge pull request #10327 from swagger-api/html2BearerAuth
fix for security header html2 generator
2 parents 122b5ef + 8a8efcf commit 0708816

File tree

2 files changed

+409
-0
lines changed

2 files changed

+409
-0
lines changed

modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@
1818

1919
public class GeneratorServiceTest {
2020

21+
@Test(description = "test generator service with html2")
22+
public void testGeneratorService_HTML2_Bearer() throws IOException {
23+
24+
String path = getTmpFolder().getAbsolutePath();
25+
GenerationRequest request = new GenerationRequest();
26+
request
27+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
28+
.type(GenerationRequest.Type.CLIENT)
29+
.lang("html2")
30+
.spec(loadSpecAsNode("3_0_0/html2BearerAuthIssue.yaml", true, false))
31+
.options(
32+
new Options()
33+
.outputDir(path)
34+
);
35+
List<File> files = new GeneratorService().generationRequest(request).generate();
36+
Assert.assertFalse(files.isEmpty());
37+
for (File f: files) {
38+
String relPath = f.getAbsolutePath().substring(path.length());
39+
if ("/index.html".equals(relPath)) {
40+
//api key
41+
Assert.assertTrue(FileUtils.readFileToString(f).contains("curl -X GET\\\n" +
42+
"-H \"api_key: [[apiKey]]\"\\"));
43+
//basic
44+
Assert.assertTrue(FileUtils.readFileToString(f).contains("curl -X POST\\\n" +
45+
" -H \"Authorization: Basic [[basicHash]]\"\\"));
46+
//bearer
47+
Assert.assertTrue(FileUtils.readFileToString(f).contains("curl -X PUT\\\n" +
48+
" -H \"Authorization: Bearer [[accessToken]]\"\\"));
49+
}
50+
}
51+
52+
}
53+
2154
@Test(description = "test generator service with html2")
2255
public void testGeneratorService_HTML2() throws IOException {
2356

0 commit comments

Comments
 (0)