oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

x-oapi-codegen-extra-tags

Open tandem97 opened this issue 1 year ago • 4 comments

Hello! Here is a simple exmaple of spec:

openapi: 3.0.3
components:
  schemas:
    queue:
      type: object
      properties:
        ticket:
          x-oapi-codegen-extra-tags:
            db: ticket,merge
          allOf: 
            - $ref: "#/components/schemas/ticket"

    queue2:
      type: object
      properties:
        ticket:
          x-oapi-codegen-extra-tags:
            db: ticket,merge
          $ref: "#/components/schemas/ticket"
          
    ticket:
      type: object
      properties:
        clientName:
          type: string
      required:
        - clientName

Here is generated code:

type Queue struct {
	Ticket *Ticket `db:"ticket,merge" json:"ticket,omitempty"`
}

// Queue2 defines model for queue2.
type Queue2 struct {
	Ticket *Ticket `json:"ticket,omitempty"`
}

// Ticket defines model for ticket.
type Ticket struct {
	ClientName string `json:"clientName"`
}

I found a lifehack to add tags to Ticket field with help of allOf, but i expected it works without allOff. Code was generated with v.2.1.0 generator. Thanks!

tandem97 avatar Mar 24 '24 12:03 tandem97

Hey @tandem97 to confirm, is this that you're reporting current behaviour or expected behaviour?

jamietanna avatar May 05 '24 21:05 jamietanna

Hey @tandem97 to confirm, is this that you're reporting current behaviour or expected behaviour?

Hi! It is current behaviour. I expected struct Queue2 to have tag db too.

tandem97 avatar May 06 '24 18:05 tandem97

Do we have an update here? I am also facing the similar problem. It is common to reuse defined schemas with different tags and names

MUzairS15 avatar Jul 17 '24 12:07 MUzairS15

+1

jnelle avatar Oct 05 '24 21:10 jnelle

Any updates?

metinatakli avatar Feb 10 '25 19:02 metinatakli