Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The OAS definition produced for []bytes seems to be wrong #111

Closed
yurisasuke opened this issue May 22, 2024 · 2 comments
Closed

The OAS definition produced for []bytes seems to be wrong #111

yurisasuke opened this issue May 22, 2024 · 2 comments

Comments

@yurisasuke
Copy link

yurisasuke commented May 22, 2024

Describe the bug
If you have []bytes as one of your field in the OAS it is represented as an array

At the moment as a work arounf I am using PrepareJSONSchema to change the generated output.

Sample struct

type Asset struct {
	DBID        ObjectId  `bson:"_id,omitempty" json:"_id,omitempty" gorm:"primaryKey;column:_id" example:"664c9b735715ec3f798bbcd2"`
	ID          string    `bson:"id" json:"id" example:"my-unique-template-id"`
	Data        []byte    `bson:"data" json:"data"`
	
}

What is produced in the OAS:

Asset:
    properties:
      _id:
        example: 664c9b735715ec3f798bbcd2
        type: string
      data:
        items:
          minimum: 0
          type: integer
        nullable: true
        type: array

Expected behavior
I would expect it to have produced a string with binary format like below:

data:
         type: string
         format: byte
@vearutop
Copy link
Member

Indeed, the definition of []byte was wrong. The behavior of enconding/json for []byte is base64 string, this behavior was applied to schema in v0.2.52.

@vearutop
Copy link
Member

Please feel free to reopen if current behavior still needs adjustment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants