How can I maintain the order of attributes from the spec (instead of getting them in alphabetical order)? #1264
-
Looks like ogen sorts all attributes in a schema alphabetically, and then encodes them in the generated function |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Actually ogen should keep original order. openapi: 3.0.3
info:
title: API
version: 0.1.0
paths:
/objects/:
get:
operationId: listObjects
responses:
default: {$ref: '#/components/responses/Error'}
'200':
description: List of clusters
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Object'
components:
schemas:
Object:
type: object
required:
- id
- name
- foo
- bar
properties:
id:
type: string
format: uuid
name:
type: string
foo:
type: string
bar:
type: string
Error:
title: Structured error
description: Error occurred while processing request
type: object
required:
- error_message
properties:
error_message:
type: string
description: "Human-readable error message"
example: "Something went wrong"
responses:
Error:
description: Structured error response.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
servers:
- url: http://127.0.0.1:8501 This will be generated: // encodeFields encodes fields.
func (s *Object) encodeFields(e *jx.Encoder) {
{
e.FieldStart("id")
json.EncodeUUID(e, s.ID)
}
{
e.FieldStart("name")
e.Str(s.Name)
}
{
e.FieldStart("foo")
e.Str(s.Foo)
}
{
e.FieldStart("bar")
e.Str(s.Bar)
}
} Can you please double-check? |
Beta Was this translation helpful? Give feedback.
-
Thanks, we were able to track down where the alphabetical order comes from, it was indeed not from ogen but from some pre-processor we were using on the spec. |
Beta Was this translation helpful? Give feedback.
Actually ogen should keep original order.
For example, following schema: