@team-supercharge/oasg 16.6.0 → 16.7.1-temp-feat-swift-openapi-generator-e02341ef

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -142,6 +142,7 @@ The table below gives an overview of the changes (breaking, non-breaking, bug fi
142
142
  | `plain-java` |🆕 |
143
143
  | `flutter` |➖ |➖ |➖ |🆕 |
144
144
  | `ios` |➖ |➖ |➖ |💥 |🐛 |➖ |➖ |➖ |✨ |➖ |💥 |➖ |➖ |✨ |🆕 |
145
+ | `swift-openapi-generator` |🆕 |
145
146
  | `kmp` |➖ |➖ |🆕 |
146
147
  | `python` |🆕 |
147
148
  | `python-legacy` |💥 |➖ |🐛 |💥 |➖ |➖ |➖ |➖ |➖ |➖ |➖ |➖ |🆕 |
@@ -701,6 +702,25 @@ TBD
701
702
  | interfaceType | Response type of the generated client: `Combine` / `Result` / `RxSwift` / `AsyncAwait` / `PromiseKit` | Y | - |
702
703
  | generatorCustomArgs | Custom arguments of the generator | N | - |
703
704
 
705
+ #### `swift-openapi-generator`
706
+
707
+ ```json
708
+ {
709
+ "id": "client-ios",
710
+ "type": "swift-openapi-generator",
711
+ "source": "source-merged",
712
+ "projectName": "OASgExample",
713
+ "repository": "git@gitlab.supercharge.io:example/openapi-generator-source.git",
714
+ "generatorCustomArgs": ""
715
+ }
716
+ ```
717
+
718
+ |Parameter| Description| Required | Default |
719
+ |-|-|-|-|
720
+ | projectName | Name of the project | Y | - |
721
+ | repository | URL of the generated client api code repository | Y | - |
722
+ | generatorCustomArgs | Custom arguments of the generator | N | - |
723
+
704
724
  #### `flutter`
705
725
 
706
726
  ```json
@@ -926,7 +946,7 @@ describe('Auth', function () {
926
946
  | repository | URL of the NPM package registry | Y | - |
927
947
 
928
948
  **Authorisation**<br>
929
- The package generates an AuthGuard and applies to endpoints, where a security scheme is defined.
949
+ The package generates an AuthGuard and applies it to endpoints where a security scheme is defined.
930
950
 
931
951
  AuthGuard usage:
932
952
  Implement the `AuthServiceInterface`, which will receive a validation request for each security scheme added to the checked endpoint and define the validation per scheme.
@@ -953,7 +973,7 @@ Future improvements:
953
973
  - no multidimensional array validation in DTOs
954
974
 
955
975
  **Validation availability:**
956
- <br> _List is not comprehensive, missing items are definitely not currently supported_
976
+ <br> _List is not comprehensive, missing items are definitely not supported currently_
957
977
 
958
978
  Validations in General:
959
979
  | Validation | DTO | Query | Header | Path |
package/bin/oasg CHANGED
@@ -42,6 +42,7 @@ const DEFAULT_GENERATOR_MAPPING = {
42
42
  "plain-java": { version: '7.11.0', generator: 'java' },
43
43
  "flutter": { version: '7.0.1', generator: 'dart-dio' },
44
44
  "ios": { version: '7.0.1', generator: 'swift5' },
45
+ "swift-openapi-generator": { version: undefined, generator: undefined },
45
46
  "kmp": { version: '7.8.0', generator: 'kotlin' },
46
47
  "python": { version: '7.11.0', generator: 'python' },
47
48
  "python-legacy": { version: '7.11.0', generator: 'python-pydantic-v1' },
package/config.schema.yml CHANGED
@@ -312,6 +312,20 @@ targets:
312
312
  - repository
313
313
  - interfaceType
314
314
 
315
+ SwiftOpenAPIGenerator:
316
+ allOf:
317
+ - $ref: '#/targets/Base'
318
+ - properties:
319
+ type:
320
+ pattern: "^swift-openapi-generator$"
321
+ packageName:
322
+ type: string
323
+ repositoryUrl:
324
+ type: string
325
+ required:
326
+ - packageName
327
+ - repositoryUrl
328
+
315
329
  Python:
316
330
  allOf:
317
331
  - $ref: '#/targets/Base'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-supercharge/oasg",
3
- "version": "16.6.0",
3
+ "version": "16.7.1-temp-feat-swift-openapi-generator-e02341ef",
4
4
  "description": "Node-based tool to lint OpenAPI documents and generate clients, servers and documentation from them",
5
5
  "author": "Supercharge",
6
6
  "license": "MIT",
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { Get, Post, Put, Delete, Patch, Options, Head } from '@nestjs/common';
6
6
  import { Query, Param, Headers, Body } from '@nestjs/common';
7
- import { HttpCode, Request } from '@nestjs/common';
7
+ import { HttpCode, Request, Response } from '@nestjs/common';
8
8
  import { UseInterceptors, UseGuards, UploadedFile, StreamableFile } from '@nestjs/common';
9
9
  import { FileInterceptor } from '@nestjs/platform-express';
10
10
 
@@ -51,11 +51,11 @@ export abstract class {{classname}} {
51
51
  //// @{{httpMethod}}('{{path}}'){{#isMultipart}}
52
52
  @UseInterceptors(FileInterceptor({{#formParams}}{{#isFile}}'{{paramName}}'{{/isFile}}{{/formParams}})){{/isMultipart}}
53
53
  @HttpCode({{#responses.0}}{{code}}{{/responses.0}})
54
- private _{{nickname}}(@Request() req{{#allParams}}{{^isBodyParam}}, {{#isQueryParam}}@Query({{/isQueryParam}}{{#isPathParam}}@Param({{/isPathParam}}{{#isHeaderParam}}@Headers({{/isHeaderParam}}{{#isFormParam}}{{^isFile}}@Body({{/isFile}}{{#isFile}}@UploadedFile({{/isFile}}{{/isFormParam}}'{{paramName}}'{{#required}}{{#isHeaderParam}}{{/isHeaderParam}}{{^isHeaderParam}}, RequiredPipe{{/isHeaderParam}}{{/required}}{{#isArray}}, new ApiParseArrayPipe({ optional: true{{#items}}{{#isNumeric}}, items: Number{{/isNumeric}}{{#isBoolean}}, items: Boolean{{/isBoolean}}{{/items}} }){{/isArray}}{{#isNumber}}, OptionalParseFloatPipe{{/isNumber}}{{#isFloat}}, OptionalParseFloatPipe{{/isFloat}}{{#isDouble}}, OptionalParseFloatPipe{{/isDouble}}{{#isInteger}}, OptionalParseIntPipe{{/isInteger}}{{#isLong}}, OptionalParseIntPipe{{/isLong}}{{#isBoolean}}, OptionalParseBoolPipe{{/isBoolean}}{{#allowableValues}}{{^enumVars.empty}}, new OptionalParseEnumPipe({{{dataType}}}){{/enumVars.empty}}{{/allowableValues}}) {{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{/isBodyParam}}{{/allParams}}{{#bodyParam}}, @Body(new ApiValidationPipe({ whitelist: true, forbidNonWhitelisted: true })) requestBody{{^required}}?{{/required}}: {{{dataType}}}{{/bodyParam}}): Promise<{{#returnType}}{{#isResponseFile}}StreamableFile{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
55
- return this.{{nickname}}({{#allParams.0}}{ params: { {{#allParams}}{{^isBodyParam}}{{^-first}}, {{/-first}}{{paramName}}{{/isBodyParam}}{{/allParams}} }{{#bodyParam}}, body: requestBody{{/bodyParam}} }, {{/allParams.0}}req);
54
+ private _{{nickname}}(@Request() req: unknown, @Response({ passthrough: true }) res: unknown{{#allParams}}{{^isBodyParam}}, {{#isQueryParam}}@Query({{/isQueryParam}}{{#isPathParam}}@Param({{/isPathParam}}{{#isHeaderParam}}@Headers({{/isHeaderParam}}{{#isFormParam}}{{^isFile}}@Body({{/isFile}}{{#isFile}}@UploadedFile({{/isFile}}{{/isFormParam}}'{{paramName}}'{{#required}}{{#isHeaderParam}}{{/isHeaderParam}}{{^isHeaderParam}}, RequiredPipe{{/isHeaderParam}}{{/required}}{{#isArray}}, new ApiParseArrayPipe({ optional: true{{#items}}{{#isNumeric}}, items: Number{{/isNumeric}}{{#isBoolean}}, items: Boolean{{/isBoolean}}{{/items}} }){{/isArray}}{{#isNumber}}, OptionalParseFloatPipe{{/isNumber}}{{#isFloat}}, OptionalParseFloatPipe{{/isFloat}}{{#isDouble}}, OptionalParseFloatPipe{{/isDouble}}{{#isInteger}}, OptionalParseIntPipe{{/isInteger}}{{#isLong}}, OptionalParseIntPipe{{/isLong}}{{#isBoolean}}, OptionalParseBoolPipe{{/isBoolean}}{{#allowableValues}}{{^enumVars.empty}}, new OptionalParseEnumPipe({{{dataType}}}){{/enumVars.empty}}{{/allowableValues}}) {{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{/isBodyParam}}{{/allParams}}{{#bodyParam}}, @Body(new ApiValidationPipe({ whitelist: true, forbidNonWhitelisted: true })) requestBody{{^required}}?{{/required}}: {{{dataType}}}{{/bodyParam}}): Promise<{{#returnType}}{{#isResponseFile}}StreamableFile{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
55
+ return this.{{nickname}}({{#allParams.0}}{ params: { {{#allParams}}{{^isBodyParam}}{{^-first}}, {{/-first}}{{paramName}}{{/isBodyParam}}{{/allParams}} }{{#bodyParam}}, body: requestBody{{/bodyParam}} }, {{/allParams.0}}req, res);
56
56
  }
57
57
 
58
- abstract {{nickname}}({{#allParams.0}}context: {{operationIdCamelCase}}Context, {{/allParams.0}}req?): Promise<{{#returnType}}{{#isResponseFile}}StreamableFile{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/returnType}}{{^returnType}}void{{/returnType}}>;
58
+ abstract {{nickname}}({{#allParams.0}}context: {{operationIdCamelCase}}Context, {{/allParams.0}}req?: unknown, res?: unknown): Promise<{{#returnType}}{{#isResponseFile}}StreamableFile{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/returnType}}{{^returnType}}void{{/returnType}}>;
59
59
 
60
60
  {{/operation}}
61
61
  // ||||||||||
@@ -10,7 +10,11 @@ export const IsValidISO8601Date = () => {
10
10
  options: {},
11
11
  validator: {
12
12
  validate(value: string) {
13
- const [year, month, day] = value.split("-").map(Number);
13
+ const [year, month, day] = value.split("-").map(Number) as [
14
+ number,
15
+ number,
16
+ number
17
+ ];
14
18
  const date = new Date(year, month - 1, day);
15
19
 
16
20
  // Check if the date components are valid
@@ -0,0 +1,26 @@
1
+ // swift-tools-version: 6.0
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "__PROJECT_NAME__",
6
+ platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
7
+ products: [
8
+ .library(
9
+ name: "__PROJECT_NAME__",
10
+ targets: ["__PROJECT_NAME__"]
11
+ )
12
+ ],
13
+ dependencies: [
14
+ .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
15
+ .package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
16
+ ],
17
+ targets: [
18
+ .target(
19
+ name: "__PROJECT_NAME__",
20
+ dependencies: [
21
+ .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
22
+ .product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
23
+ ]
24
+ )
25
+ ]
26
+ )
@@ -0,0 +1,47 @@
1
+ #/bin/bash
2
+
3
+ CURRENT_WORKING_DIR=$(pwd)
4
+
5
+ source $(dirname "$0")/../common.sh
6
+
7
+ # Clear the output directory
8
+ rm -rf out/$targetId
9
+ mkdir -p out/$targetId
10
+
11
+ # Variables
12
+ SWIFT_OPENAPI_GENERATOR_GIT_URL=https://github.com/apple/swift-openapi-generator
13
+ SWIFT_OPENAPI_GENERATOR_GIT_TAG=1.7.2
14
+ SWIFT_OPENAPI_GENERATOR_CLONE_DIR=swift-openapi-generator/$SWIFT_OPENAPI_GENERATOR_GIT_TAG
15
+ SWIFT_OPENAPI_GENERATOR_BIN="$SWIFT_OPENAPI_GENERATOR_CLONE_DIR/.build/release/swift-openapi-generator"
16
+ OPENAPI_GENERATOR_CONFIG_PATH=openapi-generator-config.yaml
17
+
18
+ # Clear OpenAPI generator directory
19
+ rm -rf "$SWIFT_OPENAPI_GENERATOR_CLONE_DIR"
20
+ mkdir -p "$SWIFT_OPENAPI_GENERATOR_CLONE_DIR"
21
+
22
+ # Checkout the swift-openapi-generator repo
23
+ git \
24
+ -c advice.detachedHead=false \
25
+ clone \
26
+ --branch "$SWIFT_OPENAPI_GENERATOR_GIT_TAG" \
27
+ --depth 1 \
28
+ "$SWIFT_OPENAPI_GENERATOR_GIT_URL" \
29
+ "$SWIFT_OPENAPI_GENERATOR_CLONE_DIR"
30
+
31
+ # Build the swift-openapi-generator
32
+ swift \
33
+ build \
34
+ --package-path "$SWIFT_OPENAPI_GENERATOR_CLONE_DIR" \
35
+ --configuration release \
36
+ --product swift-openapi-generator
37
+
38
+ # Generate the swift client
39
+ "$SWIFT_OPENAPI_GENERATOR_BIN" \
40
+ generate \
41
+ --config "$OPENAPI_GENERATOR_CONFIG_PATH" \
42
+ --output-directory "out/$targetId/Sources/$projectName" \
43
+ "$openApiFile"
44
+
45
+ # Copy Package.swift file
46
+ cp Package.swift out/$targetId
47
+ sed -i '' "s/__PROJECT_NAME__/$projectName/" out/$targetId/Package.swift
@@ -0,0 +1,5 @@
1
+ generate:
2
+ - types
3
+ - client
4
+ accessModifier: public
5
+ namingStrategy: idiomatic
@@ -0,0 +1,33 @@
1
+ #/bin/bash
2
+
3
+ source $(dirname "$0")/../common.sh
4
+
5
+ cd out
6
+ git clone $repository generator-source
7
+
8
+ # Remove all old files from the generator-source directory
9
+ cd generator-source
10
+ git rm -rf .
11
+ git clean -fdx
12
+ cd ..
13
+
14
+ # Copy the generated files to the generator-source directory
15
+ cp -rf $targetId/* generator-source
16
+
17
+ cd generator-source
18
+ if [ $(git status --porcelain | wc -l) -eq "0" ]; then
19
+ echo "🟢 No changes"
20
+ else
21
+ git add .
22
+ git commit -m "chore(release): $version"
23
+
24
+ if [ "$preRelease" == "false" ]; then git push; fi
25
+
26
+ tagVersion="v$version"
27
+ git tag -f $tagVersion
28
+ git push origin -f --tags
29
+ fi
30
+
31
+ cd ..
32
+ rm -rf generator-source
33
+ cd ../..