Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(OpenApiType): All floats are doubles #125

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ private static function resolveIdentifier(string $context, array $definitions, s
"true" => new OpenApiType(type: "boolean", enum: [true]),
"false" => new OpenApiType(type: "boolean", enum: [false]),
"numeric" => new OpenApiType(type: "number"),
"double" => new OpenApiType(type: "number", format: "double"),
"float" => new OpenApiType(type: "number", format: "float"),
// https://www.php.net/manual/en/language.types.float.php: Both float and double are always stored with double precision
"float", "double" => new OpenApiType(type: "number", format: "double"),
"mixed", "empty", "array" => new OpenApiType(type: "object"),
"object", "stdClass" => new OpenApiType(type: "object", additionalProperties: true),
"null" => new OpenApiType(nullable: true),
Expand Down
1 change: 1 addition & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@
['name' => 'Settings#passwordConfirmationAttribute', 'url' => '/api/{apiVersion}/passwordConfirmationAttribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#oneOf', 'url' => '/api/{apiVersion}/oneOf', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#anyOf', 'url' => '/api/{apiVersion}/anyOf', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#floatDouble', 'url' => '/api/{apiVersion}/floatDouble', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
15 changes: 14 additions & 1 deletion tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function oneOf(): DataResponse {
/**
* Route with anyOf
*
* @return DataResponse<Http::STATUS_OK, array{test: string}|array{test: string, abc: int}, array{}>|DataResponse<Http::STATUS_CREATED, array{foobar: string}|array{disco: string, abc: int}|array{test: string, abc: int}, array{}>|DataResponse<Http::STATUS_ACCEPTED, float|double, array{}>|DataResponse<Http::STATUS_RESET_CONTENT, int|double, array{}>
* @return DataResponse<Http::STATUS_OK, array{test: string}|array{test: string, abc: int}, array{}>|DataResponse<Http::STATUS_CREATED, array{foobar: string}|array{disco: string, abc: int}|array{test: string, abc: int}, array{}>|DataResponse<Http::STATUS_ACCEPTED, float|numeric, array{}>|DataResponse<Http::STATUS_RESET_CONTENT, int|double, array{}>
*
* 200: OK
* 201: CREATED
Expand All @@ -513,4 +513,17 @@ public function oneOf(): DataResponse {
public function anyOf(): DataResponse {
return new DataResponse();
}

/**
* Route with float and double
*
* @return DataResponse<Http::STATUS_OK, float, array{}>|DataResponse<Http::STATUS_CREATED, double, array{}>
*
* 200: OK
* 201: CREATED
*/
#[PasswordConfirmationRequired]
public function floatDouble(): DataResponse {
return new DataResponse();
}
}
111 changes: 108 additions & 3 deletions tests/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2859,11 +2859,10 @@
"anyOf": [
{
"type": "number",
"format": "float"
"format": "double"
},
{
"type": "number",
"format": "double"
"type": "number"
}
]
}
Expand Down Expand Up @@ -2916,6 +2915,112 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/floatDouble": {
"post": {
"operationId": "settings-float-double",
"summary": "Route with float and double",
"description": "This endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "number",
"format": "double"
}
}
}
}
}
}
}
},
"201": {
"description": "CREATED",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "number",
"format": "double"
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/tests/attribute-ocs/{param}": {
"get": {
"operationId": "routing-attributeocs-route",
Expand Down
111 changes: 108 additions & 3 deletions tests/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -2986,11 +2986,10 @@
"anyOf": [
{
"type": "number",
"format": "float"
"format": "double"
},
{
"type": "number",
"format": "double"
"type": "number"
}
]
}
Expand Down Expand Up @@ -3043,6 +3042,112 @@
}
}
},
"/ocs/v2.php/apps/notifications/api/{apiVersion}/floatDouble": {
"post": {
"operationId": "settings-float-double",
"summary": "Route with float and double",
"description": "This endpoint requires admin access\nThis endpoint requires password confirmation",
"tags": [
"settings"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v2"
],
"default": "v2"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "number",
"format": "double"
}
}
}
}
}
}
}
},
"201": {
"description": "CREATED",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "number",
"format": "double"
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/tests/attribute-ocs/{param}": {
"get": {
"operationId": "routing-attributeocs-route",
Expand Down
Loading