Skip to content

Commit 152df38

Browse files
authored
Merge pull request #852 from reta/fix.oauth.scope
Scope is not added properly in generated code
2 parents f361662 + 412c59f commit 152df38

30 files changed

Lines changed: 69 additions & 68 deletions

File tree

src/main/java/io/swagger/codegen/v3/generators/scala/ScalaClientCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public ScalaClientCodegen() {
7878
gradleWrapperPackage.replace( ".", File.separator ), "gradle-wrapper.jar") );
7979

8080
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
81-
81+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
82+
8283
importMapping.remove("List");
8384
importMapping.remove("Set");
8485
importMapping.remove("Map");

src/main/resources/handlebars/Java/README.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ Class | Method | HTTP request | Description
151151
- **Flow**: {{flow}}
152152
- **Authorization URL**: {{authorizationUrl}}
153153
- **Scopes**: {{^scopes}}N/A{{/scopes}}
154-
{{#scopes}} - {{scope}}: {{description}}
155-
{{/scopes}}
154+
{{#each scopes}} - {{@key}}: {{this}}
155+
{{/each}}
156156
{{/isOAuth}}
157157

158158
{{/authMethods}}

src/main/resources/handlebars/Java/libraries/feign/ApiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ApiClient {
6262
auth = new ApiKeyAuth({{#is this 'key-in-header'}}"header"{{/is}}{{#isNot this 'key-in-header'}}"query"{{/isNot}}, "{{keyParamName}}");
6363
{{/is}}
6464
{{#is this 'oauth'}}
65-
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");
65+
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#each scopes}}{{@key}}{{^@last}}, {{/@last}}{{/each}}");
6666
{{/is}}
6767
} else {{/authMethods}}{
6868
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");

src/main/resources/handlebars/Java/libraries/retrofit/ApiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ApiClient {
6262
{{#is this 'api-key'}}
6363
auth = new ApiKeyAuth({{#is this 'key-in-header'}}"header"{{/is}}{{#isNot this 'key-in-header'}}"query"{{/isNot}}, "{{keyParamName}}");{{/is}}
6464
{{#is this 'oauth'}}
65-
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");
65+
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#each scopes}}{{@key}}{{^@last}}, {{/@last}}{{/each}}");
6666
{{/is}}
6767
} else {{/authMethods}}{
6868
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");

src/main/resources/handlebars/Java/libraries/retrofit2/ApiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class ApiClient {
7070
auth = new ApiKeyAuth({{#is this 'key-in-header'}}"header"{{/is}}{{#isNot this 'key-in-header'}}"query"{{/isNot}}, "{{keyParamName}}");
7171
{{/is}}
7272
{{#is this 'oauth'}}
73-
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");
73+
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#each scopes}}{{@key}}{{^@last}}, {{/@last}}{{/each}}");
7474
{{/is}}
7575
} else {{/authMethods}}{
7676
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");

src/main/resources/handlebars/JavaJaxRS/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public class {{classname}} {
8383
{{#useOas2}}
8484
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
8585
{{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
86-
{{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
87-
{{/hasMore}}{{/scopes}}
86+
{{#each scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{@key}}", description = "{{this}}"){{^@last}},
87+
{{/@last}}{{/each}}
8888
}{{/isOAuth}}){{#hasMore}},
8989
{{/hasMore}}{{/authMethods}}
9090
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
@@ -95,8 +95,8 @@ public class {{classname}} {
9595
{{^useOas2}}
9696
@Operation(summary = "{{{summary}}}", description = "{{{notes}}}"{{#hasAuthMethods}}, security = {
9797
{{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = {
98-
{{#scopes}}"{{scope}}"{{#hasMore}},
99-
{{/hasMore}}{{/scopes}}
98+
{{#each scopes}}"{{@key}}"{{^@last}},
99+
{{/@last}}{{/each}}
100100
}{{/isOAuth}}){{#hasMore}},
101101
{{/hasMore}}{{/authMethods}}
102102
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })

src/main/resources/handlebars/JavaJaxRS/cxf-cdi/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public class {{classname}} {
5959
{{#useOas2}}
6060
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
6161
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
62-
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
63-
{{/hasMore}}{{/scopes}}
62+
{{#each scopes}}@AuthorizationScope(scope = "{{@key}}", description = "{{this}}"){{^@last}},
63+
{{/@last}}{{/each}}
6464
}{{/isOAuth}}){{#hasMore}},
6565
{{/hasMore}}{{/authMethods}}
6666
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })
@@ -70,8 +70,8 @@ public class {{classname}} {
7070
{{^useOas2}}
7171
@Operation(summary = "{{{summary}}}", description = "{{{notes}}}"{{#hasAuthMethods}}, security = {
7272
{{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = {
73-
{{#scopes}}"{{scope}}"{{#hasMore}},
74-
{{/hasMore}}{{/scopes}}
73+
{{#each scopes}}"{{@key}}"{{^@last}},
74+
{{/@last}}{{/each}}
7575
}{{/isOAuth}}){{#hasMore}},
7676
{{/hasMore}}{{/authMethods}}
7777
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })

src/main/resources/handlebars/JavaJaxRS/di/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public class {{classname}} {
6666
{{#useOas2}}
6767
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
6868
{{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
69-
{{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
70-
{{/hasMore}}{{/scopes}}
69+
{{#each scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{@key}}", description = "{{this}}"){{^@last}},
70+
{{/@last}}{{/each}}
7171
}{{/isOAuth}}){{#hasMore}},
7272
{{/hasMore}}{{/authMethods}}
7373
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
@@ -78,8 +78,8 @@ public class {{classname}} {
7878
{{^useOas2}}
7979
@Operation(summary = "{{{summary}}}", description = "{{{notes}}}"{{#hasAuthMethods}}, security = {
8080
{{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = {
81-
{{#scopes}}"{{scope}}"{{#hasMore}},
82-
{{/hasMore}}{{/scopes}}
81+
{{#each scopes}}"{{@key}}"{{^@last}},
82+
{{/@last}}{{/each}}
8383
}{{/isOAuth}}){{#hasMore}},
8484
{{/hasMore}}{{/authMethods}}
8585
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })

src/main/resources/handlebars/JavaJaxRS/libraries/jersey1/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class {{classname}} {
4747
{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
4848
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
4949
{{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
50-
{{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
51-
{{/hasMore}}{{/scopes}}
50+
{{#each scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{@key}}", description = "{{this}}"){{^@last}},
51+
{{/@last}}{{/each}}
5252
}{{/isOAuth}}){{#hasMore}},
5353
{{/hasMore}}{{/authMethods}}
5454
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })

src/main/resources/handlebars/JavaJaxRS/resteasy/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public class {{classname}} {
6464
{{#useOas2}}
6565
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
6666
{{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
67-
{{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},{{/hasMore}}
68-
{{/scopes}}
67+
{{#each scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{@key}}", description = "{{this}}"){{^@last}},{{/@last}}
68+
{{/each}}
6969
}{{/isOAuth}}){{#hasMore}},{{/hasMore}}
7070
{{/authMethods}}
7171
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
@@ -77,8 +77,8 @@ public class {{classname}} {
7777
{{^useOas2}}
7878
@Operation(summary = "{{{summary}}}", description = "{{{notes}}}"{{#hasAuthMethods}}, security = {
7979
{{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = {
80-
{{#scopes}}"{{scope}}"{{#hasMore}},{{/hasMore}}
81-
{{/scopes}}
80+
{{#each scopes}}"{{@key}}"{{^@last}},{{/@last}}
81+
{{/each}}
8282
}{{/isOAuth}}){{#hasMore}},{{/hasMore}}
8383
{{/authMethods}}
8484
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })

0 commit comments

Comments
 (0)