Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
// Place your settings in this file to overwrite default and user settings.
"editor.formatOnSave": true,
"spellright.ignoreFiles": [
"**/.gitignore",
"**/.spellignore"
],
"search.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/bower_components": true,
"**/tmp": true,
"output": true,
"**/obj": true,
"**/bin": true,
"test/inputs": true,
"test/runs": true,
"app/build": true,
"elm-stuff": true,
"dist": true
},
"explorer.excludeGitIgnore": false,
"spellright.documentTypes": [],
"java.configuration.updateBuildConfiguration": "automatic"
}
// Place your settings in this file to overwrite default and user settings.
"editor.formatOnSave": true,
"spellright.ignoreFiles": ["**/.gitignore", "**/.spellignore"],
"search.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/bower_components": true,
"**/tmp": true,
"output": true,
"**/obj": true,
"**/bin": true,
"test/inputs": true,
"test/runs": true,
"app/build": true,
"elm-stuff": true,
"dist": true
},
"explorer.excludeGitIgnore": false,
"spellright.documentTypes": [],
"java.configuration.updateBuildConfiguration": "automatic",
"typescript.tsdk": "node_modules/typescript/lib"
}
73 changes: 73 additions & 0 deletions data/codegen-templates/swift-client.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Foundation

public struct {{classPrefix}}Client
{
let httpService: VCSHTTPRequestable
let vcsUrl: String
private let JSONDecoder: () -> JSONDecoder = {
let decoder = Foundation.JSONDecoder()
decoder.dateDecodingStrategy = .iso8601Decoding
return decoder
}
public init(httpService: VCSHTTPRequestable, vcsUrl: String) {
self.httpService = httpService
self.vcsUrl = vcsUrl
}
{{#each routes}}

{{#if this.response.name}}
public typealias {{this.name}}CompletionHandler = (Result<{{this.response.name}}, VCSTBClientError>) -> Void
{{else}}
public typealias {{this.name}}CompletionHandler = (Result<Void, VCSTBClientError>) -> Void
{{/if}}

{{#if this.request.name}}
public func {{camelCase this.name}}(request: {{this.request.name}}, {{#each this.parameters}}{{this.name}}: {{{this.type}}}{{#if this.isOptional}}?{{/if}}, {{/each}}completion: @escaping {{this.name}}CompletionHandler) {
{{else}}
public func {{camelCase this.name}}({{#each this.parameters}}{{this.name}}: {{{this.type}}}{{#if this.isOptional}}?{{/if}}, {{/each}}completion: @escaping {{this.name}}CompletionHandler) {
{{/if}}

{{#if this.request.name}}
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .iso8601Encoding

guard let data = try? encoder.encode(request) else {
completion(.failure(.encoding))
return
}
{{/if}}

{{#if this.pathParameters}}
var path = "{{this.path}}"
{{#each this.pathParameters}}
path = path.replacingOccurrences(of: "{{surroundWithCurlyBraces this.name}}", with: {{this.name}})
{{/each}}
{{else}}
let path = "{{this.path}}"
{{/if}}
{{#if this.request.name}}
guard let request = vcsURLRequest(with: vcsUrl + path, body: data, method: "{{this.method}}") else { completion(.failure(.createRequest)); return }
{{else}}
guard let request = vcsURLRequest(with: vcsUrl + path, body: nil, method: "{{this.method}}") else { completion(.failure(.createRequest)); return }
{{/if}}
httpService.dataRequest(urlRequest: request, responseMimeType: "application/json") { result in
switch result {
{{#if this.response.name}}
case let .success(data):
do {
let payload = try self.JSONDecoder().decode({{this.response.name}}.self, from: data)
completion(.success(payload))
} catch {
completion(.failure(.decoding))
}
{{else}}
case .success:
completion(.success(()))
{{/if}}
case let .failure(error):
completion(.failure(.httpError(error)))
}
}
}
{{/each}}
}
44 changes: 44 additions & 0 deletions data/codegen-templates/ts-client.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AxiosInstance, AxiosRequestConfig } from 'axios'
import * as Types from './{{classPrefix}}Types'

export class {{classPrefix}}Client
{
#httpClient: AxiosInstance

constructor(httpClient: AxiosInstance) {
this.#httpClient = httpClient
}
{{#each routes}}

async {{camelCase this.name}}(
{{#if this.request}}request: {{#unless this.request.isPrimitive}}Types.{{/unless}}{{this.request.type}}{{#if this.request.isArray}}[]{{/if}}, {{/if}}
{{#if parameters}}
{
{{#each this.parameters}}
{{this.name}},
{{/each}}
}: {
{{#each this.parameters}}
{{this.name}}{{#if this.type.isOptional}}?{{/if}}: {{#unless this.type.isPrimitive}}Types.{{/unless}}{{this.type.type}}{{#if this.type.isArray}}[]{{/if}},
{{/each}}
},
{{/if}}
config?: AxiosRequestConfig
): {{#if this.response}}Promise<{{#unless this.response.isPrimitive}}Types.{{/unless}}{{{this.response.type}}}{{#if this.response.isArray}}[]{{/if}}>{{else}}Promise<void>{{/if}} {

const path = "{{this.path}}"
{{#each this.pathParameters}}
.replace("{{surroundWithCurlyBraces this.name}}", {{this.name}})
{{/each}}
const result = await this.#httpClient.request{{#if this.response}}<{{#unless this.response.isPrimitive}}Types.{{/unless}}{{{this.response.type}}}{{#if this.response.isArray}}[]{{/if}}>{{/if}}({
...config,
url: path,
method: '{{this.method}}',
{{#if this.request}}data: request,{{/if}}
params: { ...config?.params, {{#each this.queryParameters}}{{this.name}}, {{/each}} }
})

return result.data
}
{{/each}}
}
4 changes: 4 additions & 0 deletions data/codegen-templates/ts-index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{#each this}}
export { {{this}}Client } from './{{this}}Client'
export * as {{this}}Types from './{{this}}Types'
{{/each}}
77 changes: 77 additions & 0 deletions data/openapi/backoffice/frontend_openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
openapi: 3.0.2
info:
title: Test Widget API
description: Widget
version: 2.0.0
contact:
email: duzumeri@touchbistro.com
servers:
- url: http://widgets.com/widget
description: Production
tags:
- name: widgets
paths:
"/widgets1/{widgetID}":
get:
summary: Returns organization assigned addresses
description: Returns addresses of organization associated with given identifier
which were assigned to the organization using tags.
operationId: getWidgets1
tags:
- widgets
parameters:
- "$ref": "#/components/parameters/widgetID"
responses:
"200":
description: Request is processed successfully
headers:
Last-modified:
schema:
description: Date and time when this resource was modified
example: "2011-10-05T14:48:00.000Z"
content:
application/json:
schema:
oneOf:
- "$ref": "#/components/schemas/Widget"
"/widgets2/{widgetID}":
get:
summary: Returns all organization owned addresses
description: Returns addresses owned by organization(includes addresses assigned
to venues under this organization)
operationId: getWidgets2
tags:
- widgets
parameters:
- "$ref": "#/components/parameters/widgetID"
responses:
"200":
description: Request is processed successfully
headers:
Last-modified:
schema:
description: Date and time when this resource was modified
example: "2011-10-05T14:48:00.000Z"
content:
application/json:
schema:
oneOf:
- "$ref": "#/components/schemas/Widget"
components:
schemas:
Widget:
properties:
name:
type: string
required:
- name
additionalProperties: false
parameters:
widgetID:
in: path
name: widgetID
required: true
description: organization unique identifer
schema:
type: string
Loading