Skip to content

Commit

Permalink
(fix): OpenAPI/AsyncAPI importer handles invalid datetime examples (#…
Browse files Browse the repository at this point in the history
…3056)

(fix): OpenAPI/AsyncAPI importer handles invalid datetimes
  • Loading branch information
dsinghvi authored Feb 26, 2024
1 parent a01dfc4 commit 6cc99e2
Show file tree
Hide file tree
Showing 7 changed files with 12,730 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/cli/openapi-ir-sdk/fern/definition/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ types:
float: double
double: double
string: string
datetime: datetime
date: date
base64: base64
# typed as string to handle invalid datetime strings
datetime: string
date: string
base64: string
boolean: boolean

LiteralExample:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export declare namespace PrimitiveExample {

interface Datetime extends _Utils {
type: "datetime";
value: Date;
value: string;
}

interface Date_ extends _Utils {
Expand Down Expand Up @@ -71,7 +71,7 @@ export declare namespace PrimitiveExample {
float: (value: number) => _Result;
double: (value: number) => _Result;
string: (value: string) => _Result;
datetime: (value: Date) => _Result;
datetime: (value: string) => _Result;
date: (value: string) => _Result;
base64: (value: string) => _Result;
boolean: (value: boolean) => _Result;
Expand Down Expand Up @@ -145,7 +145,7 @@ export const PrimitiveExample = {
};
},

datetime: (value: Date): FernOpenapiIr.PrimitiveExample.Datetime => {
datetime: (value: string): FernOpenapiIr.PrimitiveExample.Datetime => {
return {
value: value,
type: "datetime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const PrimitiveExample: core.serialization.Schema<
value: core.serialization.string(),
}),
datetime: core.serialization.object({
value: core.serialization.date(),
value: core.serialization.string(),
}),
date: core.serialization.object({
value: core.serialization.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function convertPrimitive(primitiveExample: PrimitiveExample): RawSchemas.Exampl
case "datetime":
try {
// remove milliseconds from the datetime
return primitiveExample.value.toISOString().replace(/\.\d{3}Z$/, "Z");
return new Date(primitiveExample.value).toISOString().replace(/\.\d{3}Z$/, "Z");
} catch (e) {
return "2024-01-15T09:30:00Z";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function convertPrimitive(primitiveExample: PrimitiveExample): RawSchemas.Exampl
case "datetime":
try {
// remove milliseconds from the datetime
return primitiveExample.value.toISOString().replace(/\.\d{3}Z$/, "Z");
return new Date(primitiveExample.value).toISOString().replace(/\.\d{3}Z$/, "Z");
} catch (e) {
return "2024-01-15T09:30:00Z";
}
Expand Down
Loading

0 comments on commit 6cc99e2

Please sign in to comment.