raml-java-parser icon indicating copy to clipboard operation
raml-java-parser copied to clipboard

generated json schema always has"date-time" Date type even if in source it was "date-only" type

Open etsybaev opened this issue 7 years ago • 2 comments

generated json schema always has"date-time" Date type even if in source it was "date-only" type

The issue occurs somewhere after calling toJsonSchema() method of TypeDeclaration class

Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-56

etsybaev avatar Jul 11 '18 15:07 etsybaev

The root-cause is herehttps://github.com/raml-org/raml-java-parser/blob/b970a6eed827c69ae02e163e4387748203c82674/raml-parser-2/src/main/java/org/raml/v2/internal/impl/v10/type/TypeToJsonSchemaVisitor.java#L184

The method visitDate returns DATE_TIME

@Override public JsonObjectBuilder visitDate(DateOnlyResolvedType dateOnlyTypeDefinition) { return this.factory.createObjectBuilder() .add(TYPE, STRING) .add(FORMAT, DATE_TIME); }

etsybaev avatar Jul 12 '18 17:07 etsybaev

Issue confirmed. Still present in 1.0.41. Here: https://github.com/raml-org/raml-java-parser/blob/b970a6eed827c69ae02e163e4387748203c82674/raml-parser-2/src/main/java/org/raml/v2/internal/impl/v10/type/TypeToJsonSchemaVisitor.java#L180

The method visitDate returns the value of the DATE_TIME field. I've tested it by adding a DATE field, which returns only "date" and that fixed my issue: private static final String DATE = "date"; @Override public JsonObjectBuilder visitDate(DateOnlyResolvedType dateOnlyTypeDefinition) { return this.factory.createObjectBuilder() .add(TYPE, STRING) .add(FORMAT, DATE); }

Since date and date-time fields are used abundantly in our business, we would like to see this issue fixed. The fact that this issue has been open since July 11th, 2018 and we're running headlong into 2020, is a bit of a concern.

bspruit avatar Dec 11 '19 15:12 bspruit