add security generation - TINetworking 1.20.0

This commit is contained in:
Ivan Smolin 2022-06-10 14:55:33 +03:00
parent f7488a5731
commit 4569a09cbf
7 changed files with 26 additions and 50 deletions

View File

@ -5,7 +5,7 @@
<artifactId>TINetworking-swagger-codegen</artifactId>
<packaging>jar</packaging>
<name>TINetworking-swagger-codegen</name>
<version>1.1.8</version>
<version>1.2.0</version>
<build>
<plugins>
<plugin>

View File

@ -208,9 +208,9 @@ public class TINetworkingCodegen extends DefaultCodegenConfig {
sourceFolder,
projectName + "+Servers.swift"));
supportingFiles.add(new SupportingFile("Plugins.mustache",
supportingFiles.add(new SupportingFile("OpenAPI.mustache",
sourceFolder,
"Plugins.swift"));
projectName + "+OpenAPI.swift"));
copyFistAllOfProperties = true;
}

View File

@ -0,0 +1,17 @@
import TINetworking
public extension OpenAPI {
enum SecurityNames: String, Hashable {
{{#authMethods}}
case {{name}}
{{/authMethods}}
}
static var {{projectName}}: Self {
.init(defaultServer: .default, security: [
{{#authMethods}}
"{{name}}": {{#isApiKey}}.apiKey({{#isKeyInHeader}}.header{{/isKeyInHeader}}{{#isKeyInQuery}}.query{{/isKeyInQuery}}, parameterName: "{{keyParamName}}"){{/isApiKey}}{{#isBearer}}.http(.bearer){{/isBearer}}{{#isBasic}}.http(.basic){{/isBasic}}{{#hasMore}},{{/hasMore}}
{{/authMethods}}
])
}
}

View File

@ -1,26 +0,0 @@
import TIMoyaNetworking
import Alamofire
{{#authMethods}}
{{#isApiKey}}
{{#isKeyInHeader}}
public struct {{name}}Plugin: AdditionalHeadersPlugin {
public typealias HeaderValueProvider = () -> String?
private let headerValueProvider: HeaderValueProvider
public init(headerValueProvider: @escaping HeaderValueProvider) {
self.headerValueProvider = headerValueProvider
}
public var additionalHeaders: HTTPHeaders {
guard let value = headerValueProvider() else {
return HTTPHeaders()
}
return HTTPHeaders(["{{{keyParamName}}}": value])
}
}
{{/isKeyInHeader}}
{{/isApiKey}}
{{/authMethods}}

View File

@ -1,9 +1,3 @@
// {{projectName}}+Servers.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import TINetworking
public extension Server {

View File

@ -1,9 +1,4 @@
{{#operations}}//
// {{classname}}.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
{{#operations}}
import Alamofire
import TINetworking
@ -40,16 +35,16 @@ public extension EndpointRequest {
- parameter {{paramName}}: {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/parameters}}
*/
static func {{operationId}}({{#parameters}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}{{#hasParams}}, {{/hasParams}}server: Server? = nil) -> EndpointRequest<{{#parameters}}{{#isBodyParam}}{{{dataType}}}{{/isBodyParam}}{{/parameters}}{{^hasBodyParam}}Nothing{{/hasBodyParam}}, {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}> {
static func {{operationId}}({{#parameters}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}{{#hasParams}}, {{/hasParams}}server: Server? = nil, security: [[String]]? = nil) -> EndpointRequest<{{#parameters}}{{#isBodyParam}}{{{dataType}}}{{/isBodyParam}}{{/parameters}}{{^hasBodyParam}}Nothing{{/hasBodyParam}}, {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}> {
.init(templatePath: "{{{path}}}",
method: .init(rawValue: "{{httpMethod}}"),
body: {{#hasBodyParam}}body{{/hasBodyParam}}{{^hasBodyParam}}nil{{/hasBodyParam}},
{{#hasQueryParams}}
{{#if queryParams}}
queryParameters: [
{{#each queryParams}}
"{{{this.baseName}}}": .init(value: {{{this.paramName}}}, allowEmptyValue: {{#this.required}}false{{/this.required}}{{^this.required}}true{{/this.required}}),
{{/each}}],
{{/hasQueryParams}}
{{/if}}
{{#hasPathParams}}
pathParameters: [
{{#each pathParams}}
@ -72,6 +67,7 @@ public extension EndpointRequest {
{{/each}}],
{{/hasCookieParams}}
acceptableStatusCodes: [{{contentExtensions.x-codegen-acceptable-status-codes}}],
security: security ?? [{{#if authMethods}}[{{/if}}{{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}{{#if authMethods}}]{{/if}}], // note: OR requirement is not supported by swagger-codegen
server: server)
}
{{/contents}}

View File

@ -1,9 +1,4 @@
{{#models}}{{#model}}//
// {{classname}}.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
{{#models}}{{#model}}
import Foundation
import TIFoundationUtils