Skip to content

Commit 07ae0fa

Browse files
authored
Typescript playwright (#25282)
* adding openapi to playwright typescript support * fixes * [typescript-playwright] address PR review feedback - runtime: resolve BASE_PATH from the BASE_URL env var at runtime so the target server can actually be overridden (previously ignored) - runtime/apis: build form and multipart bodies from a FormData so collectionFormat=multi array fields emit one repeated field per element; file parts are appended as Blobs and object parts as application/json (via a JSONPart wrapper) instead of untyped text - runtime: JSON-encode bare-primitive request bodies when the Content-Type is JSON (Playwright otherwise sends the string verbatim) - generated specs: escape operation summaries and enum example values so titles containing apostrophes/backslashes/newlines produce valid TypeScript - package.json: only emit "private": true when no npmRepository is set, and require TypeScript >= 4.7 to match the ES2021 compile target - README: correct layout note (one describe block per API, one test per operation) - regenerate petstore sample * [CI] fix invalid samples-r workflow `working-directory` is only valid on `run` steps; on the setup-r-dependencies action it must be passed as a `with` input. This fixes the "Unexpected value 'working-directory'" parse error that marks the workflow invalid on every PR. * [CI] add typescript-playwright client sample workflow * remove accidentally committed effective-pom.xml * [CI] run typescript-playwright tests against echo server * [CI] wait for echo server readiness before running playwright tests
1 parent e7b5ef9 commit 07ae0fa

71 files changed

Lines changed: 1557 additions & 3882 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/samples-r.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
with:
3030
r-version: 3.6.1
3131
- uses: r-lib/actions/setup-r-dependencies@v2
32-
working-directory: ${{ matrix.sample }}
3332
with:
3433
cache-version: 2
34+
working-directory: ${{ matrix.sample }}
3535
- name: Install curl
3636
run: sudo apt-get install -y r-cran-curl
3737
- name: build and test
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Samples TypeScript Playwright Client
2+
3+
on:
4+
push:
5+
paths:
6+
- samples/client/petstore/typescript-playwright/**
7+
- .github/workflows/samples-typescript-playwright.yaml
8+
pull_request:
9+
paths:
10+
- samples/client/petstore/typescript-playwright/**
11+
- .github/workflows/samples-typescript-playwright.yaml
12+
jobs:
13+
build:
14+
name: Build TypeScript Playwright client
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node:
20+
- "18.x"
21+
- "20.x"
22+
- "22.x"
23+
sample:
24+
- samples/client/petstore/typescript-playwright/
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js ${{ matrix.node }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node }}
31+
- name: Run echo server
32+
# The generated tests issue real HTTP requests and assert on the response
33+
# status. Point them at wing328's echo server (which answers 200 to any
34+
# request) so the Playwright client is exercised at runtime, deterministically.
35+
run: |
36+
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
37+
cd http-echo-server
38+
git checkout 15a684c41d4de692878636f47fcc1670af309a0f
39+
npm install
40+
# Background only the server itself; it keeps running for later steps.
41+
npm start &
42+
# Wait until it is actually listening before moving on, so the test
43+
# step never races server startup.
44+
for i in $(seq 1 30); do
45+
if curl --fail --silent http://localhost:3000 >/dev/null; then
46+
echo "Echo server is ready"
47+
exit 0
48+
fi
49+
sleep 1
50+
done
51+
echo "Echo server did not become ready" >&2
52+
exit 1
53+
- name: npm install
54+
working-directory: ${{ matrix.sample }}
55+
run: npm install
56+
- name: Type-check generated client and tests
57+
working-directory: ${{ matrix.sample }}
58+
run: npm run typecheck
59+
- name: Test
60+
working-directory: ${{ matrix.sample }}
61+
env:
62+
BASE_URL: http://localhost:3000
63+
run: npm test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
generatorName: typescript-playwright
2-
outputDir: samples/client/petstore/typescript-wright/
2+
outputDir: samples/client/petstore/typescript-playwright
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/typescript-playwright

‎docs/generators/typescript-playwright.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3636
|paramNaming|Naming convention for parameters: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
3737
|prefixParameterInterfaces|Setting this property to true will generate parameter interface declarations prefixed with API class name to avoid name conflicts.| |false|
3838
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
39-
|sagasAndRecords|Setting this property to true will generate additional files for use with redux-saga and immutablejs.| |false|
4039
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
4140
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
4241
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|

‎modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,18 @@ protected String nullableQuotedJSString(@Nullable String string) {
240240
@SuppressWarnings("squid:S5164")
241241
protected static final ThreadLocal<SimpleDateFormat> SNAPSHOT_SUFFIX_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT));
242242

243-
@Getter
244-
protected MODEL_PROPERTY_NAMING_TYPE modelPropertyNaming = MODEL_PROPERTY_NAMING_TYPE.original;
243+
@Getter protected MODEL_PROPERTY_NAMING_TYPE modelPropertyNaming = MODEL_PROPERTY_NAMING_TYPE.original;
245244
protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.PascalCase;
246-
@Getter
247-
protected PARAM_NAMING_TYPE paramNaming = PARAM_NAMING_TYPE.camelCase;
245+
@Getter protected PARAM_NAMING_TYPE paramNaming = PARAM_NAMING_TYPE.camelCase;
248246
protected boolean enumPropertyNamingReplaceSpecialChar = false;
249-
@Getter
250-
@Setter
247+
@Getter @Setter
251248
protected Boolean supportsES6 = false;
252-
@Getter
253-
@Setter
249+
@Getter @Setter
254250
protected Boolean nullSafeAdditionalProps = false;
255251
protected HashSet<String> languageGenericTypes;
256-
@Getter
257-
@Setter
252+
@Getter @Setter
258253
protected String npmName = null;
259-
@Getter
260-
@Setter
254+
@Getter @Setter
261255
protected String npmVersion = "1.0.0";
262256

263257
protected String enumSuffix = "Enum";
@@ -1157,4 +1151,4 @@ protected List<String> getTypesFromSchemas(List<Schema> schemas) {
11571151
public GeneratorLanguage generatorLanguage() {
11581152
return GeneratorLanguage.TYPESCRIPT;
11591153
}
1160-
}
1154+
}

0 commit comments

Comments
 (0)