Skip to content

Commit

Permalink
feat: adds format in options instead of using original input
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan committed Aug 15, 2023
1 parent 33c66a4 commit f438fc5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/generators/java/JavaConstrainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,19 @@ export const JavaDefaultTypeMapping: JavaTypeMapping = {
return type;
},
String({ constrainedModel }): string {
let type = 'String';
const format =
constrainedModel.originalInput &&
constrainedModel.originalInput['format'];
switch (format) {
switch (constrainedModel.options.format) {
case 'date':
type = 'java.time.LocalDate';
break;
return 'java.time.LocalDate';
case 'time':
type = 'java.time.OffsetTime';
break;
return 'java.time.OffsetTime';
case 'dateTime':
case 'date-time':
type = 'java.time.OffsetDateTime';
break;
return 'java.time.OffsetDateTime';
case 'binary':
type = 'byte[]';
break;
return 'byte[]';
default:
return 'String';
}
return type;
},
Boolean({ constrainedModel }): string {
return constrainedModel.options.isNullable ? 'Boolean' : 'boolean';
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/CommonModelToMetaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function getMetaModelOptions(commonModel: CommonModel): MetaModelOptions {
};
}

if (commonModel.format) {
options.format = commonModel.format;
}

return options;
}

Expand Down
3 changes: 3 additions & 0 deletions src/interpreter/Interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class Interpreter {
if (schema.required !== undefined) {
model.required = schema.required;
}
if (schema.format) {
model.format = schema.format;
}

interpretPatternProperties(schema, model, this, interpreterOptions);
interpretAdditionalItems(schema, model, this, interpreterOptions);
Expand Down
1 change: 1 addition & 0 deletions src/models/CommonModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class CommonModel {
enum?: any[];
const?: unknown;
discriminator?: string;
format?: string;
items?: CommonModel | CommonModel[];
properties?: { [key: string]: CommonModel };
additionalProperties?: CommonModel;
Expand Down
1 change: 1 addition & 0 deletions src/models/ConstrainedMetaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ConstrainedMetaModelOptions extends MetaModelOptions {
const?: ConstrainedMetaModelOptionsConst;
discriminator?: ConstrainedMetaModelOptionsDiscriminator;
isNullable?: boolean = false;
format?: string;
}

export abstract class ConstrainedMetaModel extends MetaModel {
Expand Down
1 change: 1 addition & 0 deletions src/models/MetaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class MetaModelOptions {
const?: MetaModelOptionsConst;
discriminator?: MetaModelOptionsDiscriminator;
isNullable?: boolean = false;
format?: string;
}

export class MetaModel {
Expand Down

0 comments on commit f438fc5

Please sign in to comment.