@penkov/swagger-code-gen 1.6.0 → 1.6.1

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
@@ -39,6 +39,27 @@ Will generate:
39
39
  ```typescript
40
40
  // header skipped
41
41
 
42
+ async function requestImpl<T>(request: Request, requestOptions: RequestOptions): Promise<T> {
43
+ const preProcessed = requestOptions.preProcessRequest ? await requestOptions.preProcessRequest(request) : request;
44
+ const resp = await fetch(preProcessed);
45
+ const postProcessed = requestOptions.postProcessResponse ? await requestOptions.postProcessResponse(preProcessed, resp) : resp;
46
+ if (postProcessed.ok) {
47
+ let json: any = null;
48
+ if (postProcessed.headers.has('content-length')) {
49
+ const ct = parseInt(postProcessed.headers.get('content-length'));
50
+ if (ct > 0) {
51
+ json = await postProcessed.json()
52
+ }
53
+ }
54
+ return json as T;
55
+ } else {
56
+ throw postProcessed;
57
+ }
58
+ }
59
+
60
+
61
+
62
+
42
63
  export interface Customer {
43
64
  readonly id: number;
44
65
  readonly username: string;
package/dist/property.js CHANGED
@@ -24,11 +24,17 @@ export class Property {
24
24
  .exists(ref => schemas.get(ref.substring(SCHEMA_PREFIX.length)).contains('object'));
25
25
  const type = option(definition.$ref)
26
26
  .map(ref => ref.substring(SCHEMA_PREFIX.length))
27
+ .orElse(() => option(definition.allOf)
28
+ .map(x => Collection.from(x))
29
+ .filter(x => x.nonEmpty)
30
+ .map(x => x.flatMapOption(oneOfItem => option(oneOfItem.$ref)
31
+ .map(ref => ref.substring(SCHEMA_PREFIX.length))
32
+ .orElseValue(option(oneOfItem.type))).mkString(' & ')))
27
33
  .getOrElseValue(definition.type);
28
- const nullable = option(definition.nullable).contains(true) ||
34
+ const nullable = option(definition.nullable).contains(true) || !option(definition.required).contains(true) ||
29
35
  (referencesObject && options.referencedObjectsNullableByDefault && !option(definition.nullable).contains(false));
30
36
  const description = option(definition.description);
31
- const required = option(definition.required).contains(true);
37
+ const required = option(definition.required).contains(false);
32
38
  const items = option(definition.items?.$ref)
33
39
  .map(ref => ref.substring(SCHEMA_PREFIX.length))
34
40
  .orElseValue(option(definition.items?.type))
@@ -39,6 +45,7 @@ export class Property {
39
45
  .map(ref => ref.substring(SCHEMA_PREFIX.length))
40
46
  .orElseValue(option(oneOfItem.type))).mkString(' | ')))
41
47
  .getOrElseValue('any');
48
+ console.log(`${name}: ${type}`);
42
49
  return new Property(name, type, description, null, nullable, required, items, referencesObject, itemReferencesObject);
43
50
  }
44
51
  get jsType() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penkov/swagger-code-gen",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "generate-client": "./dist/cli.mjs"