@goast/kotlin 0.1.2 → 0.1.3

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.
@@ -50,19 +50,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
50
50
  }
51
51
  }
52
52
  generateFileContent(ctx, builder) {
53
- let schema = ctx.schema;
54
- if (schema.kind === 'oneOf') {
55
- schema =
56
- ctx.config.oneOfBehavior === 'treat-as-any-of'
57
- ? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
58
- ctx.schema = schema;
59
- }
60
- if (schema.kind === 'object' || schema.kind === 'combined') {
61
- const mergedSchema = (0, core_1.resolveAnyOfAndAllOf)(schema, true);
62
- if (mergedSchema) {
63
- schema = mergedSchema;
64
- }
65
- }
53
+ const schema = this.normalizeSchema(ctx, ctx.schema);
66
54
  if (schema.kind === 'object') {
67
55
  this.generateObjectType(ctx, builder, schema);
68
56
  }
@@ -370,7 +358,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
370
358
  return false;
371
359
  }
372
360
  // Too complex types cannot be represented in Kotlin, so they fallback to Any
373
- if (schema.kind === 'combined' || schema.kind === 'multi-type' || schema.kind === 'oneOf') {
361
+ if (schema.kind === 'multi-type') {
362
+ return false;
363
+ }
364
+ schema = this.normalizeSchema(ctx, schema);
365
+ if (schema.kind === 'combined' || schema.kind === 'oneOf') {
374
366
  return false;
375
367
  }
376
368
  // Only object types with properties should have its own type declaration
@@ -392,6 +384,21 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
392
384
  return bRequired - aRequired;
393
385
  });
394
386
  }
387
+ normalizeSchema(ctx, schema) {
388
+ if (schema.kind === 'oneOf') {
389
+ schema =
390
+ ctx.config.oneOfBehavior === 'treat-as-any-of'
391
+ ? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
392
+ ctx.schema = schema;
393
+ }
394
+ if (schema.kind === 'object' || schema.kind === 'combined') {
395
+ const mergedSchema = (0, core_1.resolveAnyOfAndAllOf)(schema, true);
396
+ if (mergedSchema) {
397
+ schema = mergedSchema;
398
+ }
399
+ }
400
+ return schema;
401
+ }
395
402
  hasProperty(ctx, schema, name) {
396
403
  return (('properties' in schema && schema.properties.has(name)) ||
397
404
  ('anyOf' in schema && schema.anyOf.some((x) => this.hasProperty(ctx, x, name))) ||
@@ -47,19 +47,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
47
47
  }
48
48
  }
49
49
  generateFileContent(ctx, builder) {
50
- let schema = ctx.schema;
51
- if (schema.kind === 'oneOf') {
52
- schema =
53
- ctx.config.oneOfBehavior === 'treat-as-any-of'
54
- ? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
55
- ctx.schema = schema;
56
- }
57
- if (schema.kind === 'object' || schema.kind === 'combined') {
58
- const mergedSchema = resolveAnyOfAndAllOf(schema, true);
59
- if (mergedSchema) {
60
- schema = mergedSchema;
61
- }
62
- }
50
+ const schema = this.normalizeSchema(ctx, ctx.schema);
63
51
  if (schema.kind === 'object') {
64
52
  this.generateObjectType(ctx, builder, schema);
65
53
  }
@@ -367,7 +355,11 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
367
355
  return false;
368
356
  }
369
357
  // Too complex types cannot be represented in Kotlin, so they fallback to Any
370
- if (schema.kind === 'combined' || schema.kind === 'multi-type' || schema.kind === 'oneOf') {
358
+ if (schema.kind === 'multi-type') {
359
+ return false;
360
+ }
361
+ schema = this.normalizeSchema(ctx, schema);
362
+ if (schema.kind === 'combined' || schema.kind === 'oneOf') {
371
363
  return false;
372
364
  }
373
365
  // Only object types with properties should have its own type declaration
@@ -389,6 +381,21 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
389
381
  return bRequired - aRequired;
390
382
  });
391
383
  }
384
+ normalizeSchema(ctx, schema) {
385
+ if (schema.kind === 'oneOf') {
386
+ schema =
387
+ ctx.config.oneOfBehavior === 'treat-as-any-of'
388
+ ? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
389
+ ctx.schema = schema;
390
+ }
391
+ if (schema.kind === 'object' || schema.kind === 'combined') {
392
+ const mergedSchema = resolveAnyOfAndAllOf(schema, true);
393
+ if (mergedSchema) {
394
+ schema = mergedSchema;
395
+ }
396
+ }
397
+ return schema;
398
+ }
392
399
  hasProperty(ctx, schema, name) {
393
400
  return (('properties' in schema && schema.properties.has(name)) ||
394
401
  ('anyOf' in schema && schema.anyOf.some((x) => this.hasProperty(ctx, x, name))) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/kotlin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -33,6 +33,7 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
33
33
  protected shouldGenerateTypeDeclaration(ctx: Context, schema: ApiSchema): boolean;
34
34
  protected getDeclarationTypeName(ctx: Context, schema: ApiSchema): string;
35
35
  protected sortProperties(ctx: Context, schema: ApiSchema, properties: Iterable<ApiSchemaProperty>): ApiSchemaProperty[];
36
+ private normalizeSchema;
36
37
  private hasProperty;
37
38
  }
38
39
  export {};