ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.45k stars 86 forks source link

$ref: keywords such as default used on a ref affect all instances #1321

Open abemedia opened 1 month ago

abemedia commented 1 month ago

What version of ogen are you using?

$ go list -m github.com/ogen-go/ogen
github.com/ogen-go/ogen v1.4.1

Can this issue be reproduced with the latest version?

Yes

What did you do?

Creating a custom type and referencing that with $ref, then using keywords such as default, x-ogen-name, minimum etc. will apply these keywords to all instances.

See the following example where I create the custom type Decimal and then use this for both price and gratuity, but only set a default value on gratuity.

components:
  schemas:
    Decimal:
      type: string
      pattern: ^-?\d+(\.\d*)?$
    Transaction:
      gratuity:
        $ref: '#/components/schemas/Decimal'
        default: '5.00'
      price:
        $ref: '#/components/schemas/Decimal'

What did you expect to see?

I expected gratuity to have the default value 5.00 and price to not have a default value.

What did you see instead?

Both price and gratuity have the default value 5.00.