Skip to content

Commit

Permalink
TT-39 - Support number literal generation to OpenApi2 and 3 with form…
Browse files Browse the repository at this point in the history
…at on it. (airtasker#479)

* TT-39 - Support number literal generation to OpenApi2 and 3 with format on it.

* Updated test.
  • Loading branch information
committedteadrinker authored Oct 14, 2019
1 parent e0735db commit 7ec2497
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/src/generators/contract/openapi2-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("OpenAPI 2 generator", () => {
"enum": Array [
1.5,
],
"format": "float",
"type": "number",
}
`);
Expand All @@ -94,6 +95,7 @@ describe("OpenAPI 2 generator", () => {
"enum": Array [
-23.1,
],
"format": "float",
"type": "number",
}
`);
Expand Down Expand Up @@ -123,6 +125,7 @@ describe("OpenAPI 2 generator", () => {
"enum": Array [
0,
],
"format": "int32",
"type": "integer",
}
`);
Expand All @@ -131,6 +134,7 @@ describe("OpenAPI 2 generator", () => {
"enum": Array [
122,
],
"format": "int32",
"type": "integer",
}
`);
Expand All @@ -139,6 +143,7 @@ describe("OpenAPI 2 generator", () => {
"enum": Array [
-1000,
],
"format": "int32",
"type": "integer",
}
`);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/generators/contract/openapi2-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export function openApi2TypeSchema(type: DataType): OpenAPI2SchemaType {
return Math.round(type.value) === type.value
? {
type: "integer",
enum: [type.value]
enum: [type.value],
format: "int32"
}
: {
type: "number",
enum: [type.value]
enum: [type.value],
format: "float"
};
case TypeKind.INT32:
return {
Expand Down Expand Up @@ -180,11 +182,13 @@ export interface OpenAPI2SchemaTypeString extends OpenAPI2BaseSchemaType {
export interface OpenAPI2SchemaTypeNumber extends OpenAPI2BaseSchemaType {
type: "number";
enum?: number[];
format: "float" | "double";
}

export interface OpenAPI2SchemaTypeInteger extends OpenAPI2BaseSchemaType {
type: "integer";
enum?: number[];
format: "int32" | "int64";
}

export interface OpenAPI2SchemaTypeDateTime extends OpenAPI2BaseSchemaType {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/generators/contract/openapi3-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe("OpenAPI 3 generator", () => {
"enum": Array [
1.5,
],
"format": "float",
"type": "number",
}
`);
Expand All @@ -97,6 +98,7 @@ describe("OpenAPI 3 generator", () => {
"enum": Array [
-23.1,
],
"format": "float",
"type": "number",
}
`);
Expand Down Expand Up @@ -126,6 +128,7 @@ describe("OpenAPI 3 generator", () => {
"enum": Array [
0,
],
"format": "int32",
"type": "integer",
}
`);
Expand All @@ -134,6 +137,7 @@ describe("OpenAPI 3 generator", () => {
"enum": Array [
123,
],
"format": "int32",
"type": "integer",
}
`);
Expand All @@ -143,6 +147,7 @@ describe("OpenAPI 3 generator", () => {
"enum": Array [
-1000,
],
"format": "int32",
"type": "integer",
}
`);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/generators/contract/openapi3-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export function openApi3TypeSchema(
return Math.round(type.value) === type.value
? {
type: "integer",
enum: [type.value]
enum: [type.value],
format: "int32"
}
: {
type: "number",
enum: [type.value]
enum: [type.value],
format: "float"
};
case TypeKind.INT32:
return {
Expand Down Expand Up @@ -225,11 +227,13 @@ export interface OpenAPI3SchemaTypeString extends OpenAPI3BaseSchemaType {
export interface OpenAPI3SchemaTypeNumber extends OpenAPI3BaseSchemaType {
type: "number";
enum?: number[];
format: "float" | "double";
}

export interface OpenAPI3SchemaTypeInteger extends OpenAPI3BaseSchemaType {
type: "integer";
enum?: number[];
format: "int32" | "int64";
}

export interface OpenAPI3SchemaTypeDateTime extends OpenAPI3BaseSchemaType {
Expand Down

0 comments on commit 7ec2497

Please sign in to comment.