Skip to content

Commit

Permalink
Merge pull request #125 from nextcloud/fix/openapitype/doubles
Browse files Browse the repository at this point in the history
fix(OpenApiType): All floats are doubles
  • Loading branch information
nickvergessen authored Apr 15, 2024
2 parents 0450537 + 94bbc4e commit a2dde48
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 9 deletions.
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

0 comments on commit a2dde48

Please sign in to comment.