You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by mcclurec December 19, 2024
The compareResponses method effectively does a deep equal check by marshaling the JSON and comparing their byte array. This means that if you've defined a schema with a standard error type, but provide relevant example errors for different endpoints, ogen doesn't generate a convenient error handler.
If the comparison did an equality check to see that the $ref'd object was of the same shape as the manually defined response, you could mix default responses and ones with specific examples.
Example OpenAPI 3.1 schema
The following spec only defines a single error type, and all the default responses are technically equal, but the comparison checker deems them different by doing a deep equality check.
openapi: 3.1.1info:
title: Relevent Example Errorspaths:
/endpoint1:
get:
responses:
200:
$ref: "#/components/responses/Endpoint1Response"default:
$ref: '#/components/responses/ErrorResponse'patch:
requestBody:
$ref: '#/components/requestBodies/Endpoint1PatchRequest'responses:
200:
$ref: "#/components/responses/Endpoint1Response"default:
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"examples:
ErrorOutOfRange:
$ref: '#/components/examples/ErrorOutOfRange'ErrorValueType:
$ref: '#/components/examples/ErrorValueType'/endpoint2:
get:
responses:
200:
$ref: "#/components/responses/Endpoint2Response"default:
$ref: '#/components/responses/ErrorResponse'patch:
requestBody:
$ref: '#/components/requestBodies/Endpoint2PatchRequest'responses:
200:
$ref: "#/components/responses/Endpoint2Response"default:
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"examples:
ErrorIpValidation:
$ref: '#/components/examples/ErrorIpAddress'components:
schemas:
Endpoint1:
type: objectproperties:
some_integer:
type: integerformat: int32minimum: 0maximum: 100some_double:
type: numberformat: doubleEndpoint2:
type: objectproperties:
some_string:
type: stringsome_ip_address:
type: stringformat: ipv4examples: [192.168.0.255]ErrorMessage:
type: objectproperties:
code:
type: stringexamples: [unique_error_code_string]message:
type: stringexamples: [a helpful human readable description]examples:
ErrorOutOfRange:
summary: Value out of rangevalue:
code: value_out_of_rangemessage: <field> out of range [0, 100]ErrorValueType:
summary: Value must be of proper typevalue:
code: value_typemessage: <field> must be a <type>ErrorIpAddress:
summary: Value must be a valid IPv4 addressvalue:
code: value_typemessage: some_ip_address must be a valid ipv4 formatresponses:
Endpoint1Response:
description: successheaders:
'Accept-Patch':
$ref: "#/components/headers/AcceptPatch"content:
application/json:
schema:
$ref: "#/components/schemas/Endpoint1"Endpoint2Response:
description: successheaders:
'Accept-Patch':
$ref: "#/components/headers/AcceptPatch"content:
application/json:
schema:
$ref: "#/components/schemas/Endpoint2"ErrorResponse:
description: error responsecontent:
application/json:
schema:
$ref: "#/components/schemas/ErrorMessage"requestBodies:
Endpoint1PatchRequest:
required: truecontent:
application/json:
schema:
$ref: '#/components/schemas/Endpoint1'Endpoint2PatchRequest:
required: truecontent:
application/json:
schema:
$ref: '#/components/schemas/Endpoint2'headers:
AcceptPatch:
schema:
type: stringenum:
- application/json```</div>
The text was updated successfully, but these errors were encountered:
Discussed in #1372
Originally posted by mcclurec December 19, 2024
The
compareResponses
method effectively does a deep equal check by marshaling the JSON and comparing their byte array. This means that if you've defined a schema with a standard error type, but provide relevant example errors for different endpoints, ogen doesn't generate a convenient error handler.I seems like you could safely drop the
example
andexamples
properties off thecontent
before doing the comparison. (Relevant OpenAPI schema spec forMedia Type Object
)Bonus Points
If the comparison did an equality check to see that the
$ref
'd object was of the same shape as the manually defined response, you could mix default responses and ones with specific examples.Example OpenAPI 3.1 schema
The following spec only defines a single error type, and all the
default
responses are technically equal, but the comparison checker deems them different by doing a deep equality check.The text was updated successfully, but these errors were encountered: