Skip to content

Option to generate a struct without sorting fields #458

@mf-sakura

Description

@mf-sakura

I want to generate a struct without sorting fields, in the order listed in the OpenAPI doc.

I wrote my OpenAPI component schema so that the fields that are important to the user are at the top
And I want to return JSON fields on my server response in the same order.
However, for now, generated fields are sorted in increasing order.

So I want an option to generate a struct without sorting field.

openapi.yml

components:
  schemas:
    Pet:
      properties:
        id:
          type: integer
          format: int64
          description: Unique id of the pet
        name:
          type: string
          description: Name of the pet
        age:
          type: integer
          format: int64
          description: Age of the pet

Current

// Pet defines model for Pet.
type Pet struct {
  // Age of the pet
  Age *int64 `json:"age,omitempty"`

  // Unique id of the pet
  Id *int64 `json:"id,omitempty"`

  // Name of the pet
  Name *string `json:"name,omitempty"`
}

What I want

// Pet defines model for Pet.
type Pet struct {
  // Unique id of the pet
  Id *int64 `json:"id,omitempty"`

  // Name of the pet
  Name *string `json:"name,omitempty"`

  // Age of the pet
  Age *int64 `json:"age,omitempty"`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions